diff --git a/demo/kitchen-sink/demo.js b/demo/kitchen-sink/demo.js index 6081a2512a..27ed606b6b 100644 --- a/demo/kitchen-sink/demo.js +++ b/demo/kitchen-sink/demo.js @@ -504,6 +504,7 @@ function updateUIEditorOptions() { env.editor.on("changeSession", function() { for (var i in env.editor.session.$options) { + if (i == "mode") continue; var value = util.getOption(i); if (value != undefined) { env.editor.setOption(i, value); diff --git a/demo/test_package/index.ts b/demo/test_package/index.ts index 055c48d596..cd417fcbd9 100644 --- a/demo/test_package/index.ts +++ b/demo/test_package/index.ts @@ -158,6 +158,11 @@ editor.commands.on('exec', ({editor, command}) => { console.log(editor.getValue(), command.name); }); +editor.setSession(null); +console.log(editor.destroyed); +editor.destroy(); +console.log(editor.destroyed); + const diffViewOptions: DiffViewOptions = { maxDiffs: 1000, folding: true @@ -170,4 +175,4 @@ var diffView = createDiffView({ diffView.setProvider(new DiffProvider()); -diffView.destroy(); \ No newline at end of file +diffView.destroy(); diff --git a/src/editor.js b/src/editor.js index 9f162c18c9..f97042468d 100644 --- a/src/editor.js +++ b/src/editor.js @@ -242,7 +242,7 @@ class Editor { /** * Sets a new editsession to use. This method also emits the `'changeSession'` event. - * @param {EditSession} [session] The new session to use + * @param {EditSession|null} [session] The new session to use **/ setSession(session) { if (this.session == session) @@ -2690,11 +2690,12 @@ class Editor { * Cleans up the entire editor. **/ destroy() { + this.destroyed = true; if (this.$toDestroy) { this.$toDestroy.forEach(function(el) { el.destroy(); }); - this.$toDestroy = null; + this.$toDestroy = []; } if (this.$mouseHandler) this.$mouseHandler.destroy(); @@ -2841,12 +2842,16 @@ config.defineOptions(Editor.prototype, "editor", { readOnly: { set: function(/**@type{boolean}*/readOnly) { this.textInput.setReadOnly(readOnly); + if (this.destroyed) return; this.$resetCursorStyle(); if (!this.$readOnlyCallback) { this.$readOnlyCallback = (e) => { var shouldShow = false; if (e && e.type == "keydown") { - shouldShow = e && e.key && e.key.length == 1 && !e.ctrlKey && !e.metaKey; + if (e && e.key && !e.ctrlKey && !e.metaKey) { + if (e.key == " ") e.preventDefault(); + shouldShow = e.key.length == 1; + } if (!shouldShow) return; } else if (e && e.type !== "exec") { shouldShow = true; diff --git a/src/ext/searchbox.js b/src/ext/searchbox.js index 3345d6f582..0b5cf0b646 100644 --- a/src/ext/searchbox.js +++ b/src/ext/searchbox.js @@ -224,6 +224,7 @@ class SearchBox { * @param {any} [preventScroll] */ find(skipCurrent, backwards, preventScroll) { + if (!this.editor.session) return; var range = this.editor.find(this.searchInput.value, { skipCurrent: skipCurrent, backwards: backwards, diff --git a/types/ace-modules.d.ts b/types/ace-modules.d.ts index c7834a76a4..50d232983b 100644 --- a/types/ace-modules.d.ts +++ b/types/ace-modules.d.ts @@ -2147,9 +2147,9 @@ declare module "ace-code/src/editor" { getKeyboardHandler(): any; /** * Sets a new editsession to use. This method also emits the `'changeSession'` event. - * @param {EditSession} [session] The new session to use + * @param {EditSession|null} [session] The new session to use **/ - setSession(session?: EditSession): void; + setSession(session?: EditSession | null): void; selection: import("ace-code/src/selection").Selection; /** * Returns the current session being used. @@ -2752,6 +2752,10 @@ declare module "ace-code/src/editor" { * Cleans up the entire editor. **/ destroy(): void; + /** + * true if editor is destroyed + */ + destroyed: boolean; /** * Enables automatic scrolling of the cursor into view when editor itself is inside scrollable element * @param {Boolean} enable default true