timing issue with setting modes

This commit is contained in:
nightwing 2013-06-20 17:49:59 +04:00
commit 4b51b9288f
2 changed files with 35 additions and 7 deletions

View file

@ -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);