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
|
||||
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.
|
||||
|
|
@ -948,25 +930,22 @@ var EditSession = function(text, mode) {
|
|||
this.$mode = null;
|
||||
this.$modeId = null;
|
||||
this.setMode = function(mode) {
|
||||
mode = mode || "null";
|
||||
// load on demand
|
||||
if (typeof mode === "string") {
|
||||
if (this.$modeId == mode)
|
||||
if (!mode || typeof mode === "string") {
|
||||
var modeName = mode || "ace/mode/text";
|
||||
if (this.$modeId === modeName)
|
||||
return;
|
||||
|
||||
this.$modeId = mode;
|
||||
var _self = this;
|
||||
this._loadMode(mode, function(module) {
|
||||
if (_self.$modeId !== mode)
|
||||
return;
|
||||
|
||||
_self.$onChangeMode(module);
|
||||
});
|
||||
this.$modeId = modeName;
|
||||
this._loadMode(modeName, function(mode) {
|
||||
if (this.$modeId === modeName)
|
||||
this.$onChangeMode(mode);
|
||||
}.bind(this));
|
||||
} else
|
||||
_self.$onChangeMode(module);
|
||||
}
|
||||
this.$onChangeMode(mode);
|
||||
};
|
||||
|
||||
this.$onChangeMode = function(mode) {
|
||||
this.$onChangeMode = function(mode, $isPlaceholder) {
|
||||
if (this.$mode === mode) return;
|
||||
this.$mode = mode;
|
||||
this.$modeId = mode.$id;
|
||||
|
|
@ -994,14 +973,16 @@ var EditSession = function(text, mode) {
|
|||
}
|
||||
|
||||
this.bgTokenizer.setDocument(this.getDocument());
|
||||
this.bgTokenizer.start(0);
|
||||
|
||||
this.tokenRe = mode.tokenRe;
|
||||
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