diff --git a/resources/assets/js/components/AceEditor.vue b/resources/assets/js/components/AceEditor.vue index 1c8640acd..e62cec5a0 100644 --- a/resources/assets/js/components/AceEditor.vue +++ b/resources/assets/js/components/AceEditor.vue @@ -210,8 +210,7 @@ export default { } // set value and clear selection - this.editor.setValue(this.value) - this.editor.clearSelection() + this.setValue(this.value) // set ace editor options and theme this.editor.setOptions(this.options) @@ -264,6 +263,17 @@ export default { this.$nextTick(() => this.editor && this.editor.resize()) }, + /** + * 设置内容 + * @param value + */ + setValue(value) { + if (typeof value === "string" && this.editor) { + this.editor.setValue(value) + this.editor.clearSelection() + } + }, + /** * 获取文件类型 * @returns {string} @@ -359,8 +369,7 @@ export default { if (newCode == this.code) { return; } - this.editor.setValue(newCode) - this.editor.clearSelection() + this.setValue(newCode) const {row, column} = this.cursorPosition // move cursor to current position this.editor.selection.moveCursorTo(row, column)