timing issue with setting modes
This commit is contained in:
parent
fa13f377e1
commit
4b51b9288f
2 changed files with 35 additions and 7 deletions
|
|
@ -865,11 +865,12 @@ var EditSession = function(text, mode) {
|
|||
/**
|
||||
* Sets a new text mode for the `EditSession`. This method also emits the `'changeMode'` event. If a [[BackgroundTokenizer `BackgroundTokenizer`]] is set, the `'tokenizerUpdate'` event is also emitted.
|
||||
* @param {TextMode} mode Set a new text mode
|
||||
* @param {cb} optional callback
|
||||
*
|
||||
**/
|
||||
this.$mode = null;
|
||||
this.$modeId = null;
|
||||
this.setMode = function(mode) {
|
||||
this.setMode = function(mode, cb) {
|
||||
if (mode && typeof mode === "object") {
|
||||
if (mode.getTokenizer)
|
||||
return this.$onChangeMode(mode);
|
||||
|
|
@ -890,7 +891,7 @@ var EditSession = function(text, mode) {
|
|||
this.$modeId = path;
|
||||
config.loadModule(["mode", path], function(m) {
|
||||
if (this.$modeId !== path)
|
||||
return;
|
||||
return cb && cb();
|
||||
if (this.$modes[path] && !options)
|
||||
return this.$onChangeMode(this.$modes[path]);
|
||||
if (m && m.Mode) {
|
||||
|
|
@ -899,7 +900,8 @@ var EditSession = function(text, mode) {
|
|||
this.$modes[path] = m;
|
||||
m.$id = path;
|
||||
}
|
||||
this.$onChangeMode(m)
|
||||
this.$onChangeMode(m);
|
||||
cb && cb(this.mode);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
|
|
@ -909,7 +911,11 @@ var EditSession = function(text, mode) {
|
|||
};
|
||||
|
||||
this.$onChangeMode = function(mode, $isPlaceholder) {
|
||||
if (this.$mode === mode) return;
|
||||
if (!$isPlaceholder)
|
||||
this.$modeId = mode.$id;
|
||||
if (this.$mode === mode)
|
||||
return;
|
||||
|
||||
this.$mode = mode;
|
||||
|
||||
this.$stopWorker();
|
||||
|
|
@ -941,7 +947,6 @@ var EditSession = function(text, mode) {
|
|||
|
||||
|
||||
if (!$isPlaceholder) {
|
||||
this.$modeId = mode.$id;
|
||||
this.$setFolding(mode.foldingRules);
|
||||
this._emit("changeMode");
|
||||
this.bgTokenizer.start(0);
|
||||
|
|
|
|||
|
|
@ -1037,11 +1037,34 @@ module.exports = {
|
|||
assertArray(session.getAnnotations(), []);
|
||||
session.setAnnotations([annotation]);
|
||||
assertArray(session.getAnnotations(), [annotation]);
|
||||
},
|
||||
|
||||
"test: mode loading" : function(next) {
|
||||
if (!require.undef) {
|
||||
console.log("Skipping test: This test only runs in the browser");
|
||||
next();
|
||||
return;
|
||||
}
|
||||
var session = new EditSession([]);
|
||||
session.setMode("ace/mode/javascript");
|
||||
assert.equal(session.$modeid, "ace/mode/javascript");
|
||||
session.on("changeMode", function() {
|
||||
assert.equal(session.$modeid, "ace/mode/javascript");
|
||||
});
|
||||
session.setMode("ace/mode/sh", function(mode) {
|
||||
assert.ok(!mode);
|
||||
});
|
||||
setTimeout(function() {
|
||||
session.setMode("ace/mode/javascript", function(mode) {
|
||||
session.setMode("ace/mode/javascript");
|
||||
assert.equal(session.$modeid, "ace/mode/javascript");
|
||||
next();
|
||||
});
|
||||
}, 0);
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
if (typeof module !== "undefined" && module === require.main) {
|
||||
require("asyncjs").test.testcase(module.exports).exec()
|
||||
require("asyncjs").test.testcase(module.exports).exec();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue