update highlighting when mode is changed

This commit is contained in:
Harutyun Amirjanyan 2012-10-04 03:25:48 -04:00
commit 201210fefa

View file

@ -23,40 +23,43 @@ var editor2 = window.editor2 = splitEditor.editor1;
new TokenTooltip(editor2); new TokenTooltip(editor2);
var timeout = null; var timeout = null;
schedule = function() { var schedule = function() {
if(timeout != null) { if (timeout != null) {
clearTimeout(timeout); clearTimeout(timeout);
} }
timeout = setTimeout(run, 800); timeout = setTimeout(run, 800);
}; };
setAutorunEnabled = function(val) { var setAutorunEnabled = function(val) {
if (val) if (val)
editor1.on('change', schedule); editor1.on('change', schedule);
else else
editor1.removeEventListener('change', schedule); editor1.removeEventListener('change', schedule);
} };
util.bindCheckbox("autorunEl", setAutorunEnabled); util.bindCheckbox("autorunEl", setAutorunEnabled);
docEl = document.getElementById("doc"); var docEl = document.getElementById("doc");
util.fillDropdown(docEl, doclist.docs); util.fillDropdown(docEl, doclist.docs);
util.bindDropdown("doc", function(value) { util.bindDropdown("doc", function(value) {
doclist.loadDoc(value, function(session) { doclist.loadDoc(value, function(session) {
if (session) { if (session) {
editor2.setSession(session); editor2.setSession(session);
} }
}) });
}); });
modeEl = document.getElementById("modeEl"); var modeEl = document.getElementById("modeEl");
util.fillDropdown(modeEl, modelist.modes); util.fillDropdown(modeEl, modelist.modes);
var modeSessions = {}; var modeSessions = {};
util.bindDropdown(modeEl, function(value) { util.bindDropdown(modeEl, function(value) {
if (modeSessions[value]) if (modeSessions[value]) {
editor1.setSession(modeSessions[value]); editor1.setSession(modeSessions[value]);
schedule();
return;
}
var hp = "./lib/ace/mode/" + value + "_highlight_rules.js"; var hp = "./lib/ace/mode/" + value + "_highlight_rules.js";
net.get(hp, function(text) { net.get(hp, function(text) {
text = util.stripLeadingComments(text); text = util.stripLeadingComments(text);
@ -67,6 +70,7 @@ util.bindDropdown(modeEl, function(value) {
session.setMode("ace/mode/javascript"); session.setMode("ace/mode/javascript");
editor1.setSession(modeSessions[value]); editor1.setSession(modeSessions[value]);
schedule();
}); });
}); });