cleanup mode loading
This commit is contained in:
parent
ffadbe44bf
commit
e6671462cd
1 changed files with 17 additions and 36 deletions
|
|
@ -918,27 +918,9 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
// set mode to text until loading is finished
|
// set mode to text until loading is finished
|
||||||
if (!this.$mode)
|
if (!this.$mode)
|
||||||
this.$setModePlaceholder();
|
this.$onChangeMode(_self.$modes["ace/mode/text"], true);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$setModePlaceholder = function() {
|
|
||||||
this.$mode = this.$modes["null"];
|
|
||||||
var tokenizer = this.$mode.getTokenizer();
|
|
||||||
|
|
||||||
if (!this.bgTokenizer) {
|
|
||||||
this.bgTokenizer = new BackgroundTokenizer(tokenizer);
|
|
||||||
var _self = this;
|
|
||||||
this.bgTokenizer.addEventListener("update", function(e) {
|
|
||||||
_self._emit("tokenizerUpdate", e);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.bgTokenizer.setTokenizer(tokenizer);
|
|
||||||
}
|
|
||||||
this.bgTokenizer.setDocument(this.getDocument());
|
|
||||||
|
|
||||||
this.tokenRe = this.$mode.tokenRe;
|
|
||||||
this.nonTokenRe = this.$mode.nonTokenRe;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
* 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.
|
||||||
|
|
@ -948,25 +930,22 @@ var EditSession = function(text, mode) {
|
||||||
this.$mode = null;
|
this.$mode = null;
|
||||||
this.$modeId = null;
|
this.$modeId = null;
|
||||||
this.setMode = function(mode) {
|
this.setMode = function(mode) {
|
||||||
mode = mode || "null";
|
|
||||||
// load on demand
|
// load on demand
|
||||||
if (typeof mode === "string") {
|
if (!mode || typeof mode === "string") {
|
||||||
if (this.$modeId == mode)
|
var modeName = mode || "ace/mode/text";
|
||||||
|
if (this.$modeId === modeName)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.$modeId = mode;
|
this.$modeId = modeName;
|
||||||
var _self = this;
|
this._loadMode(modeName, function(mode) {
|
||||||
this._loadMode(mode, function(module) {
|
if (this.$modeId === modeName)
|
||||||
if (_self.$modeId !== mode)
|
this.$onChangeMode(mode);
|
||||||
return;
|
}.bind(this));
|
||||||
|
|
||||||
_self.$onChangeMode(module);
|
|
||||||
});
|
|
||||||
} else
|
} else
|
||||||
_self.$onChangeMode(module);
|
this.$onChangeMode(mode);
|
||||||
}
|
};
|
||||||
|
|
||||||
this.$onChangeMode = function(mode) {
|
this.$onChangeMode = function(mode, $isPlaceholder) {
|
||||||
if (this.$mode === mode) return;
|
if (this.$mode === mode) return;
|
||||||
this.$mode = mode;
|
this.$mode = mode;
|
||||||
this.$modeId = mode.$id;
|
this.$modeId = mode.$id;
|
||||||
|
|
@ -994,14 +973,16 @@ var EditSession = function(text, mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.bgTokenizer.setDocument(this.getDocument());
|
this.bgTokenizer.setDocument(this.getDocument());
|
||||||
this.bgTokenizer.start(0);
|
|
||||||
|
|
||||||
this.tokenRe = mode.tokenRe;
|
this.tokenRe = mode.tokenRe;
|
||||||
this.nonTokenRe = mode.nonTokenRe;
|
this.nonTokenRe = mode.nonTokenRe;
|
||||||
|
|
||||||
this.$setFolding(mode.foldingRules);
|
|
||||||
|
|
||||||
this._emit("changeMode");
|
if (!$isPlaceholder) {
|
||||||
|
this.$setFolding(mode.foldingRules);
|
||||||
|
this._emit("changeMode");
|
||||||
|
this.bgTokenizer.start(0);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue