allow options object in setMode
This commit is contained in:
parent
0a61c37a3b
commit
07792dab9a
1 changed files with 36 additions and 36 deletions
|
|
@ -898,29 +898,6 @@ var EditSession = function(text, mode) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$modes = {};
|
this.$modes = {};
|
||||||
this._loadMode = function(name, callback) {
|
|
||||||
if (!this.$modes["null"])
|
|
||||||
this.$modes["null"] = this.$modes["ace/mode/text"] = new TextMode();
|
|
||||||
|
|
||||||
if (this.$modes[name])
|
|
||||||
return callback(this.$modes[name]);
|
|
||||||
|
|
||||||
var _self = this;
|
|
||||||
config.loadModule(["mode", name], function(module) {
|
|
||||||
if (_self.$modes[name])
|
|
||||||
return callback(_self.$modes[name]);
|
|
||||||
if (module && module.Mode) {
|
|
||||||
_self.$modes[name] = new module.Mode();
|
|
||||||
_self.$modes[name].$id = name;
|
|
||||||
callback(_self.$modes[name]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// set mode to text until loading is finished
|
|
||||||
if (!this.$mode)
|
|
||||||
this.$onChangeMode(_self.$modes["ace/mode/text"], true);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
|
@ -930,19 +907,42 @@ 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) {
|
||||||
// load on demand
|
if (mode && typeof mode === "object") {
|
||||||
if (!mode || typeof mode === "string") {
|
if (mode.getTokenizer)
|
||||||
var modeName = mode || "ace/mode/text";
|
return this.$onChangeMode(mode);
|
||||||
if (this.$modeId === modeName)
|
var options = mode;
|
||||||
return;
|
var path = options.path;
|
||||||
|
} else {
|
||||||
|
path = mode || "ace/mode/text";
|
||||||
|
}
|
||||||
|
|
||||||
this.$modeId = modeName;
|
// this is needed if ace isn't on require path (e.g tests in node)
|
||||||
this._loadMode(modeName, function(mode) {
|
if (!this.$modes["ace/mode/text"])
|
||||||
if (this.$modeId === modeName)
|
this.$modes["ace/mode/text"] = new TextMode();
|
||||||
this.$onChangeMode(mode);
|
|
||||||
|
if (this.$modes[path] && !options)
|
||||||
|
return this.$onChangeMode(this.$modes[path]);
|
||||||
|
|
||||||
|
// load on demand
|
||||||
|
this.$modeId = path;
|
||||||
|
config.loadModule(["mode", path], function(m) {
|
||||||
|
if (this.$modeId !== path)
|
||||||
|
return;
|
||||||
|
if (this.$modes[path] && !options)
|
||||||
|
return this.$onChangeMode(this.$modes[path]);
|
||||||
|
if (m && m.Mode) {
|
||||||
|
m = new m.Mode(options);
|
||||||
|
if (!options) {
|
||||||
|
this.$modes[path] = m;
|
||||||
|
m.$id = path;
|
||||||
|
}
|
||||||
|
this.$onChangeMode(m)
|
||||||
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
} else
|
|
||||||
this.$onChangeMode(mode);
|
// set mode to text until loading is finished
|
||||||
|
if (!this.$mode)
|
||||||
|
this.$onChangeMode(this.$modes["ace/mode/text"], true);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$onChangeMode = function(mode, $isPlaceholder) {
|
this.$onChangeMode = function(mode, $isPlaceholder) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue