Skip to content

Commit ea591e2

Browse files
author
Ruben Daniels
committed
Merge pull request ajaxorg#1479 from ajaxorg/pulreq
Fix timing issue with setting modes
2 parents 132d444 + 3667a15 commit ea591e2

6 files changed

Lines changed: 44 additions & 18 deletions

File tree

lib/ace/autocomplete.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,7 @@ Autocomplete.startCommand = {
246246
// needed for firefox on mac
247247
editor.completer.cancelContextMenu();
248248
},
249-
bindKey: "Ctrl-Space|Shift-Space|Alt-Space"
250-
};
251-
Autocomplete.addTo = function(editor) {
252-
editor.commands.addCommand(Autocomplete.startCommand);
249+
bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space"
253250
};
254251

255252
var FilteredList = function(array, mutateData) {

lib/ace/edit_session.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -865,11 +865,12 @@ var EditSession = function(text, mode) {
865865
/**
866866
* 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.
867867
* @param {TextMode} mode Set a new text mode
868+
* @param {cb} optional callback
868869
*
869870
**/
870871
this.$mode = null;
871872
this.$modeId = null;
872-
this.setMode = function(mode) {
873+
this.setMode = function(mode, cb) {
873874
if (mode && typeof mode === "object") {
874875
if (mode.getTokenizer)
875876
return this.$onChangeMode(mode);
@@ -890,7 +891,7 @@ var EditSession = function(text, mode) {
890891
this.$modeId = path;
891892
config.loadModule(["mode", path], function(m) {
892893
if (this.$modeId !== path)
893-
return;
894+
return cb && cb();
894895
if (this.$modes[path] && !options)
895896
return this.$onChangeMode(this.$modes[path]);
896897
if (m && m.Mode) {
@@ -899,7 +900,8 @@ var EditSession = function(text, mode) {
899900
this.$modes[path] = m;
900901
m.$id = path;
901902
}
902-
this.$onChangeMode(m)
903+
this.$onChangeMode(m);
904+
cb && cb(this.mode);
903905
}
904906
}.bind(this));
905907

@@ -909,7 +911,11 @@ var EditSession = function(text, mode) {
909911
};
910912

911913
this.$onChangeMode = function(mode, $isPlaceholder) {
912-
if (this.$mode === mode) return;
914+
if (!$isPlaceholder)
915+
this.$modeId = mode.$id;
916+
if (this.$mode === mode)
917+
return;
918+
913919
this.$mode = mode;
914920

915921
this.$stopWorker();
@@ -941,7 +947,6 @@ var EditSession = function(text, mode) {
941947

942948

943949
if (!$isPlaceholder) {
944-
this.$modeId = mode.$id;
945950
this.$setFolding(mode.foldingRules);
946951
this._emit("changeMode");
947952
this.bgTokenizer.start(0);

lib/ace/edit_session_test.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,11 +1037,34 @@ module.exports = {
10371037
assertArray(session.getAnnotations(), []);
10381038
session.setAnnotations([annotation]);
10391039
assertArray(session.getAnnotations(), [annotation]);
1040+
},
1041+
1042+
"test: mode loading" : function(next) {
1043+
if (!require.undef) {
1044+
console.log("Skipping test: This test only runs in the browser");
1045+
next();
1046+
return;
1047+
}
1048+
var session = new EditSession([]);
1049+
session.setMode("ace/mode/javascript");
1050+
assert.equal(session.$modeid, "ace/mode/javascript");
1051+
session.on("changeMode", function() {
1052+
assert.equal(session.$modeid, "ace/mode/javascript");
1053+
});
1054+
session.setMode("ace/mode/sh", function(mode) {
1055+
assert.ok(!mode);
1056+
});
1057+
setTimeout(function() {
1058+
session.setMode("ace/mode/javascript", function(mode) {
1059+
session.setMode("ace/mode/javascript");
1060+
assert.equal(session.$modeid, "ace/mode/javascript");
1061+
next();
1062+
});
1063+
}, 0);
10401064
}
10411065
};
1042-
10431066
});
10441067

10451068
if (typeof module !== "undefined" && module === require.main) {
1046-
require("asyncjs").test.testcase(module.exports).exec()
1069+
require("asyncjs").test.testcase(module.exports).exec();
10471070
}

lib/ace/keyboard/textinput.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var BROKEN_SETDATA = useragent.isChrome < 18;
4040
var TextInput = function(parentNode, host) {
4141
var text = dom.createElement("textarea");
4242
text.className = "ace_text-input";
43-
// debug
43+
/*/ debug
4444
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";
4545
/**/
4646
if (useragent.isTouchPad)
@@ -436,7 +436,7 @@ var TextInput = function(parentNode, host) {
436436
tempStyle = text.style.cssText;
437437

438438
text.style.cssText = "z-index:100000;" + (useragent.isIE ? "opacity:0.1;" : "");
439-
text.style.cssText += "background:rgba(250, 0, 0, 0.3); opacity:1;";
439+
//debug*/ text.style.cssText += "background:rgba(250, 0, 0, 0.3); opacity:1;";
440440

441441
resetSelection(host.selection.isEmpty());
442442
host._emit("nativecontextmenu", {target: host, domEvent: e});

lib/ace/selection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ var Selection = function(session) {
668668
while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch))
669669
index ++;
670670

671-
if (index <= 1) {
671+
if (index < 1) {
672672
tokenRe.lastIndex = 0;
673673
while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) {
674674
tokenRe.lastIndex = 0;

lib/ace/virtual_renderer.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,10 +1257,10 @@ var VirtualRenderer = function(container, theme) {
12571257
/**
12581258
* [Sets a new theme for the editor. `theme` should exist, and be a directory path, like `ace/theme/textmate`.]{: #VirtualRenderer.setTheme}
12591259
* @param {String} theme The path to a theme
1260-
*
1260+
* @param {Function} cb optional callback
12611261
*
12621262
**/
1263-
this.setTheme = function(theme) {
1263+
this.setTheme = function(theme, cb) {
12641264
var _self = this;
12651265
this.$themeValue = theme;
12661266
_self._dispatchEvent('themeChange',{theme:theme});
@@ -1274,7 +1274,7 @@ var VirtualRenderer = function(container, theme) {
12741274

12751275
function afterLoad(module) {
12761276
if (_self.$themeValue != theme)
1277-
return;
1277+
return cb && cb();
12781278
if (!module.cssClass)
12791279
return;
12801280
dom.importCssString(
@@ -1303,7 +1303,8 @@ var VirtualRenderer = function(container, theme) {
13031303
_self.onResize();
13041304
}
13051305

1306-
_self._dispatchEvent('themeLoaded',{theme:module});
1306+
_self._dispatchEvent('themeLoaded', {theme:module});
1307+
cb && cb();
13071308
}
13081309
};
13091310

0 commit comments

Comments
 (0)