mirror of
https://github.com/ONLYOFFICE/web-apps.git
synced 2026-07-24 01:04:22 +08:00
Add control methods for monaco editor(setReadonly, undo/redo, center position)
This commit is contained in:
@ -155,6 +155,30 @@ define([], function () {
|
||||
});
|
||||
},
|
||||
|
||||
revealPositionInCenter: function() {
|
||||
this._postMessage(this.iframe.contentWindow, {
|
||||
command: 'revealPositionInCenter',
|
||||
referer: 'monaco-editor',
|
||||
data: {}
|
||||
});
|
||||
},
|
||||
|
||||
undo: function() {
|
||||
this._postMessage(this.iframe.contentWindow, {
|
||||
command: 'undo',
|
||||
referer: 'monaco-editor',
|
||||
data: {}
|
||||
});
|
||||
},
|
||||
|
||||
redo: function() {
|
||||
this._postMessage(this.iframe.contentWindow, {
|
||||
command: 'redo',
|
||||
referer: 'monaco-editor',
|
||||
data: {}
|
||||
});
|
||||
},
|
||||
|
||||
enablePointerEvents: function(enable) {
|
||||
this.iframe && (this.iframe.style.pointerEvents = enable ? "" : "none");
|
||||
},
|
||||
|
||||
9
vendor/monaco/MonacoEditorCode.js
vendored
9
vendor/monaco/MonacoEditorCode.js
vendored
@ -68,6 +68,7 @@ var _postMessage = function(msg) {
|
||||
window.isDisable = true;
|
||||
codeEditor.setValue(data.value || '');
|
||||
codeEditor.setPosition({lineNumber: data.currentPos ? data.currentPos.row : 0, column: data.currentPos ? data.currentPos.column : 0});
|
||||
codeEditor.setReadonly(!!data.readonly);
|
||||
codeEditor.setFocus();
|
||||
window.isDisable = false;
|
||||
};
|
||||
@ -129,7 +130,13 @@ var _postMessage = function(msg) {
|
||||
onThemeChanged(cmd.data);
|
||||
}else if (cmd.command==='disableDrop') {
|
||||
editorDisableDrop(cmd.data);
|
||||
}
|
||||
} else if(cmd.command==='revealPositionInCenter') {
|
||||
codeEditor.revealPositionInCenter();
|
||||
} else if(cmd.command==='undo') {
|
||||
codeEditor.undo();
|
||||
} else if(cmd.command==='redo') {
|
||||
codeEditor.redo();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
17
vendor/monaco/monaco.js
vendored
17
vendor/monaco/monaco.js
vendored
@ -53,6 +53,7 @@
|
||||
language: "javascript",
|
||||
theme: this.theme ? this.theme : "vs-light",
|
||||
automaticLayout: true,
|
||||
domReadOnly: true,
|
||||
suggest: {
|
||||
preview: false,
|
||||
showInlineDetails: true
|
||||
@ -146,6 +147,22 @@
|
||||
this.editor && this.editor.focus();
|
||||
};
|
||||
|
||||
MonacoEditor.prototype.setReadonly = function(value) {
|
||||
this.editor && this.editor.updateOptions({readOnly: value});
|
||||
};
|
||||
|
||||
MonacoEditor.prototype.revealPositionInCenter = function() {
|
||||
this.editor && this.editor.revealPositionInCenter(this.editor.getPosition());
|
||||
};
|
||||
|
||||
MonacoEditor.prototype.undo = function() {
|
||||
this.editor && this.editor.trigger("codeEditor", "undo");
|
||||
};
|
||||
|
||||
MonacoEditor.prototype.redo = function() {
|
||||
this.editor && this.editor.trigger("codeEditor", "redo");
|
||||
};
|
||||
|
||||
MonacoEditor.prototype._loadEvents = function() {
|
||||
while (this.events.length>0) {
|
||||
let event = this.events.shift();
|
||||
|
||||
Reference in New Issue
Block a user