setting mode to same string shouldn't reset it
This commit is contained in:
parent
9ae7bc0c04
commit
51f8f87a98
1 changed files with 19 additions and 16 deletions
|
|
@ -487,7 +487,7 @@ var EditSession = function(text, mode) {
|
||||||
this._loadMode = function(mode, callback) {
|
this._loadMode = function(mode, callback) {
|
||||||
if (this.$modes[mode])
|
if (this.$modes[mode])
|
||||||
return callback(this.$modes[mode]);
|
return callback(this.$modes[mode]);
|
||||||
|
|
||||||
var _self = this;
|
var _self = this;
|
||||||
var module;
|
var module;
|
||||||
try {
|
try {
|
||||||
|
|
@ -495,15 +495,15 @@ var EditSession = function(text, mode) {
|
||||||
} catch (e) {};
|
} catch (e) {};
|
||||||
if (module)
|
if (module)
|
||||||
return done(module);
|
return done(module);
|
||||||
|
|
||||||
fetch(function() {
|
fetch(function() {
|
||||||
require([mode], done);
|
require([mode], done);
|
||||||
});
|
});
|
||||||
|
|
||||||
function done(module) {
|
function done(module) {
|
||||||
if (_self.$modes[mode])
|
if (_self.$modes[mode])
|
||||||
return callback(_self.$modes[mode]);
|
return callback(_self.$modes[mode]);
|
||||||
|
|
||||||
_self.$modes[mode] = new module.Mode();
|
_self.$modes[mode] = new module.Mode();
|
||||||
_self.$modes[mode].$id = mode;
|
_self.$modes[mode].$id = mode;
|
||||||
_self._emit("loadmode", {
|
_self._emit("loadmode", {
|
||||||
|
|
@ -516,7 +516,7 @@ var EditSession = function(text, mode) {
|
||||||
function fetch(callback) {
|
function fetch(callback) {
|
||||||
if (!config.get("packaged"))
|
if (!config.get("packaged"))
|
||||||
return callback();
|
return callback();
|
||||||
|
|
||||||
var base = mode.split("/").pop();
|
var base = mode.split("/").pop();
|
||||||
var filename = config.get("modePath") + "/mode-" + base + config.get("suffix");
|
var filename = config.get("modePath") + "/mode-" + base + config.get("suffix");
|
||||||
net.loadScript(filename, callback);
|
net.loadScript(filename, callback);
|
||||||
|
|
@ -524,30 +524,33 @@ var EditSession = function(text, mode) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$mode = null;
|
this.$mode = null;
|
||||||
this.$origMode = null;
|
this.$modeId = null;
|
||||||
this.setMode = function(mode) {
|
this.setMode = function(mode) {
|
||||||
// load on demand
|
// load on demand
|
||||||
if (typeof mode === "string") {
|
if (typeof mode === "string") {
|
||||||
this.$origMode = mode;
|
if (this.$modeId == mode)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.$modeId = mode;
|
||||||
var _self = this;
|
var _self = this;
|
||||||
this._loadMode(mode, function(module) {
|
this._loadMode(mode, function(module) {
|
||||||
if (_self.$origMode !== mode)
|
if (_self.$modeId !== mode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_self.setMode(module);
|
_self.setMode(module);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
} else if (mode == null) {
|
} else if (mode == null) {
|
||||||
mode = "ace/mode/text"
|
mode = "ace/mode/text"
|
||||||
this.$origMode = mode;
|
this.$modeId = mode;
|
||||||
this.$modes[mode] = this.$modes[mode] || (new TextMode());
|
this.$modes[mode] = this.$modes[mode] || (new TextMode());
|
||||||
this.setMode(this.$modes[mode]);
|
this.setMode(this.$modes[mode]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.$mode === mode) return;
|
if (this.$mode === mode) return;
|
||||||
this.$mode = mode;
|
this.$mode = mode;
|
||||||
|
this.$modeId = mode.$id;
|
||||||
|
|
||||||
this.$stopWorker();
|
this.$stopWorker();
|
||||||
|
|
||||||
|
|
@ -606,7 +609,7 @@ var EditSession = function(text, mode) {
|
||||||
this.getMode = function() {
|
this.getMode = function() {
|
||||||
return this.$mode;
|
return this.$mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$scrollTop = 0;
|
this.$scrollTop = 0;
|
||||||
this.setScrollTop = function(scrollTop) {
|
this.setScrollTop = function(scrollTop) {
|
||||||
scrollTop = Math.round(Math.max(0, scrollTop));
|
scrollTop = Math.round(Math.max(0, scrollTop));
|
||||||
|
|
@ -620,7 +623,7 @@ var EditSession = function(text, mode) {
|
||||||
this.getScrollTop = function() {
|
this.getScrollTop = function() {
|
||||||
return this.$scrollTop;
|
return this.$scrollTop;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$scrollLeft = 0;
|
this.$scrollLeft = 0;
|
||||||
this.setScrollLeft = function(scrollLeft) {
|
this.setScrollLeft = function(scrollLeft) {
|
||||||
scrollLeft = Math.round(Math.max(0, scrollLeft));
|
scrollLeft = Math.round(Math.max(0, scrollLeft));
|
||||||
|
|
@ -758,7 +761,7 @@ var EditSession = function(text, mode) {
|
||||||
this.selection.setSelectionRange(lastUndoRange);
|
this.selection.setSelectionRange(lastUndoRange);
|
||||||
return lastUndoRange;
|
return lastUndoRange;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setUndoSelect = function(enable) {
|
this.setUndoSelect = function(enable) {
|
||||||
this.$undoSelect = enable;
|
this.$undoSelect = enable;
|
||||||
};
|
};
|
||||||
|
|
@ -959,7 +962,7 @@ var EditSession = function(text, mode) {
|
||||||
range.start.column
|
range.start.column
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var len = this.doc.getLength() - 1;
|
var len = this.doc.getLength() - 1;
|
||||||
if (range.end.row > len) {
|
if (range.end.row > len) {
|
||||||
range.end.row = len;
|
range.end.row = len;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue