allow options object in setMode

This commit is contained in:
nightwing 2012-12-15 16:42:51 +04:00
commit 07792dab9a

View file

@ -898,29 +898,6 @@ var EditSession = function(text, mode) {
};
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.
@ -930,21 +907,44 @@ var EditSession = function(text, mode) {
this.$mode = null;
this.$modeId = null;
this.setMode = function(mode) {
// load on demand
if (!mode || typeof mode === "string") {
var modeName = mode || "ace/mode/text";
if (this.$modeId === modeName)
return;
if (mode && typeof mode === "object") {
if (mode.getTokenizer)
return this.$onChangeMode(mode);
var options = mode;
var path = options.path;
} else {
path = mode || "ace/mode/text";
}
this.$modeId = modeName;
this._loadMode(modeName, function(mode) {
if (this.$modeId === modeName)
this.$onChangeMode(mode);
}.bind(this));
} else
this.$onChangeMode(mode);
// this is needed if ace isn't on require path (e.g tests in node)
if (!this.$modes["ace/mode/text"])
this.$modes["ace/mode/text"] = new TextMode();
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));
// set mode to text until loading is finished
if (!this.$mode)
this.$onChangeMode(this.$modes["ace/mode/text"], true);
};
this.$onChangeMode = function(mode, $isPlaceholder) {
if (this.$mode === mode) return;
this.$mode = mode;