setting mode to same string shouldn't reset it

This commit is contained in:
nightwing 2012-04-29 23:33:37 +04:00
commit 51f8f87a98

View file

@ -487,7 +487,7 @@ var EditSession = function(text, mode) {
this._loadMode = function(mode, callback) {
if (this.$modes[mode])
return callback(this.$modes[mode]);
var _self = this;
var module;
try {
@ -495,15 +495,15 @@ var EditSession = function(text, mode) {
} catch (e) {};
if (module)
return done(module);
fetch(function() {
require([mode], done);
});
function done(module) {
if (_self.$modes[mode])
return callback(_self.$modes[mode]);
_self.$modes[mode] = new module.Mode();
_self.$modes[mode].$id = mode;
_self._emit("loadmode", {
@ -516,7 +516,7 @@ var EditSession = function(text, mode) {
function fetch(callback) {
if (!config.get("packaged"))
return callback();
var base = mode.split("/").pop();
var filename = config.get("modePath") + "/mode-" + base + config.get("suffix");
net.loadScript(filename, callback);
@ -524,30 +524,33 @@ var EditSession = function(text, mode) {
};
this.$mode = null;
this.$origMode = null;
this.$modeId = null;
this.setMode = function(mode) {
// load on demand
if (typeof mode === "string") {
this.$origMode = mode;
if (this.$modeId == mode)
return;
this.$modeId = mode;
var _self = this;
this._loadMode(mode, function(module) {
if (_self.$origMode !== mode)
if (_self.$modeId !== mode)
return;
_self.setMode(module);
});
return;
} else if (mode == null) {
mode = "ace/mode/text"
this.$origMode = mode;
this.$modeId = mode;
this.$modes[mode] = this.$modes[mode] || (new TextMode());
this.setMode(this.$modes[mode]);
return;
}
if (this.$mode === mode) return;
this.$mode = mode;
this.$modeId = mode.$id;
this.$stopWorker();
@ -606,7 +609,7 @@ var EditSession = function(text, mode) {
this.getMode = function() {
return this.$mode;
};
this.$scrollTop = 0;
this.setScrollTop = function(scrollTop) {
scrollTop = Math.round(Math.max(0, scrollTop));
@ -620,7 +623,7 @@ var EditSession = function(text, mode) {
this.getScrollTop = function() {
return this.$scrollTop;
};
this.$scrollLeft = 0;
this.setScrollLeft = function(scrollLeft) {
scrollLeft = Math.round(Math.max(0, scrollLeft));
@ -758,7 +761,7 @@ var EditSession = function(text, mode) {
this.selection.setSelectionRange(lastUndoRange);
return lastUndoRange;
};
this.setUndoSelect = function(enable) {
this.$undoSelect = enable;
};
@ -959,7 +962,7 @@ var EditSession = function(text, mode) {
range.start.column
);
}
var len = this.doc.getLength() - 1;
if (range.end.row > len) {
range.end.row = len;