Merge pull request #1479 from ajaxorg/pulreq

Fix timing issue with setting modes
This commit is contained in:
Ruben Daniels 2013-06-20 07:08:11 -07:00
commit ea591e2149
6 changed files with 44 additions and 18 deletions

View file

@ -246,10 +246,7 @@ Autocomplete.startCommand = {
// needed for firefox on mac // needed for firefox on mac
editor.completer.cancelContextMenu(); editor.completer.cancelContextMenu();
}, },
bindKey: "Ctrl-Space|Shift-Space|Alt-Space" bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space"
};
Autocomplete.addTo = function(editor) {
editor.commands.addCommand(Autocomplete.startCommand);
}; };
var FilteredList = function(array, mutateData) { var FilteredList = function(array, mutateData) {

View file

@ -865,11 +865,12 @@ var EditSession = function(text, mode) {
/** /**
* 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.
* @param {TextMode} mode Set a new text mode * @param {TextMode} mode Set a new text mode
* @param {cb} optional callback
* *
**/ **/
this.$mode = null; this.$mode = null;
this.$modeId = null; this.$modeId = null;
this.setMode = function(mode) { this.setMode = function(mode, cb) {
if (mode && typeof mode === "object") { if (mode && typeof mode === "object") {
if (mode.getTokenizer) if (mode.getTokenizer)
return this.$onChangeMode(mode); return this.$onChangeMode(mode);
@ -890,7 +891,7 @@ var EditSession = function(text, mode) {
this.$modeId = path; this.$modeId = path;
config.loadModule(["mode", path], function(m) { config.loadModule(["mode", path], function(m) {
if (this.$modeId !== path) if (this.$modeId !== path)
return; return cb && cb();
if (this.$modes[path] && !options) if (this.$modes[path] && !options)
return this.$onChangeMode(this.$modes[path]); return this.$onChangeMode(this.$modes[path]);
if (m && m.Mode) { if (m && m.Mode) {
@ -899,7 +900,8 @@ var EditSession = function(text, mode) {
this.$modes[path] = m; this.$modes[path] = m;
m.$id = path; m.$id = path;
} }
this.$onChangeMode(m) this.$onChangeMode(m);
cb && cb(this.mode);
} }
}.bind(this)); }.bind(this));
@ -909,7 +911,11 @@ var EditSession = function(text, mode) {
}; };
this.$onChangeMode = function(mode, $isPlaceholder) { this.$onChangeMode = function(mode, $isPlaceholder) {
if (this.$mode === mode) return; if (!$isPlaceholder)
this.$modeId = mode.$id;
if (this.$mode === mode)
return;
this.$mode = mode; this.$mode = mode;
this.$stopWorker(); this.$stopWorker();
@ -941,7 +947,6 @@ var EditSession = function(text, mode) {
if (!$isPlaceholder) { if (!$isPlaceholder) {
this.$modeId = mode.$id;
this.$setFolding(mode.foldingRules); this.$setFolding(mode.foldingRules);
this._emit("changeMode"); this._emit("changeMode");
this.bgTokenizer.start(0); this.bgTokenizer.start(0);

View file

@ -1037,11 +1037,34 @@ module.exports = {
assertArray(session.getAnnotations(), []); assertArray(session.getAnnotations(), []);
session.setAnnotations([annotation]); session.setAnnotations([annotation]);
assertArray(session.getAnnotations(), [annotation]); assertArray(session.getAnnotations(), [annotation]);
},
"test: mode loading" : function(next) {
if (!require.undef) {
console.log("Skipping test: This test only runs in the browser");
next();
return;
}
var session = new EditSession([]);
session.setMode("ace/mode/javascript");
assert.equal(session.$modeid, "ace/mode/javascript");
session.on("changeMode", function() {
assert.equal(session.$modeid, "ace/mode/javascript");
});
session.setMode("ace/mode/sh", function(mode) {
assert.ok(!mode);
});
setTimeout(function() {
session.setMode("ace/mode/javascript", function(mode) {
session.setMode("ace/mode/javascript");
assert.equal(session.$modeid, "ace/mode/javascript");
next();
});
}, 0);
} }
}; };
}); });
if (typeof module !== "undefined" && module === require.main) { if (typeof module !== "undefined" && module === require.main) {
require("asyncjs").test.testcase(module.exports).exec() require("asyncjs").test.testcase(module.exports).exec();
} }

View file

@ -40,7 +40,7 @@ var BROKEN_SETDATA = useragent.isChrome < 18;
var TextInput = function(parentNode, host) { var TextInput = function(parentNode, host) {
var text = dom.createElement("textarea"); var text = dom.createElement("textarea");
text.className = "ace_text-input"; text.className = "ace_text-input";
// debug /*/ debug
text.style.cssText = "opacity:1;background:rgba(0, 250, 0, 0.3);outline:rgba(0, 250, 0, 0.8) solid 1px;outline-offset:3px;width:5em;z-pindex:500"; text.style.cssText = "opacity:1;background:rgba(0, 250, 0, 0.3);outline:rgba(0, 250, 0, 0.8) solid 1px;outline-offset:3px;width:5em;z-pindex:500";
/**/ /**/
if (useragent.isTouchPad) if (useragent.isTouchPad)
@ -436,7 +436,7 @@ var TextInput = function(parentNode, host) {
tempStyle = text.style.cssText; tempStyle = text.style.cssText;
text.style.cssText = "z-index:100000;" + (useragent.isIE ? "opacity:0.1;" : ""); text.style.cssText = "z-index:100000;" + (useragent.isIE ? "opacity:0.1;" : "");
text.style.cssText += "background:rgba(250, 0, 0, 0.3); opacity:1;"; //debug*/ text.style.cssText += "background:rgba(250, 0, 0, 0.3); opacity:1;";
resetSelection(host.selection.isEmpty()); resetSelection(host.selection.isEmpty());
host._emit("nativecontextmenu", {target: host, domEvent: e}); host._emit("nativecontextmenu", {target: host, domEvent: e});

View file

@ -668,7 +668,7 @@ var Selection = function(session) {
while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch)) while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
index ++; index ++;
if (index <= 1) { if (index < 1) {
tokenRe.lastIndex = 0; tokenRe.lastIndex = 0;
while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) { while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
tokenRe.lastIndex = 0; tokenRe.lastIndex = 0;

View file

@ -1257,10 +1257,10 @@ var VirtualRenderer = function(container, theme) {
/** /**
* [Sets a new theme for the editor. `theme` should exist, and be a directory path, like `ace/theme/textmate`.]{: #VirtualRenderer.setTheme} * [Sets a new theme for the editor. `theme` should exist, and be a directory path, like `ace/theme/textmate`.]{: #VirtualRenderer.setTheme}
* @param {String} theme The path to a theme * @param {String} theme The path to a theme
* * @param {Function} cb optional callback
* *
**/ **/
this.setTheme = function(theme) { this.setTheme = function(theme, cb) {
var _self = this; var _self = this;
this.$themeValue = theme; this.$themeValue = theme;
_self._dispatchEvent('themeChange',{theme:theme}); _self._dispatchEvent('themeChange',{theme:theme});
@ -1274,7 +1274,7 @@ var VirtualRenderer = function(container, theme) {
function afterLoad(module) { function afterLoad(module) {
if (_self.$themeValue != theme) if (_self.$themeValue != theme)
return; return cb && cb();
if (!module.cssClass) if (!module.cssClass)
return; return;
dom.importCssString( dom.importCssString(
@ -1303,7 +1303,8 @@ var VirtualRenderer = function(container, theme) {
_self.onResize(); _self.onResize();
} }
_self._dispatchEvent('themeLoaded',{theme:module}); _self._dispatchEvent('themeLoaded', {theme:module});
cb && cb();
} }
}; };