parent
a15688ce00
commit
b837cd547b
5 changed files with 50 additions and 8 deletions
|
|
@ -384,9 +384,6 @@ var EditSession = function(text, mode) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.tokenRe = /^[\w\d]+/g;
|
|
||||||
this.nonTokenRe = /^(?:[^\w\d]|[\u3040-\u309F]|[\u30A0-\u30FF]|[\u4E00-\u9FFF\uF900-\uFAFF\u3400-\u4DBF])+/g;
|
|
||||||
|
|
||||||
this.getWordRange = function(row, column) {
|
this.getWordRange = function(row, column) {
|
||||||
var line = this.getLine(row);
|
var line = this.getLine(row);
|
||||||
|
|
||||||
|
|
@ -477,6 +474,9 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
this.bgTokenizer.setDocument(this.getDocument());
|
this.bgTokenizer.setDocument(this.getDocument());
|
||||||
this.bgTokenizer.start(0);
|
this.bgTokenizer.start(0);
|
||||||
|
|
||||||
|
this.tokenRe = mode.tokenRe;
|
||||||
|
this.nonTokenRe = mode.nonTokenRe;
|
||||||
|
|
||||||
this._dispatchEvent("changeMode");
|
this._dispatchEvent("changeMode");
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ define(function(require, exports, module) {
|
||||||
|
|
||||||
var oop = require("pilot/oop");
|
var oop = require("pilot/oop");
|
||||||
var lang = require("pilot/lang");
|
var lang = require("pilot/lang");
|
||||||
|
var regexp = require("ace/regexp");
|
||||||
var DocCommentHighlightRules = require("ace/mode/doc_comment_highlight_rules").DocCommentHighlightRules;
|
var DocCommentHighlightRules = require("ace/mode/doc_comment_highlight_rules").DocCommentHighlightRules;
|
||||||
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
||||||
|
|
||||||
|
|
@ -60,6 +61,13 @@ var JavaScriptHighlightRules = function() {
|
||||||
"public|interface|package|protected|static").split("|")
|
"public|interface|package|protected|static").split("|")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: Unicode escape sequences
|
||||||
|
var identifierRe = "[" + regexp.unicode.L + "\\$_]["
|
||||||
|
+ regexp.unicode.L
|
||||||
|
+ regexp.unicode.Mn + regexp.unicode.Mc
|
||||||
|
+ regexp.unicode.Nd
|
||||||
|
+ regexp.unicode.Pc + "\\$_]*\\b";
|
||||||
|
|
||||||
// regexp must not have capturing parentheses. Use (?:) instead.
|
// regexp must not have capturing parentheses. Use (?:) instead.
|
||||||
// regexps are ordered -> the first match is used
|
// regexps are ordered -> the first match is used
|
||||||
|
|
||||||
|
|
@ -115,9 +123,7 @@ var JavaScriptHighlightRules = function() {
|
||||||
else
|
else
|
||||||
return "identifier";
|
return "identifier";
|
||||||
},
|
},
|
||||||
// TODO: Unicode escape sequences
|
regex : identifierRe
|
||||||
// TODO: Unicode identifiers
|
|
||||||
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
|
|
||||||
}, {
|
}, {
|
||||||
token : "keyword.operator",
|
token : "keyword.operator",
|
||||||
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
|
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,11 @@ module.exports = {
|
||||||
"test tokenize regular expressions": function() {
|
"test tokenize regular expressions": function() {
|
||||||
var tokens = this.tokenizer.getLineTokens("a/b/c", "start").tokens;
|
var tokens = this.tokenizer.getLineTokens("a/b/c", "start").tokens;
|
||||||
assert.equal(5, tokens.length);
|
assert.equal(5, tokens.length);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test tokenize identifier with umlauts": function() {
|
||||||
|
var tokens = this.tokenizer.getLineTokens("füße", "start").tokens;
|
||||||
|
assert.equal(1, tokens.length);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ define(function(require, exports, module) {
|
||||||
var Tokenizer = require("ace/tokenizer").Tokenizer;
|
var Tokenizer = require("ace/tokenizer").Tokenizer;
|
||||||
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
||||||
var Behaviour = require("ace/mode/behaviour").Behaviour;
|
var Behaviour = require("ace/mode/behaviour").Behaviour;
|
||||||
|
var regexp = require("ace/regexp");
|
||||||
|
|
||||||
var Mode = function() {
|
var Mode = function() {
|
||||||
this.$tokenizer = new Tokenizer(new TextHighlightRules().getRules());
|
this.$tokenizer = new Tokenizer(new TextHighlightRules().getRules());
|
||||||
|
|
@ -51,6 +52,20 @@ var Mode = function() {
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
this.tokenRe = new RegExp("^["
|
||||||
|
+ regexp.unicode.L
|
||||||
|
+ regexp.unicode.Mn + regexp.unicode.Mc
|
||||||
|
+ regexp.unicode.Nd
|
||||||
|
+ regexp.unicode.Pc + "\\$_]+", "g"
|
||||||
|
);
|
||||||
|
|
||||||
|
this.nonTokenRe = new RegExp("^(?:[^"
|
||||||
|
+ regexp.unicode.L
|
||||||
|
+ regexp.unicode.Mn + regexp.unicode.Mc
|
||||||
|
+ regexp.unicode.Nd
|
||||||
|
+ regexp.unicode.Pc + "\\$_]|\s])+", "g"
|
||||||
|
);
|
||||||
|
|
||||||
this.getTokenizer = function() {
|
this.getTokenizer = function() {
|
||||||
return this.$tokenizer;
|
return this.$tokenizer;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -144,8 +144,12 @@ module.exports = {
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: moveCursor word left" : function() {
|
"test: moveCursor word left" : function() {
|
||||||
var session = new EditSession( ["ab",
|
var session = new EditSession([
|
||||||
" Juhu Kinners (abc, 12)", " cde"].join("\n"));
|
"ab",
|
||||||
|
" Juhu Kinners (abc, 12)",
|
||||||
|
" cde"
|
||||||
|
].join("\n"));
|
||||||
|
|
||||||
var selection = session.getSelection();
|
var selection = session.getSelection();
|
||||||
|
|
||||||
selection.moveCursorDown();
|
selection.moveCursorDown();
|
||||||
|
|
@ -183,6 +187,18 @@ module.exports = {
|
||||||
selection.moveCursorWordLeft();
|
selection.moveCursorWordLeft();
|
||||||
assert.position(selection.getCursor(), 0, 2);
|
assert.position(selection.getCursor(), 0, 2);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"test: moveCursor word left" : function() {
|
||||||
|
var session = new EditSession(" Fuß Füße");
|
||||||
|
|
||||||
|
var selection = session.getSelection();
|
||||||
|
selection.moveCursorTo(0, 9)
|
||||||
|
selection.moveCursorWordLeft();
|
||||||
|
assert.position(selection.getCursor(), 0, 5);
|
||||||
|
|
||||||
|
selection.moveCursorWordLeft();
|
||||||
|
assert.position(selection.getCursor(), 0, 4);
|
||||||
|
},
|
||||||
|
|
||||||
"test: select word left if cursor in word" : function() {
|
"test: select word left if cursor in word" : function() {
|
||||||
var session = new EditSession("Juhu Kinners");
|
var session = new EditSession("Juhu Kinners");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue