Merge pull request #265 from fivesixty/master
Add standard mode/highlight delegation into base Text Mode/Highlighter
This commit is contained in:
commit
7bb2cd9792
3 changed files with 69 additions and 0 deletions
|
|
@ -144,6 +144,9 @@ var BackgroundTokenizer = function(tokenizer, editor) {
|
||||||
} else if (firstRow == 0) {
|
} else if (firstRow == 0) {
|
||||||
state = "start";
|
state = "start";
|
||||||
doCache = true;
|
doCache = true;
|
||||||
|
} else if (this.lines.length > 0) {
|
||||||
|
// Guess that we haven't changed state.
|
||||||
|
state = this.lines[this.lines.length-1].state;
|
||||||
}
|
}
|
||||||
|
|
||||||
var lines = this.doc.getLines(firstRow, lastRow);
|
var lines = this.doc.getLines(firstRow, lastRow);
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,44 @@ var Mode = function() {
|
||||||
|
|
||||||
editor.session.$selectionOccurrences = [];
|
editor.session.$selectionOccurrences = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.createModeDelegates = function (mapping) {
|
||||||
|
if (!this.$embeds) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.$modes = {};
|
||||||
|
for (var i = 0; i < this.$embeds.length; i++) {
|
||||||
|
this.$modes[this.$embeds[i]] = new mapping[this.$embeds[i]]();
|
||||||
|
}
|
||||||
|
|
||||||
|
var delegations = ['toggleCommentLines', 'getNextLineIndent', 'checkOutdent', 'autoOutdent'];
|
||||||
|
|
||||||
|
for (var i = 0; i < delegations.length; i++) {
|
||||||
|
(function(scope) {
|
||||||
|
var functionName = delegations[i];
|
||||||
|
var defaultHandler = scope[functionName];
|
||||||
|
scope[delegations[i]] = function() {
|
||||||
|
return this.$delegator(functionName, arguments, defaultHandler);
|
||||||
|
}
|
||||||
|
} (this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$delegator = function(method, args, defaultHandler) {
|
||||||
|
var state = args[0];
|
||||||
|
|
||||||
|
for (var i = 0; i < this.$embeds.length; i++) {
|
||||||
|
var split = state.split(this.$embeds[i]);
|
||||||
|
|
||||||
|
if (!split[0] && split[1]) {
|
||||||
|
args[0] = split[1];
|
||||||
|
var mode = this.$modes[this.$embeds[i]];
|
||||||
|
return mode[method].apply(mode, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultHandler ? defaultHandler.apply(this, args) : undefined;
|
||||||
|
};
|
||||||
|
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,34 @@ var TextHighlightRules = function() {
|
||||||
this.getRules = function() {
|
this.getRules = function() {
|
||||||
return this.$rules;
|
return this.$rules;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.embedRules = function (HighlightRules, prefix, escapeRules, states) {
|
||||||
|
var embedRules = new HighlightRules().getRules();
|
||||||
|
if (states) {
|
||||||
|
for (var i = 0; i < states.length; i++) {
|
||||||
|
states[i] = prefix + states[i];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
states = [];
|
||||||
|
for (var key in embedRules) {
|
||||||
|
states.push(prefix + key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.addRules(embedRules, prefix);
|
||||||
|
|
||||||
|
for (var i = 0; i < states.length; i++) {
|
||||||
|
Array.prototype.unshift.apply(this.$rules[states[i]], escapeRules);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.$embeds) {
|
||||||
|
this.$embeds = [];
|
||||||
|
}
|
||||||
|
this.$embeds.push(prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getEmbeds = function() {
|
||||||
|
return this.$embeds;
|
||||||
|
}
|
||||||
|
|
||||||
}).call(TextHighlightRules.prototype);
|
}).call(TextHighlightRules.prototype);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue