Skip to content

add editor.destroyed property #5785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions demo/kitchen-sink/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,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);
Expand Down
7 changes: 6 additions & 1 deletion demo/test_package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,9 @@ editor.commands.on('afterExec', ({editor, command}) => {

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);
11 changes: 8 additions & 3 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -2689,11 +2689,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();
Expand Down Expand Up @@ -2840,12 +2841,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;
Expand Down
1 change: 1 addition & 0 deletions src/ext/searchbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,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,
Expand Down
8 changes: 6 additions & 2 deletions types/ace-modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2072,9 +2072,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.
Expand Down Expand Up @@ -2676,6 +2676,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
Expand Down