Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/edit_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,9 @@ class EditSession {
// load on demand
this.$modeId = path;
config.loadModule(["mode", path], function(m) {
if (this.destroyed) {
return;
}
if (this.$modeId !== path)
return cb && cb();
if (this.$modes[path] && !options) {
Expand Down
23 changes: 18 additions & 5 deletions src/edit_session_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@

"test issue 83": function() {
var session = new EditSession("");
var editor = new Editor(new MockRenderer(), session);

Check warning on line 439 in src/edit_session_test.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'editor' is assigned a value but never used
var document = session.getDocument();

session.setUseWrapMode(true);
Expand All @@ -448,7 +448,7 @@

"test wrapMode init has to create wrapData array": function() {
var session = new EditSession("foo bar\nfoo bar");
var editor = new Editor(new MockRenderer(), session);

Check warning on line 451 in src/edit_session_test.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'editor' is assigned a value but never used

session.setUseWrapMode(true);
session.setWrapLimitRange(3, 3);
Expand Down Expand Up @@ -1125,7 +1125,17 @@
}
});
var session = new EditSession([]);
session.setMode("ace/mode/javascript");

var onChangeModeCallCount = 0;
var originalOnChangeMode = session.$onChangeMode;

// Create spy
session.$onChangeMode = function(...arguments) {
Copy link
Member

@nightwing nightwing Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the spy here? we already could see the call by effects it produces

onChangeModeCallCount++;
originalOnChangeMode.apply(this, arguments);
};

session.setMode("ace/mode/javascript");
assert.equal(session.$modeId, "ace/mode/javascript");

var modeChangeCallbacks = 0;
Expand All @@ -1147,12 +1157,15 @@
assert.equal(session.$mode.$id, "ace/mode/sh");
session.setMode("ace/mode/css");
assert.equal(session.$mode.$id, "ace/mode/sh");
// TODO this should not error
// session.destroy();
// destory session to check if the last mode which is being loaded is aborted or not
session.destroy();
setTimeout(function() {
next();
// check if last setmode is aborted due to destroy
assert.equal(onChangeModeCallCount, 4);
session.$onChangeMode = originalOnChangeMode;
next();
});
}, 0);
});
},

"test: sets destroyed flag when destroy called and tokenizer is never null": function() {
Expand Down
Loading