Merge branch 'master' of github.com:ajaxorg/ace
This commit is contained in:
commit
a3cb7b3f84
28 changed files with 1986 additions and 1901 deletions
10
build.js
10
build.js
|
|
@ -73,6 +73,16 @@
|
|||
"ace/mode/javascript",
|
||||
"ace/mode/css",
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "ace/mode/python",
|
||||
exclude: [
|
||||
"ace/lib/oop",
|
||||
"ace/lib/lang",
|
||||
"ace/tokenizer",
|
||||
"ace/range",
|
||||
"ace/mode/text"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
define(function() {
|
||||
return{selectall:"Command-A", removeline:"Command-D", gotoline:"Command-L", togglecomment:"Command-7", findnext:"Command-K", findprevious:"Command-Shift-K", find:"Command-F", replace:"Command-R", undo:"Command-Z", redo:"Command-Shift-Z|Command-Y", overwrite:"Insert", copylinesup:"Command-Option-Up", movelinesup:"Option-Up", selecttostart:"Command-Shift-Up", gotostart:"Command-Home|Command-Up", selectup:"Shift-Up", golineup:"Up", copylinesdown:"Command-Option-Down", movelinesdown:"Option-Down",
|
||||
selecttoend:"Command-Shift-Down", gotoend:"Command-End|Command-Down", selectdown:"Shift-Down", godown:"Down", selectwordleft:"Option-Shift-Left", gotowordleft:"Option-Left", selecttolinestart:"Command-Shift-Left", gotolinestart:"Command-Left|Home", selectleft:"Shift-Left", gotoleft:"Left", selectwordright:"Option-Shift-Right", gotowordright:"Option-Right", selecttolineend:"Command-Shift-Right", gotolineend:"Command-Right|End", selectright:"Shift-Right", gotoright:"Right", selectpagedown:"Shift-PageDown",
|
||||
pagedown:"PageDown", selectpageup:"Shift-PageUp", pageup:"PageUp", selectlinestart:"Shift-Home", selectlineend:"Shift-End", del:"Delete", backspace:"Backspace", outdent:"Shift-Tab", indent:"Tab"}
|
||||
pagedown:"PageDown", selectpageup:"Shift-PageUp", pageup:"PageUp", selectlinestart:"Shift-Home", selectlineend:"Shift-End", del:"Delete", backspace:"Ctrl-Backspace|Command-Backspace|Option-Backspace|Backspace", outdent:"Shift-Tab", indent:"Tab"}
|
||||
});
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
define(function() {
|
||||
return{selectall:"Ctrl-A", removeline:"Ctrl-D", gotoline:"Ctrl-L", togglecomment:"Ctrl-7", findnext:"Ctrl-K", findprevious:"Ctrl-Shift-K", find:"Ctrl-F", replace:"Ctrl-R", undo:"Ctrl-Z", redo:"Ctrl-Shift-Z|Ctrl-Y", overwrite:"Insert", copylinesup:"Ctrl-Alt-Up", movelinesup:"Alt-Up", selecttostart:"Alt-Shift-Up", gotostart:"Ctrl-Home|Ctrl-Up", selectup:"Shift-Up", golineup:"Up", copylinesdown:"Ctrl-Alt-Down", movelinesdown:"Alt-Down", selecttoend:"Alt-Shift-Down", gotoend:"Ctrl-End|Ctrl-Down", selectdown:"Shift-Down",
|
||||
godown:"Down", selectwordleft:"Ctrl-Shift-Left", gotowordleft:"Ctrl-Left", selecttolinestart:"Ctrl-Shift-Left", gotolinestart:"Alt-Left|Home", selectleft:"Shift-Left", gotoleft:"Left", selectwordright:"Ctrl-Shift-Right", gotowordright:"Ctrl-Right", selecttolineend:"Ctrl-Shift-Right", gotolineend:"Alt-Right|End", selectright:"Shift-Right", gotoright:"Right", selectpagedown:"Shift-PageDown", pagedown:"PageDown", selectpageup:"Shift-PageUp", pageup:"PageUp", selectlinestart:"Shift-Home", selectlineend:"Shift-End",
|
||||
godown:"Down", selectwordleft:"Ctrl-Shift-Left", gotowordleft:"Ctrl-Left", selecttolinestart:"Alt-Shift-Left", gotolinestart:"Alt-Left|Home", selectleft:"Shift-Left", gotoleft:"Left", selectwordright:"Ctrl-Shift-Right", gotowordright:"Ctrl-Right", selecttolineend:"Alt-Shift-Right", gotolineend:"Alt-Right|End", selectright:"Shift-Right", gotoright:"Right", selectpagedown:"Shift-PageDown", pagedown:"PageDown", selectpageup:"Shift-PageUp", pageup:"PageUp", selectlinestart:"Shift-Home", selectlineend:"Shift-End",
|
||||
del:"Delete", backspace:"Backspace", outdent:"Shift-Tab", indent:"Tab"}
|
||||
});
|
||||
|
|
@ -327,7 +327,7 @@ define(function(g) {
|
|||
}this.modified = true;
|
||||
b = a.start.row;
|
||||
var c = a.end.row, d = this.getLine(b).substring(0, a.start.column) + this.getLine(c).substring(a.end.column);
|
||||
this.lines.splice(b, c - b + 1, d);
|
||||
d != "" ? this.lines.splice(b, c - b + 1, d) : this.lines.splice(b, c - b + 1, "");
|
||||
return a.start
|
||||
}
|
||||
};
|
||||
|
|
|
|||
1904
build/ace/editor.js
1904
build/ace/editor.js
File diff suppressed because it is too large
Load diff
|
|
@ -67,6 +67,7 @@ define(function(k) {
|
|||
};
|
||||
this.updateLines = function(a, b, e) {
|
||||
this.$computeTabString();
|
||||
this.config = a;
|
||||
var f = Math.max(b, a.firstRow), c = Math.min(e, a.lastRow), d = this.element.childNodes, h = this;
|
||||
this.tokenizer.getTokens(f, c, function(i) {
|
||||
for(var g = f;g <= c;g++) {
|
||||
|
|
@ -128,6 +129,7 @@ define(function(k) {
|
|||
};
|
||||
this.update = function(a) {
|
||||
this.$computeTabString();
|
||||
this.config = a;
|
||||
var b = [], e = this;
|
||||
this.tokenizer.getTokens(a.firstRow, a.lastRow, function(f) {
|
||||
for(var c = a.firstRow;c <= a.lastRow;c++) {
|
||||
|
|
|
|||
|
|
@ -6,53 +6,55 @@ define(function(f) {
|
|||
};
|
||||
h.inherits(f, i);
|
||||
(function() {
|
||||
this.toggleCommentLines = function(d, b, e) {
|
||||
var c = true;
|
||||
d = /^(\s*)\/\//;
|
||||
for(var a = e.start.row;a <= e.end.row;a++) {
|
||||
if(!d.test(b.getLine(a))) {
|
||||
c = false;
|
||||
this.toggleCommentLines = function(c, d, e) {
|
||||
var a = true;
|
||||
c = /^(\s*)\/\//;
|
||||
for(var b = e.start.row;b <= e.end.row;b++) {
|
||||
if(!c.test(d.getLine(b))) {
|
||||
a = false;
|
||||
break
|
||||
}
|
||||
}if(c) {
|
||||
c = new m(0, 0, 0, 0);
|
||||
for(a = e.start.row;a <= e.end.row;a++) {
|
||||
var g = b.getLine(a).replace(d, "$1");
|
||||
c.start.row = a;
|
||||
c.end.row = a;
|
||||
c.end.column = g.length + 2;
|
||||
b.replace(c, g)
|
||||
}if(a) {
|
||||
a = new m(0, 0, 0, 0);
|
||||
for(b = e.start.row;b <= e.end.row;b++) {
|
||||
var g = d.getLine(b).replace(c, "$1");
|
||||
a.start.row = b;
|
||||
a.end.row = b;
|
||||
a.end.column = g.length + 2;
|
||||
d.replace(a, g)
|
||||
}return-2
|
||||
}else {
|
||||
return b.indentRows(e, "//")
|
||||
return d.indentRows(e, "//")
|
||||
}
|
||||
};
|
||||
this.getNextLineIndent = function(d, b, e) {
|
||||
var c = this.$getIndent(b), a = this.$tokenizer.getLineTokens(b, d), g = a.tokens;
|
||||
a = a.state;
|
||||
this.getNextLineIndent = function(c, d, e) {
|
||||
var a = this.$getIndent(d), b = this.$tokenizer.getLineTokens(d, c), g = b.tokens;
|
||||
b = b.state;
|
||||
if(g.length && g[g.length - 1].type == "comment") {
|
||||
return c
|
||||
}if(d == "start") {
|
||||
if(d = b.match(/^.*[\{\(\[]\s*$/)) {
|
||||
c += e
|
||||
return a
|
||||
}if(c == "start") {
|
||||
if(c = d.match(/^.*[\{\(\[]\s*$/)) {
|
||||
a += e
|
||||
}
|
||||
}else {
|
||||
if(d == "doc-start") {
|
||||
if(a == "start") {
|
||||
if(c == "doc-start") {
|
||||
if(b == "start") {
|
||||
return""
|
||||
}if(d = b.match(/^\s*(\/?)\*/)) {
|
||||
if(d[1]) {
|
||||
c += " "
|
||||
}c += "* "
|
||||
}
|
||||
}if(c = d.match(/^\s*(\/?)\*/)) {
|
||||
if(c[1]) {
|
||||
a += " "
|
||||
}a += "* "
|
||||
}if(c[1]) {
|
||||
a += " "
|
||||
}a += "* "
|
||||
}
|
||||
}return c
|
||||
}return a
|
||||
};
|
||||
this.checkOutdent = function(d, b, e) {
|
||||
return this.$outdent.checkOutdent(b, e)
|
||||
this.checkOutdent = function(c, d, e) {
|
||||
return this.$outdent.checkOutdent(d, e)
|
||||
};
|
||||
this.autoOutdent = function(d, b, e) {
|
||||
return this.$outdent.autoOutdent(b, e)
|
||||
this.autoOutdent = function(c, d, e) {
|
||||
return this.$outdent.autoOutdent(d, e)
|
||||
}
|
||||
}).call(f.prototype);
|
||||
return f
|
||||
|
|
|
|||
93
build/ace/mode/python.js
Normal file
93
build/ace/mode/python.js
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
define("ace/mode/python_highlight_rules", ["require", "exports", "module", "../lib/oop", "../lib/lang", "./text_highlight_rules"], function(a) {
|
||||
var k = a("../lib/oop"), b = a("../lib/lang");
|
||||
a = a("./text_highlight_rules");
|
||||
PythonHighlightRules = function() {
|
||||
var f = b.arrayToMap("and|as|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|raise|return|try|while|with|yield".split("|")), i = b.arrayToMap("True|False|None|NotImplemented|Ellipsis|__debug__".split("|")), j = b.arrayToMap("abs|divmod|input|open|staticmethod|all|enumerate|int|ord|str|any|eval|isinstance|pow|sum|basestring|execfile|issubclass|print|super|binfile|iter|property|tuple|bool|filter|len|range|type|bytearray|float|list|raw_input|unichr|callable|format|locals|reduce|unicode|chr|frozenset|long|reload|vars|classmethod|getattr|map|repr|xrange|cmp|globals|max|reversed|zip|compile|hasattr|memoryview|round|__import__|complex|hash|min|set|apply|delattr|help|next|setattr|buffer|dict|hex|object|slice|coerce|dir|id|oct|sorted|intern".split("|")),
|
||||
l = b.arrayToMap("".split("|"));
|
||||
this.$rules = {start:[{token:"comment", regex:"#.*$"}, {token:"string", regex:'(?:(?:[rubRUB])|(?:[ubUB][rR]))?"{3}(?:(?:.)|(?:^"{3}))*?"{3}'}, {token:"string", regex:'(?:(?:[rubRUB])|(?:[ubUB][rR]))?"{3}.*$', next:"qqstring"}, {token:"string", regex:'(?:(?:[rubRUB])|(?:[ubUB][rR]))?"(?:(?:\\\\.)|(?:[^"\\\\]))*?"'}, {token:"string", regex:"(?:(?:[rubRUB])|(?:[ubUB][rR]))?'{3}(?:(?:.)|(?:^'{3}))*?'{3}"}, {token:"string", regex:"(?:(?:[rubRUB])|(?:[ubUB][rR]))?'{3}.*$", next:"qstring"}, {token:"string",
|
||||
regex:"(?:(?:[rubRUB])|(?:[ubUB][rR]))?'(?:(?:\\\\.)|(?:[^'\\\\]))*?'"}, {token:"constant.numeric", regex:"(?:(?:(?:(?:(?:(?:(?:\\d+)?(?:\\.\\d+))|(?:(?:\\d+)\\.))|(?:\\d+))(?:[eE][+-]?\\d+))|(?:(?:(?:\\d+)?(?:\\.\\d+))|(?:(?:\\d+)\\.)))|\\d+)[jJ]\\b"}, {token:"constant.numeric", regex:"(?:(?:(?:(?:(?:(?:\\d+)?(?:\\.\\d+))|(?:(?:\\d+)\\.))|(?:\\d+))(?:[eE][+-]?\\d+))|(?:(?:(?:\\d+)?(?:\\.\\d+))|(?:(?:\\d+)\\.)))"}, {token:"constant.numeric", regex:"(?:(?:(?:[1-9]\\d*)|(?:0))|(?:0[oO]?[0-7]+)|(?:0[xX][\\dA-Fa-f]+)|(?:0[bB][01]+))[lL]\\b"},
|
||||
{token:"constant.numeric", regex:"(?:(?:(?:[1-9]\\d*)|(?:0))|(?:0[oO]?[0-7]+)|(?:0[xX][\\dA-Fa-f]+)|(?:0[bB][01]+))\\b"}, {token:function(c) {
|
||||
return f[c] ? "keyword" : i[c] ? "constant.language" : l[c] ? "invalid.illegal" : j[c] ? "support.function" : c == "debugger" ? "invalid.deprecated" : "identifier"
|
||||
}, regex:"[a-zA-Z_$][a-zA-Z0-9_$]*\\b"}, {token:"keyword.operator", regex:"\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|%|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|="}, {token:"lparen", regex:"[\\[\\(\\{]"}, {token:"rparen", regex:"[\\]\\)\\}]"}, {token:"text", regex:"\\s+"}], qqstring:[{token:"string", regex:'(?:^"{3})*?"{3}', next:"start"}, {token:"string", regex:".+"}], qstring:[{token:"string", regex:"(?:^'{3})*?'{3}", next:"start"}, {token:"string", regex:".+"}]}
|
||||
};
|
||||
k.inherits(PythonHighlightRules, a);
|
||||
return PythonHighlightRules
|
||||
});
|
||||
define("ace/mode/matching_brace_outdent", ["require", "exports", "module", "../range"], function(a) {
|
||||
var k = a("../range");
|
||||
a = function() {
|
||||
};
|
||||
(function() {
|
||||
this.checkOutdent = function(b, f) {
|
||||
if(!/^\s+$/.test(b)) {
|
||||
return false
|
||||
}return/^\s*\}/.test(f)
|
||||
};
|
||||
this.autoOutdent = function(b, f) {
|
||||
var i = b.getLine(f).match(/^(\s*\})/);
|
||||
if(!i) {
|
||||
return 0
|
||||
}i = i[1].length;
|
||||
var j = b.findMatchingBracket({row:f, column:i});
|
||||
if(!j || j.row == f) {
|
||||
return 0
|
||||
}j = this.$getIndent(b.getLine(j.row));
|
||||
b.replace(new k(f, 0, f, i - 1), j);
|
||||
return j.length - (i - 1)
|
||||
};
|
||||
this.$getIndent = function(b) {
|
||||
if(b = b.match(/^(\s+)/)) {
|
||||
return b[1]
|
||||
}return""
|
||||
}
|
||||
}).call(a.prototype);
|
||||
return a
|
||||
});
|
||||
define("ace/mode/python", ["require", "exports", "module", "../lib/oop", "./text", "../tokenizer", "./python_highlight_rules", "./matching_brace_outdent", "../range"], function(a) {
|
||||
var k = a("../lib/oop"), b = a("./text"), f = a("../tokenizer"), i = a("./python_highlight_rules"), j = a("./matching_brace_outdent"), l = a("../range");
|
||||
a = function() {
|
||||
this.$tokenizer = new f((new i).getRules());
|
||||
this.$outdent = new j
|
||||
};
|
||||
k.inherits(a, b);
|
||||
(function() {
|
||||
this.toggleCommentLines = function(c, e, g) {
|
||||
var h = true;
|
||||
c = /^(\s*)#/;
|
||||
for(var d = g.start.row;d <= g.end.row;d++) {
|
||||
if(!c.test(e.getLine(d))) {
|
||||
h = false;
|
||||
break
|
||||
}
|
||||
}if(h) {
|
||||
h = new l(0, 0, 0, 0);
|
||||
for(d = g.start.row;d <= g.end.row;d++) {
|
||||
var m = e.getLine(d).replace(c, "$1");
|
||||
h.start.row = d;
|
||||
h.end.row = d;
|
||||
h.end.column = m.length + 2;
|
||||
e.replace(h, m)
|
||||
}return-2
|
||||
}else {
|
||||
return e.indentRows(g, "#")
|
||||
}
|
||||
};
|
||||
this.getNextLineIndent = function(c, e, g) {
|
||||
var h = this.$getIndent(e), d = this.$tokenizer.getLineTokens(e, c).tokens;
|
||||
if(d.length && d[d.length - 1].type == "comment") {
|
||||
return h
|
||||
}if(c == "start") {
|
||||
if(e.match(/^.*[\{\(\[\:]\s*$/)) {
|
||||
h += g
|
||||
}
|
||||
}return h
|
||||
};
|
||||
this.checkOutdent = function(c, e, g) {
|
||||
return this.$outdent.checkOutdent(e, g)
|
||||
};
|
||||
this.autoOutdent = function(c, e, g) {
|
||||
return this.$outdent.autoOutdent(e, g)
|
||||
}
|
||||
}).call(a.prototype);
|
||||
return a
|
||||
});
|
||||
15
build/ace/mode/python_highlight_rules.js
Normal file
15
build/ace/mode/python_highlight_rules.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
define(function(a) {
|
||||
var d = a("../lib/oop"), c = a("../lib/lang");
|
||||
a = a("./text_highlight_rules");
|
||||
PythonHighlightRules = function() {
|
||||
var e = c.arrayToMap("and|as|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|raise|return|try|while|with|yield".split("|")), f = c.arrayToMap("True|False|None|NotImplemented|Ellipsis|__debug__".split("|")), g = c.arrayToMap("abs|divmod|input|open|staticmethod|all|enumerate|int|ord|str|any|eval|isinstance|pow|sum|basestring|execfile|issubclass|print|super|binfile|iter|property|tuple|bool|filter|len|range|type|bytearray|float|list|raw_input|unichr|callable|format|locals|reduce|unicode|chr|frozenset|long|reload|vars|classmethod|getattr|map|repr|xrange|cmp|globals|max|reversed|zip|compile|hasattr|memoryview|round|__import__|complex|hash|min|set|apply|delattr|help|next|setattr|buffer|dict|hex|object|slice|coerce|dir|id|oct|sorted|intern".split("|")),
|
||||
h = c.arrayToMap("".split("|"));
|
||||
this.$rules = {start:[{token:"comment", regex:"#.*$"}, {token:"string", regex:'(?:(?:[rubRUB])|(?:[ubUB][rR]))?"{3}(?:(?:.)|(?:^"{3}))*?"{3}'}, {token:"string", regex:'(?:(?:[rubRUB])|(?:[ubUB][rR]))?"{3}.*$', next:"qqstring"}, {token:"string", regex:'(?:(?:[rubRUB])|(?:[ubUB][rR]))?"(?:(?:\\\\.)|(?:[^"\\\\]))*?"'}, {token:"string", regex:"(?:(?:[rubRUB])|(?:[ubUB][rR]))?'{3}(?:(?:.)|(?:^'{3}))*?'{3}"}, {token:"string", regex:"(?:(?:[rubRUB])|(?:[ubUB][rR]))?'{3}.*$", next:"qstring"}, {token:"string",
|
||||
regex:"(?:(?:[rubRUB])|(?:[ubUB][rR]))?'(?:(?:\\\\.)|(?:[^'\\\\]))*?'"}, {token:"constant.numeric", regex:"(?:(?:(?:(?:(?:(?:(?:\\d+)?(?:\\.\\d+))|(?:(?:\\d+)\\.))|(?:\\d+))(?:[eE][+-]?\\d+))|(?:(?:(?:\\d+)?(?:\\.\\d+))|(?:(?:\\d+)\\.)))|\\d+)[jJ]\\b"}, {token:"constant.numeric", regex:"(?:(?:(?:(?:(?:(?:\\d+)?(?:\\.\\d+))|(?:(?:\\d+)\\.))|(?:\\d+))(?:[eE][+-]?\\d+))|(?:(?:(?:\\d+)?(?:\\.\\d+))|(?:(?:\\d+)\\.)))"}, {token:"constant.numeric", regex:"(?:(?:(?:[1-9]\\d*)|(?:0))|(?:0[oO]?[0-7]+)|(?:0[xX][\\dA-Fa-f]+)|(?:0[bB][01]+))[lL]\\b"},
|
||||
{token:"constant.numeric", regex:"(?:(?:(?:[1-9]\\d*)|(?:0))|(?:0[oO]?[0-7]+)|(?:0[xX][\\dA-Fa-f]+)|(?:0[bB][01]+))\\b"}, {token:function(b) {
|
||||
return e[b] ? "keyword" : f[b] ? "constant.language" : h[b] ? "invalid.illegal" : g[b] ? "support.function" : b == "debugger" ? "invalid.deprecated" : "identifier"
|
||||
}, regex:"[a-zA-Z_$][a-zA-Z0-9_$]*\\b"}, {token:"keyword.operator", regex:"\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|%|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|="}, {token:"lparen", regex:"[\\[\\(\\{]"}, {token:"rparen", regex:"[\\]\\)\\}]"}, {token:"text", regex:"\\s+"}], qqstring:[{token:"string", regex:'(?:^"{3})*?"{3}', next:"start"}, {token:"string", regex:".+"}], qstring:[{token:"string", regex:"(?:^'{3})*?'{3}", next:"start"}, {token:"string", regex:".+"}]}
|
||||
};
|
||||
d.inherits(PythonHighlightRules, a);
|
||||
return PythonHighlightRules
|
||||
});
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
define(function(c) {
|
||||
var e = c("./lib/event");
|
||||
c = function(b) {
|
||||
define(function(d) {
|
||||
var e = d("./lib/event");
|
||||
d = function(b) {
|
||||
this.onRender = b;
|
||||
this.pending = false;
|
||||
this.changes = 0
|
||||
|
|
@ -13,8 +13,9 @@ define(function(c) {
|
|||
var a = this;
|
||||
this.setTimeoutZero(function() {
|
||||
a.pending = false;
|
||||
a.onRender(a.changes);
|
||||
a.changes = 0
|
||||
var c = a.changes;
|
||||
a.changes = 0;
|
||||
a.onRender(c)
|
||||
})
|
||||
}
|
||||
};
|
||||
|
|
@ -23,9 +24,9 @@ define(function(c) {
|
|||
this.setTimeoutZero = function(b) {
|
||||
if(!this.attached) {
|
||||
var a = this;
|
||||
e.addListener(window, "message", function(d) {
|
||||
if(d.source == window && a.callback && d.data == a.messageName) {
|
||||
e.stopPropagation(d);
|
||||
e.addListener(window, "message", function(c) {
|
||||
if(c.source == window && a.callback && c.data == a.messageName) {
|
||||
e.stopPropagation(c);
|
||||
a.callback()
|
||||
}
|
||||
});
|
||||
|
|
@ -38,6 +39,6 @@ define(function(c) {
|
|||
setTimeout(b, 0)
|
||||
}
|
||||
}
|
||||
}).call(c.prototype);
|
||||
return c
|
||||
}).call(d.prototype);
|
||||
return d
|
||||
});
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
/*
|
||||
LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
*/
|
||||
require.def([], function() {
|
||||
window.assertPosition = function(a, b, c) {
|
||||
assertEquals(a, c.row);
|
||||
assertEquals(b, c.column)
|
||||
};
|
||||
window.assertRange = function(a, b, c, e, d) {
|
||||
assertPosition(a, b, d.start);
|
||||
assertPosition(c, e, d.end)
|
||||
};
|
||||
window.assertJsonEquals = function(a, b) {
|
||||
assertEquals(JSON.stringify(a), JSON.stringify(b))
|
||||
}
|
||||
});
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
*/
|
||||
require.def(["ace/Document", "ace/Editor", "ace/mode/Text", "ace/mode/JavaScript", "ace/test/MockRenderer"], function(b, c, f, d, e) {
|
||||
new TestCase("ChangeDocumentTest", {setUp:function() {
|
||||
this.doc1 = new b("abc\ndef");
|
||||
this.doc2 = new b("ghi\njkl");
|
||||
this.editor = new c(new e)
|
||||
}, "test: change document":function() {
|
||||
this.editor.setDocument(this.doc1);
|
||||
assertEquals(this.doc1, this.editor.getDocument());
|
||||
this.editor.setDocument(this.doc2);
|
||||
assertEquals(this.doc2, this.editor.getDocument())
|
||||
}, "test: only changes to the new document should have effect":function() {
|
||||
var a = false;
|
||||
this.editor.onDocumentChange = function() {
|
||||
a = true
|
||||
};
|
||||
this.editor.setDocument(this.doc1);
|
||||
this.editor.setDocument(this.doc2);
|
||||
this.doc1.duplicateLines(0, 0);
|
||||
assertFalse(a);
|
||||
this.doc2.duplicateLines(0, 0);
|
||||
assertTrue(a)
|
||||
}, "test: should use cursor of new document":function() {
|
||||
this.doc1.getSelection().moveCursorTo(0, 1);
|
||||
this.doc2.getSelection().moveCursorTo(1, 0);
|
||||
this.editor.setDocument(this.doc1);
|
||||
assertPosition(0, 1, this.editor.getCursorPosition());
|
||||
this.editor.setDocument(this.doc2);
|
||||
assertPosition(1, 0, this.editor.getCursorPosition())
|
||||
}, "test: only changing the cursor of the new doc should not have an effect":function() {
|
||||
this.editor.onCursorChange = function() {
|
||||
a = true
|
||||
};
|
||||
this.editor.setDocument(this.doc1);
|
||||
this.editor.setDocument(this.doc2);
|
||||
assertPosition(0, 0, this.editor.getCursorPosition());
|
||||
var a = false;
|
||||
this.doc1.getSelection().moveCursorTo(0, 1);
|
||||
assertPosition(0, 0, this.editor.getCursorPosition());
|
||||
assertFalse(a);
|
||||
this.doc2.getSelection().moveCursorTo(1, 1);
|
||||
assertPosition(1, 1, this.editor.getCursorPosition());
|
||||
assertTrue(a)
|
||||
}, "test: should use selection of new document":function() {
|
||||
this.doc1.getSelection().selectTo(0, 1);
|
||||
this.doc2.getSelection().selectTo(1, 0);
|
||||
this.editor.setDocument(this.doc1);
|
||||
assertPosition(0, 1, this.editor.getSelection().getSelectionLead());
|
||||
this.editor.setDocument(this.doc2);
|
||||
assertPosition(1, 0, this.editor.getSelection().getSelectionLead())
|
||||
}, "test: only changing the selection of the new doc should not have an effect":function() {
|
||||
this.editor.onSelectionChange = function() {
|
||||
a = true
|
||||
};
|
||||
this.editor.setDocument(this.doc1);
|
||||
this.editor.setDocument(this.doc2);
|
||||
assertPosition(0, 0, this.editor.getSelection().getSelectionLead());
|
||||
var a = false;
|
||||
this.doc1.getSelection().selectTo(0, 1);
|
||||
assertPosition(0, 0, this.editor.getSelection().getSelectionLead());
|
||||
assertFalse(a);
|
||||
this.doc2.getSelection().selectTo(1, 1);
|
||||
assertPosition(1, 1, this.editor.getSelection().getSelectionLead());
|
||||
assertTrue(a)
|
||||
}, "test: should use mode of new document":function() {
|
||||
this.editor.onDocumentModeChange = function() {
|
||||
a = true
|
||||
};
|
||||
this.editor.setDocument(this.doc1);
|
||||
this.editor.setDocument(this.doc2);
|
||||
var a = false;
|
||||
this.doc1.setMode(new Text);
|
||||
assertFalse(a);
|
||||
this.doc2.setMode(new d);
|
||||
assertTrue(a)
|
||||
}})
|
||||
});
|
||||
|
|
@ -1,148 +1,153 @@
|
|||
/*
|
||||
LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
*/
|
||||
require.def(["ace/Document", "ace/UndoManager", "ace/Editor", "ace/test/MockRenderer"], function(b, h, i, j) {
|
||||
new TestCase("TextDocumentTest", {"test: find matching opening bracket":function() {
|
||||
var a = new b(["(()(", "())))"]);
|
||||
assertPosition(0, 1, a.findMatchingBracket({row:0, column:3}));
|
||||
assertPosition(1, 0, a.findMatchingBracket({row:1, column:2}));
|
||||
assertPosition(0, 3, a.findMatchingBracket({row:1, column:3}));
|
||||
assertPosition(0, 0, a.findMatchingBracket({row:1, column:4}));
|
||||
assertEquals(null, a.findMatchingBracket({row:1, column:5}))
|
||||
}, "test: find matching closing bracket":function() {
|
||||
var a = new b(["(()(", "())))"]);
|
||||
assertPosition(1, 1, a.findMatchingBracket({row:1, column:1}));
|
||||
assertPosition(1, 1, a.findMatchingBracket({row:1, column:1}));
|
||||
assertPosition(1, 2, a.findMatchingBracket({row:0, column:4}));
|
||||
assertPosition(0, 2, a.findMatchingBracket({row:0, column:2}));
|
||||
assertPosition(1, 3, a.findMatchingBracket({row:0, column:1}));
|
||||
assertEquals(null, a.findMatchingBracket({row:0, column:0}))
|
||||
}, "test: match different bracket types":function() {
|
||||
var a = new b(["({[", ")]}"]);
|
||||
assertPosition(1, 0, a.findMatchingBracket({row:0, column:1}));
|
||||
assertPosition(1, 2, a.findMatchingBracket({row:0, column:2}));
|
||||
assertPosition(1, 1, a.findMatchingBracket({row:0, column:3}));
|
||||
assertPosition(0, 0, a.findMatchingBracket({row:1, column:1}));
|
||||
assertPosition(0, 2, a.findMatchingBracket({row:1, column:2}));
|
||||
assertPosition(0, 1, a.findMatchingBracket({row:1, column:3}))
|
||||
}, "test: move lines down":function() {
|
||||
var a = new b(["1", "2", "3", "4"]);
|
||||
a.moveLinesDown(0, 1);
|
||||
assertEquals("3\n1\n2\n4", a.toString());
|
||||
a.moveLinesDown(1, 2);
|
||||
assertEquals("3\n4\n1\n2", a.toString());
|
||||
a.moveLinesDown(2, 3);
|
||||
assertEquals("3\n4\n1\n2", a.toString());
|
||||
a.moveLinesDown(2, 2);
|
||||
assertEquals("3\n4\n2\n1", a.toString())
|
||||
}, "test: move lines up":function() {
|
||||
var a = new b(["1", "2", "3", "4"]);
|
||||
a.moveLinesUp(2, 3);
|
||||
assertEquals("1\n3\n4\n2", a.toString());
|
||||
a.moveLinesUp(1, 2);
|
||||
assertEquals("3\n4\n1\n2", a.toString());
|
||||
a.moveLinesUp(0, 1);
|
||||
assertEquals("3\n4\n1\n2", a.toString());
|
||||
a.moveLinesUp(2, 2);
|
||||
assertEquals("3\n1\n4\n2", a.toString())
|
||||
}, "test: duplicate lines":function() {
|
||||
var a = new b(["1", "2", "3", "4"]);
|
||||
a.duplicateLines(1, 2);
|
||||
assertEquals("1\n2\n3\n2\n3\n4", a.toString())
|
||||
}, "test: duplicate last line":function() {
|
||||
var a = new b(["1", "2", "3"]);
|
||||
a.duplicateLines(2, 2);
|
||||
assertEquals("1\n2\n3\n3", a.toString())
|
||||
}, "test: duplicate first line":function() {
|
||||
var a = new b(["1", "2", "3"]);
|
||||
a.duplicateLines(0, 0);
|
||||
assertEquals("1\n1\n2\n3", a.toString())
|
||||
}, "test: should handle unix style new lines":function() {
|
||||
var a = new b(["1", "2", "3"]);
|
||||
assertEquals("1\n2\n3", a.toString())
|
||||
}, "test: should handle windows style new lines":function() {
|
||||
var a = new b("1\r\n2\r\n3");
|
||||
a.setNewLineMode("unix");
|
||||
assertEquals("1\n2\n3", a.toString())
|
||||
}, "test: set new line mode to 'windows' should use '\r\n' as new lines":function() {
|
||||
var a = new b("1\n2\n3");
|
||||
a.setNewLineMode("windows");
|
||||
assertEquals("1\r\n2\r\n3", a.toString())
|
||||
}, "test: set new line mode to 'unix' should use '\n' as new lines":function() {
|
||||
var a = new b("1\r\n2\r\n3");
|
||||
a.setNewLineMode("unix");
|
||||
assertEquals("1\n2\n3", a.toString())
|
||||
}, "test: set new line mode to 'auto' should use detect the incoming nl type":function() {
|
||||
var a = new b("1\n2\n3");
|
||||
a.setNewLineMode("auto");
|
||||
assertEquals("1\n2\n3", a.toString());
|
||||
a = new b("1\r\n2\r\n3");
|
||||
a.setNewLineMode("auto");
|
||||
assertEquals("1\r\n2\r\n3", a.toString());
|
||||
a.replace(new Range(0, 0, 2, 1), "4\n5\n6");
|
||||
assertEquals("4\n5\n6", a.toString())
|
||||
}, "test: undo/redo for delete line":function() {
|
||||
var a = new b(["111", "222", "333"]), c = new h;
|
||||
a.setUndoManager(c);
|
||||
var e = a.toString(), d = new i(new j, a);
|
||||
d.removeLines();
|
||||
var f = a.toString();
|
||||
assertEquals("222\n333", f);
|
||||
a.$informUndoManager.call();
|
||||
d.removeLines();
|
||||
var g = a.toString();
|
||||
assertEquals("333", g);
|
||||
a.$informUndoManager.call();
|
||||
d.removeLines();
|
||||
d = a.toString();
|
||||
assertEquals("", d);
|
||||
a.$informUndoManager.call();
|
||||
c.undo();
|
||||
a.$informUndoManager.call();
|
||||
assertEquals(g, a.toString());
|
||||
c.undo();
|
||||
a.$informUndoManager.call();
|
||||
assertEquals(f, a.toString());
|
||||
c.undo();
|
||||
a.$informUndoManager.call();
|
||||
assertEquals(e, a.toString());
|
||||
c.undo();
|
||||
a.$informUndoManager.call();
|
||||
assertEquals(e, a.toString())
|
||||
}, "test: convert document to screen coordinates":function() {
|
||||
var a = new b("01234\t567890\t1234");
|
||||
a.setTabSize(4);
|
||||
assertEquals(0, a.documentToScreenColumn(0, 0));
|
||||
assertEquals(4, a.documentToScreenColumn(0, 4));
|
||||
assertEquals(5, a.documentToScreenColumn(0, 5));
|
||||
assertEquals(9, a.documentToScreenColumn(0, 6));
|
||||
assertEquals(15, a.documentToScreenColumn(0, 12));
|
||||
assertEquals(19, a.documentToScreenColumn(0, 13));
|
||||
a.setTabSize(2);
|
||||
assertEquals(0, a.documentToScreenColumn(0, 0));
|
||||
assertEquals(4, a.documentToScreenColumn(0, 4));
|
||||
assertEquals(5, a.documentToScreenColumn(0, 5));
|
||||
assertEquals(7, a.documentToScreenColumn(0, 6));
|
||||
assertEquals(13, a.documentToScreenColumn(0, 12));
|
||||
assertEquals(15, a.documentToScreenColumn(0, 13))
|
||||
}, "test: convert document to scrren coordinates with leading tabs":function() {
|
||||
var a = new b("\t\t123");
|
||||
a.setTabSize(4);
|
||||
assertEquals(0, a.documentToScreenColumn(0, 0));
|
||||
assertEquals(4, a.documentToScreenColumn(0, 1));
|
||||
assertEquals(8, a.documentToScreenColumn(0, 2));
|
||||
assertEquals(9, a.documentToScreenColumn(0, 3))
|
||||
}, "test: convert screen to document coordinates":function() {
|
||||
var a = new b("01234\t567890\t1234");
|
||||
a.setTabSize(4);
|
||||
assertEquals(0, a.screenToDocumentColumn(0, 0));
|
||||
assertEquals(4, a.screenToDocumentColumn(0, 4));
|
||||
assertEquals(5, a.screenToDocumentColumn(0, 5));
|
||||
assertEquals(5, a.screenToDocumentColumn(0, 6));
|
||||
assertEquals(5, a.screenToDocumentColumn(0, 7));
|
||||
assertEquals(5, a.screenToDocumentColumn(0, 8));
|
||||
assertEquals(6, a.screenToDocumentColumn(0, 9));
|
||||
assertEquals(12, a.screenToDocumentColumn(0, 15));
|
||||
assertEquals(13, a.screenToDocumentColumn(0, 19))
|
||||
}})
|
||||
});
|
||||
require("../../../support/paths");
|
||||
var Document = require("../document"), UndoManager = require("../undomanager"), MockRenderer = require("./mockrenderer"), Range = require("../range"), assert = require("./assertions"), async = require("async"), Test = {"test: find matching opening bracket":function() {
|
||||
var a = new Document(["(()(", "())))"]);
|
||||
assert.position(a.findMatchingBracket({row:0, column:3}), 0, 1);
|
||||
assert.position(a.findMatchingBracket({row:1, column:2}), 1, 0);
|
||||
assert.position(a.findMatchingBracket({row:1, column:3}), 0, 3);
|
||||
assert.position(a.findMatchingBracket({row:1, column:4}), 0, 0);
|
||||
assert.equal(a.findMatchingBracket({row:1, column:5}), null)
|
||||
}, "test: find matching closing bracket":function() {
|
||||
var a = new Document(["(()(", "())))"]);
|
||||
assert.position(a.findMatchingBracket({row:1, column:1}), 1, 1);
|
||||
assert.position(a.findMatchingBracket({row:1, column:1}), 1, 1);
|
||||
assert.position(a.findMatchingBracket({row:0, column:4}), 1, 2);
|
||||
assert.position(a.findMatchingBracket({row:0, column:2}), 0, 2);
|
||||
assert.position(a.findMatchingBracket({row:0, column:1}), 1, 3);
|
||||
assert.equal(a.findMatchingBracket({row:0, column:0}), null)
|
||||
}, "test: match different bracket types":function() {
|
||||
var a = new Document(["({[", ")]}"]);
|
||||
assert.position(a.findMatchingBracket({row:0, column:1}), 1, 0);
|
||||
assert.position(a.findMatchingBracket({row:0, column:2}), 1, 2);
|
||||
assert.position(a.findMatchingBracket({row:0, column:3}), 1, 1);
|
||||
assert.position(a.findMatchingBracket({row:1, column:1}), 0, 0);
|
||||
assert.position(a.findMatchingBracket({row:1, column:2}), 0, 2);
|
||||
assert.position(a.findMatchingBracket({row:1, column:3}), 0, 1)
|
||||
}, "test: move lines down":function() {
|
||||
var a = new Document(["1", "2", "3", "4"]);
|
||||
console.log(a.toString().replace(/\n/g, "\\n"));
|
||||
a.moveLinesDown(0, 1);
|
||||
console.log(a.toString().replace(/\n/g, "\\n"));
|
||||
assert.equal(a.toString(), "3\n1\n2\n4");
|
||||
a.moveLinesDown(1, 2);
|
||||
assert.equal(a.toString(), "3\n4\n1\n2");
|
||||
a.moveLinesDown(2, 3);
|
||||
assert.equal(a.toString(), "3\n4\n1\n2");
|
||||
a.moveLinesDown(2, 2);
|
||||
assert.equal(a.toString(), "3\n4\n2\n1")
|
||||
}, "__test: move lines up":function() {
|
||||
var a = new Document(["1", "2", "3", "4"]);
|
||||
console.log(a.toString().replace(/\n/g, "\\n"));
|
||||
a.moveLinesUp(2, 3);
|
||||
console.log(a.toString().replace(/\n/g, "\\n"));
|
||||
assert.equal(a.toString(), "1\n3\n4\n2");
|
||||
a.moveLinesUp(1, 2);
|
||||
assert.equal(a.toString(), "3\n4\n1\n2");
|
||||
a.moveLinesUp(0, 1);
|
||||
assert.equal(a.toString(), "3\n4\n1\n2");
|
||||
a.moveLinesUp(2, 2);
|
||||
assert.equal(a.toString(), "3\n1\n4\n2")
|
||||
}, "test: duplicate lines":function() {
|
||||
var a = new Document(["1", "2", "3", "4"]);
|
||||
a.duplicateLines(1, 2);
|
||||
assert.equal(a.toString(), "1\n2\n3\n2\n3\n4")
|
||||
}, "test: duplicate last line":function() {
|
||||
var a = new Document(["1", "2", "3"]);
|
||||
a.duplicateLines(2, 2);
|
||||
assert.equal(a.toString(), "1\n2\n3\n3")
|
||||
}, "test: duplicate first line":function() {
|
||||
var a = new Document(["1", "2", "3"]);
|
||||
a.duplicateLines(0, 0);
|
||||
assert.equal(a.toString(), "1\n1\n2\n3")
|
||||
}, "test: should handle unix style new lines":function() {
|
||||
var a = new Document(["1", "2", "3"]);
|
||||
assert.equal(a.toString(), "1\n2\n3")
|
||||
}, "test: should handle windows style new lines":function() {
|
||||
var a = new Document("1\r\n2\r\n3");
|
||||
a.setNewLineMode("unix");
|
||||
assert.equal(a.toString(), "1\n2\n3")
|
||||
}, "test: set new line mode to 'windows' should use '\r\n' as new lines":function() {
|
||||
var a = new Document("1\n2\n3");
|
||||
a.setNewLineMode("windows");
|
||||
assert.equal(a.toString(), "1\r\n2\r\n3")
|
||||
}, "test: set new line mode to 'unix' should use '\n' as new lines":function() {
|
||||
var a = new Document("1\r\n2\r\n3");
|
||||
a.setNewLineMode("unix");
|
||||
assert.equal(a.toString(), "1\n2\n3")
|
||||
}, "test: set new line mode to 'auto' should detect the incoming nl type":function() {
|
||||
var a = new Document("1\n2\n3");
|
||||
a.setNewLineMode("auto");
|
||||
assert.equal(a.toString(), "1\n2\n3");
|
||||
a = new Document("1\r\n2\r\n3");
|
||||
a.setNewLineMode("auto");
|
||||
assert.equal(a.toString(), "1\r\n2\r\n3");
|
||||
a.replace(new Range(0, 0, 2, 1), "4\n5\n6");
|
||||
assert.equal("4\n5\n6", a.toString())
|
||||
}, "__test: undo/redo for delete line":function() {
|
||||
var a = new Document(["111", "222", "333"]), b = new UndoManager;
|
||||
a.setUndoManager(b);
|
||||
var d = a.toString(), c = new Editor(new MockRenderer, a);
|
||||
c.removeLines();
|
||||
var e = a.toString();
|
||||
assert.equal(e, "222\n333");
|
||||
a.$informUndoManager.call();
|
||||
c.removeLines();
|
||||
var f = a.toString();
|
||||
assert.equal(f, "333");
|
||||
a.$informUndoManager.call();
|
||||
c.removeLines();
|
||||
c = a.toString();
|
||||
assert.equal(c, "");
|
||||
a.$informUndoManager.call();
|
||||
b.undo();
|
||||
a.$informUndoManager.call();
|
||||
assert.equal(a.toString(), f);
|
||||
b.undo();
|
||||
a.$informUndoManager.call();
|
||||
assert.equal(a.toString(), e);
|
||||
b.undo();
|
||||
a.$informUndoManager.call();
|
||||
assert.equal(a.toString(), d);
|
||||
b.undo();
|
||||
a.$informUndoManager.call();
|
||||
assert.equal(a.toString(), d)
|
||||
}, "test: convert document to screen coordinates":function() {
|
||||
var a = new Document("01234\t567890\t1234");
|
||||
a.setTabSize(4);
|
||||
assert.equal(a.documentToScreenColumn(0, 0), 0);
|
||||
assert.equal(a.documentToScreenColumn(0, 4), 4);
|
||||
assert.equal(a.documentToScreenColumn(0, 5), 5);
|
||||
assert.equal(a.documentToScreenColumn(0, 6), 9);
|
||||
assert.equal(a.documentToScreenColumn(0, 12), 15);
|
||||
assert.equal(a.documentToScreenColumn(0, 13), 19);
|
||||
a.setTabSize(2);
|
||||
assert.equal(a.documentToScreenColumn(0, 0), 0);
|
||||
assert.equal(a.documentToScreenColumn(0, 4), 4);
|
||||
assert.equal(a.documentToScreenColumn(0, 5), 5);
|
||||
assert.equal(a.documentToScreenColumn(0, 6), 7);
|
||||
assert.equal(a.documentToScreenColumn(0, 12), 13);
|
||||
assert.equal(a.documentToScreenColumn(0, 13), 15)
|
||||
}, "test: convert document to scrren coordinates with leading tabs":function() {
|
||||
var a = new Document("\t\t123");
|
||||
a.setTabSize(4);
|
||||
assert.equal(a.documentToScreenColumn(0, 0), 0);
|
||||
assert.equal(a.documentToScreenColumn(0, 1), 4);
|
||||
assert.equal(a.documentToScreenColumn(0, 2), 8);
|
||||
assert.equal(a.documentToScreenColumn(0, 3), 9)
|
||||
}, "test: convert screen to document coordinates":function() {
|
||||
var a = new Document("01234\t567890\t1234");
|
||||
a.setTabSize(4);
|
||||
assert.equal(a.screenToDocumentColumn(0, 0), 0);
|
||||
assert.equal(a.screenToDocumentColumn(0, 4), 4);
|
||||
assert.equal(a.screenToDocumentColumn(0, 5), 5);
|
||||
assert.equal(a.screenToDocumentColumn(0, 6), 5);
|
||||
assert.equal(a.screenToDocumentColumn(0, 7), 5);
|
||||
assert.equal(a.screenToDocumentColumn(0, 8), 5);
|
||||
assert.equal(a.screenToDocumentColumn(0, 9), 6);
|
||||
assert.equal(a.screenToDocumentColumn(0, 15), 12);
|
||||
assert.equal(a.screenToDocumentColumn(0, 19), 13)
|
||||
}};
|
||||
module.exports = require("async/test").testcase(Test);
|
||||
module === require.main && module.exports.exec();
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
/*
|
||||
LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
*/
|
||||
require.def(["ace/lib/oop", "ace/MEventEmitter"], function(d, e) {
|
||||
var a = function() {
|
||||
};
|
||||
d.implement(a.prototype, e);
|
||||
new TestCase("EventEmitterTest", {"test: dispatch event with no data":function() {
|
||||
var b = new a, c = false;
|
||||
b.addEventListener("juhu", function(f) {
|
||||
c = true;
|
||||
assertEquals("juhu", f.type)
|
||||
});
|
||||
b.$dispatchEvent("juhu");
|
||||
assertTrue(c)
|
||||
}})
|
||||
});
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
*/
|
||||
require.def([], function() {
|
||||
define(function() {
|
||||
MockRenderer = function(a) {
|
||||
this.container = document.createElement("div");
|
||||
this.cursor = {row:0, column:0};
|
||||
|
|
@ -52,5 +52,11 @@ require.def([], function() {
|
|||
};
|
||||
MockRenderer.prototype.setBreakpoints = function() {
|
||||
};
|
||||
MockRenderer.prototype.updateFull = function() {
|
||||
};
|
||||
MockRenderer.prototype.showCursor = function() {
|
||||
};
|
||||
MockRenderer.prototype.visualizeFocus = function() {
|
||||
};
|
||||
return MockRenderer
|
||||
});
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
*/
|
||||
require.def(["ace/Document", "ace/Editor", "ace/test/MockRenderer"], function(e, c, d) {
|
||||
TestCase("NavigationTest", {createTextDocument:function(a, b) {
|
||||
b = (new Array(b + 1)).join("a");
|
||||
a = (new Array(a)).join(b + "\n") + b;
|
||||
return new e(a)
|
||||
}, "test: navigate to end of file should scroll the last line into view":function() {
|
||||
var a = this.createTextDocument(200, 10);
|
||||
a = new c(new d, a);
|
||||
a.navigateFileEnd();
|
||||
var b = a.getCursorPosition();
|
||||
assertTrue(a.getFirstVisibleRow() <= b.row);
|
||||
assertTrue(a.getLastVisibleRow() >= b.row)
|
||||
}, "test: navigate to start of file should scroll the first row into view":function() {
|
||||
var a = this.createTextDocument(200, 10);
|
||||
a = new c(new d, a);
|
||||
a.moveCursorTo(a.getLastVisibleRow() + 20);
|
||||
a.navigateFileStart();
|
||||
assertEquals(0, a.getFirstVisibleRow())
|
||||
}, "test: goto hidden line should scroll the line into the middle of the viewport":function() {
|
||||
var a = new c(new d, this.createTextDocument(200, 5));
|
||||
a.navigateTo(0, 0);
|
||||
a.gotoLine(101);
|
||||
assertPosition(100, 0, a.getCursorPosition());
|
||||
assertEquals(90, a.getFirstVisibleRow());
|
||||
a.navigateTo(100, 0);
|
||||
a.gotoLine(11);
|
||||
assertPosition(10, 0, a.getCursorPosition());
|
||||
assertEquals(0, a.getFirstVisibleRow());
|
||||
a.navigateTo(100, 0);
|
||||
a.gotoLine(6);
|
||||
assertPosition(5, 0, a.getCursorPosition());
|
||||
assertEquals(0, a.getFirstVisibleRow());
|
||||
a.navigateTo(100, 0);
|
||||
a.gotoLine(1);
|
||||
assertPosition(0, 0, a.getCursorPosition());
|
||||
assertEquals(0, a.getFirstVisibleRow());
|
||||
a.navigateTo(0, 0);
|
||||
a.gotoLine(191);
|
||||
assertPosition(190, 0, a.getCursorPosition());
|
||||
assertEquals(180, a.getFirstVisibleRow());
|
||||
a.navigateTo(0, 0);
|
||||
a.gotoLine(196);
|
||||
assertPosition(195, 0, a.getCursorPosition());
|
||||
assertEquals(180, a.getFirstVisibleRow())
|
||||
}, "test: goto visible line should only move the cursor and not scroll":function() {
|
||||
var a = new c(new d, this.createTextDocument(200, 5));
|
||||
a.navigateTo(0, 0);
|
||||
a.gotoLine(12);
|
||||
assertPosition(11, 0, a.getCursorPosition());
|
||||
assertEquals(0, a.getFirstVisibleRow());
|
||||
a.navigateTo(30, 0);
|
||||
a.gotoLine(33);
|
||||
assertPosition(32, 0, a.getCursorPosition());
|
||||
assertEquals(30, a.getFirstVisibleRow())
|
||||
}, "test: navigate from the end of a long line down to a short line and back should maintain the curser column":function() {
|
||||
var a = new c(new d, new e(["123456", "1"]));
|
||||
a.navigateTo(0, 6);
|
||||
assertPosition(0, 6, a.getCursorPosition());
|
||||
a.navigateDown();
|
||||
assertPosition(1, 1, a.getCursorPosition());
|
||||
a.navigateUp();
|
||||
assertPosition(0, 6, a.getCursorPosition())
|
||||
}, "test: reset desired column on navigate left or right":function() {
|
||||
var a = new c(new d, new e(["123456", "12"]));
|
||||
a.navigateTo(0, 6);
|
||||
assertPosition(0, 6, a.getCursorPosition());
|
||||
a.navigateDown();
|
||||
assertPosition(1, 2, a.getCursorPosition());
|
||||
a.navigateLeft();
|
||||
assertPosition(1, 1, a.getCursorPosition());
|
||||
a.navigateUp();
|
||||
assertPosition(0, 1, a.getCursorPosition())
|
||||
}})
|
||||
});
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
*/
|
||||
require.def(["ace/Range"], function(b) {
|
||||
RangeTest = new TestCase("RangeTest", {"test: create range":function() {
|
||||
var a = new b(1, 2, 3, 4);
|
||||
assertEquals(1, a.start.row);
|
||||
assertEquals(2, a.start.column);
|
||||
assertEquals(3, a.end.row);
|
||||
assertEquals(4, a.end.column)
|
||||
}, "test: create from points":function() {
|
||||
var a = b.fromPoints({row:1, column:2}, {row:3, column:4});
|
||||
assertEquals(1, a.start.row);
|
||||
assertEquals(2, a.start.column);
|
||||
assertEquals(3, a.end.row);
|
||||
assertEquals(4, a.end.column)
|
||||
}, "test: clip to rows":function() {
|
||||
assertRange(10, 0, 31, 0, (new b(0, 20, 100, 30)).clipRows(10, 30));
|
||||
assertRange(10, 0, 30, 10, (new b(0, 20, 30, 10)).clipRows(10, 30));
|
||||
var a = new b(0, 20, 3, 10);
|
||||
a = a.clipRows(10, 30);
|
||||
assertTrue(a.isEmpty());
|
||||
assertRange(10, 0, 10, 0, a)
|
||||
}, "test: isEmpty":function() {
|
||||
var a = new b(1, 2, 1, 2);
|
||||
assertTrue(a.isEmpty());
|
||||
a = new b(1, 2, 1, 6);
|
||||
assertFalse(a.isEmpty())
|
||||
}, "test: is multi line":function() {
|
||||
var a = new b(1, 2, 1, 6);
|
||||
assertFalse(a.isMultiLine());
|
||||
a = new b(1, 2, 2, 6);
|
||||
assertTrue(a.isMultiLine())
|
||||
}, "test: clone":function() {
|
||||
var a = new b(1, 2, 3, 4), c = a.clone();
|
||||
assertPosition(1, 2, c.start);
|
||||
assertPosition(3, 4, c.end);
|
||||
c.start.column = 20;
|
||||
assertPosition(1, 2, a.start);
|
||||
c.end.column = 20;
|
||||
assertPosition(3, 4, a.end)
|
||||
}, "test: contains for multi line ranges":function() {
|
||||
var a = new b(1, 10, 5, 20);
|
||||
assertTrue(a.contains(1, 10));
|
||||
assertTrue(a.contains(2, 0));
|
||||
assertTrue(a.contains(3, 100));
|
||||
assertTrue(a.contains(5, 19));
|
||||
assertTrue(a.contains(5, 20));
|
||||
assertFalse(a.contains(1, 9));
|
||||
assertFalse(a.contains(0, 0));
|
||||
assertFalse(a.contains(5, 21))
|
||||
}, "test: contains for single line ranges":function() {
|
||||
var a = new b(1, 10, 1, 20);
|
||||
assertTrue(a.contains(1, 10));
|
||||
assertTrue(a.contains(1, 15));
|
||||
assertTrue(a.contains(1, 20));
|
||||
assertFalse(a.contains(0, 9));
|
||||
assertFalse(a.contains(2, 9));
|
||||
assertFalse(a.contains(1, 9));
|
||||
assertFalse(a.contains(1, 21))
|
||||
}, "test: extend range":function() {
|
||||
var a = new b(2, 10, 2, 30);
|
||||
a = a.extend(2, 5);
|
||||
assertRange(2, 5, 2, 30, a);
|
||||
a = a.extend(2, 35);
|
||||
assertRange(2, 5, 2, 35, a);
|
||||
a = a.extend(2, 15);
|
||||
assertRange(2, 5, 2, 35, a);
|
||||
a = a.extend(1, 4);
|
||||
assertRange(1, 4, 2, 35, a);
|
||||
a = a.extend(6, 10);
|
||||
assertRange(1, 4, 6, 10, a)
|
||||
}})
|
||||
});
|
||||
|
|
@ -1,135 +1,135 @@
|
|||
/*
|
||||
LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
*/
|
||||
require.def(["ace/Document", "ace/Search"], function(c, b) {
|
||||
new TestCase("SearchTest", {"test: configure the search object":function() {
|
||||
(new b).set({needle:"juhu", scope:b.ALL})
|
||||
}, "test: find simple text in document":function() {
|
||||
var a = new c(["juhu kinners 123", "456"]);
|
||||
a = (new b).set({needle:"kinners"}).find(a);
|
||||
assertPosition(0, 5, a.start);
|
||||
assertPosition(0, 12, a.end)
|
||||
}, "test: find simple text in next line":function() {
|
||||
var a = new c(["abc", "juhu kinners 123", "456"]);
|
||||
a = (new b).set({needle:"kinners"}).find(a);
|
||||
assertPosition(1, 5, a.start);
|
||||
assertPosition(1, 12, a.end)
|
||||
}, "test: find text starting at cursor position":function() {
|
||||
var a = new c(["juhu kinners", "juhu kinners 123"]);
|
||||
a.getSelection().moveCursorTo(0, 6);
|
||||
a = (new b).set({needle:"kinners"}).find(a);
|
||||
assertPosition(1, 5, a.start);
|
||||
assertPosition(1, 12, a.end)
|
||||
}, "test: wrap search is off by default":function() {
|
||||
var a = new c(["abc", "juhu kinners 123", "456"]);
|
||||
a.getSelection().moveCursorTo(2, 1);
|
||||
var d = (new b).set({needle:"kinners"});
|
||||
assertEquals(null, d.find(a))
|
||||
}, "test: wrap search should wrap at file end":function() {
|
||||
var a = new c(["abc", "juhu kinners 123", "456"]);
|
||||
a.getSelection().moveCursorTo(2, 1);
|
||||
a = (new b).set({needle:"kinners", wrap:true}).find(a);
|
||||
assertPosition(1, 5, a.start);
|
||||
assertPosition(1, 12, a.end)
|
||||
}, "test: wrap search with no match should return 'null'":function() {
|
||||
var a = new c(["abc", "juhu kinners 123", "456"]);
|
||||
a.getSelection().moveCursorTo(2, 1);
|
||||
var d = (new b).set({needle:"xyz", wrap:true});
|
||||
assertEquals(null, d.find(a))
|
||||
}, "test: case sensitive is by default off":function() {
|
||||
var a = new c(["abc", "juhu kinners 123", "456"]), d = (new b).set({needle:"JUHU"});
|
||||
assertEquals(null, d.find(a))
|
||||
}, "test: case sensitive search":function() {
|
||||
var a = new c(["abc", "juhu kinners 123", "456"]);
|
||||
a = (new b).set({needle:"KINNERS", caseSensitive:true}).find(a);
|
||||
assertPosition(1, 5, a.start);
|
||||
assertPosition(1, 12, a.end)
|
||||
}, "test: whole word search should not match inside of words":function() {
|
||||
var a = new c(["juhukinners", "juhu kinners 123", "456"]);
|
||||
a = (new b).set({needle:"kinners", wholeWord:true}).find(a);
|
||||
assertPosition(1, 5, a.start);
|
||||
assertPosition(1, 12, a.end)
|
||||
}, "test: find backwards":function() {
|
||||
var a = new c(["juhu juhu juhu juhu"]);
|
||||
a.getSelection().moveCursorTo(0, 10);
|
||||
a = (new b).set({needle:"juhu", backwards:true}).find(a);
|
||||
assertPosition(0, 5, a.start);
|
||||
assertPosition(0, 9, a.end)
|
||||
}, "test: find in selection":function() {
|
||||
var a = new c(["juhu", "juhu", "juhu", "juhu"]);
|
||||
a.getSelection().setSelectionAnchor(1, 0);
|
||||
a.getSelection().selectTo(3, 5);
|
||||
var d = (new b).set({needle:"juhu", wrap:true, scope:b.SELECTION}), e = d.find(a);
|
||||
assertPosition(1, 0, e.start);
|
||||
assertPosition(1, 4, e.end);
|
||||
a.getSelection().setSelectionAnchor(0, 2);
|
||||
a.getSelection().selectTo(3, 2);
|
||||
e = d.find(a);
|
||||
assertPosition(1, 0, e.start);
|
||||
assertPosition(1, 4, e.end)
|
||||
}, "test: find backwards in selection":function() {
|
||||
var a = new c(["juhu", "juhu", "juhu", "juhu"]), d = (new b).set({needle:"juhu", wrap:true, backwards:true, scope:b.SELECTION});
|
||||
a.getSelection().setSelectionAnchor(0, 2);
|
||||
a.getSelection().selectTo(3, 2);
|
||||
var e = d.find(a);
|
||||
assertPosition(2, 0, e.start);
|
||||
assertPosition(2, 4, e.end);
|
||||
a.getSelection().setSelectionAnchor(0, 2);
|
||||
a.getSelection().selectTo(1, 2);
|
||||
assertEquals(null, d.find(a))
|
||||
}, "test: edge case - match directly before the cursor":function() {
|
||||
var a = new c(["123", "123", "juhu"]), d = (new b).set({needle:"juhu", wrap:true});
|
||||
a.getSelection().moveCursorTo(2, 5);
|
||||
a = d.find(a);
|
||||
assertPosition(2, 0, a.start);
|
||||
assertPosition(2, 4, a.end)
|
||||
}, "test: edge case - match backwards directly after the cursor":function() {
|
||||
var a = new c(["123", "123", "juhu"]), d = (new b).set({needle:"juhu", wrap:true, backwards:true});
|
||||
a.getSelection().moveCursorTo(2, 0);
|
||||
a = d.find(a);
|
||||
assertPosition(2, 0, a.start);
|
||||
assertPosition(2, 4, a.end)
|
||||
}, "test: find using a regular expression":function() {
|
||||
var a = new c(["abc123 123 cd", "abc"]);
|
||||
a = (new b).set({needle:"\\d+", regExp:true}).find(a);
|
||||
assertPosition(0, 3, a.start);
|
||||
assertPosition(0, 6, a.end)
|
||||
}, "test: find using a regular expression and whole word":function() {
|
||||
var a = new c(["abc123 123 cd", "abc"]);
|
||||
a = (new b).set({needle:"\\d+\\b", regExp:true, wholeWord:true}).find(a);
|
||||
assertPosition(0, 7, a.start);
|
||||
assertPosition(0, 10, a.end)
|
||||
}, "test: use regular expressions with capture groups":function() {
|
||||
var a = new c([" ab: 12px", " <h1 abc"]);
|
||||
a = (new b).set({needle:"(\\d+)", regExp:true}).find(a);
|
||||
assertPosition(0, 6, a.start);
|
||||
assertPosition(0, 8, a.end)
|
||||
}, "test: find all matches in selection":function() {
|
||||
var a = new c(["juhu", "juhu", "juhu", "juhu"]), d = (new b).set({needle:"uh", wrap:true, scope:b.SELECTION});
|
||||
a.getSelection().setSelectionAnchor(0, 2);
|
||||
a.getSelection().selectTo(3, 2);
|
||||
a = d.findAll(a);
|
||||
assertEquals(2, a.length);
|
||||
assertPosition(1, 1, a[0].start);
|
||||
assertPosition(1, 3, a[0].end);
|
||||
assertPosition(2, 1, a[1].start);
|
||||
assertPosition(2, 3, a[1].end)
|
||||
}, "test: replace() should return the replacement if the input matches the needle":function() {
|
||||
var a = (new b).set({needle:"juhu"});
|
||||
assertEquals("kinners", a.replace("juhu", "kinners"));
|
||||
assertEquals(null, a.replace("", "kinners"));
|
||||
assertEquals(null, a.replace(" juhu", "kinners"))
|
||||
}, "test: replace with a RegExp search":function() {
|
||||
var a = (new b).set({needle:"\\d+", regExp:true});
|
||||
assertEquals("kinners", a.replace("123", "kinners"));
|
||||
assertEquals("kinners", a.replace("01234", "kinners"));
|
||||
assertEquals(null, a.replace("", "kinners"));
|
||||
assertEquals(null, a.replace("a12", "kinners"));
|
||||
assertEquals(null, a.replace("12a", "kinners"))
|
||||
}, "test: replace with RegExp match and capture groups":function() {
|
||||
var a = (new b).set({needle:"ab(\\d\\d)", regExp:true});
|
||||
assertEquals("cd12", a.replace("ab12", "cd$1"));
|
||||
assertEquals("-ab12-", a.replace("ab12", "-$&-"));
|
||||
assertEquals("$", a.replace("ab12", "$$"))
|
||||
}})
|
||||
});
|
||||
require("../../../support/paths");
|
||||
var Document = require("../document"), Search = require("../search"), assert = require("./assertions"), Test = {"test: configure the search object":function() {
|
||||
(new Search).set({needle:"juhu", scope:Search.ALL})
|
||||
}, "test: find simple text in document":function() {
|
||||
var a = new Document(["juhu kinners 123", "456"]);
|
||||
a = (new Search).set({needle:"kinners"}).find(a);
|
||||
assert.position(a.start, 0, 5);
|
||||
assert.position(a.end, 0, 12)
|
||||
}, "test: find simple text in next line":function() {
|
||||
var a = new Document(["abc", "juhu kinners 123", "456"]);
|
||||
a = (new Search).set({needle:"kinners"}).find(a);
|
||||
assert.position(a.start, 1, 5);
|
||||
assert.position(a.end, 1, 12)
|
||||
}, "test: find text starting at cursor position":function() {
|
||||
var a = new Document(["juhu kinners", "juhu kinners 123"]);
|
||||
a.getSelection().moveCursorTo(0, 6);
|
||||
a = (new Search).set({needle:"kinners"}).find(a);
|
||||
assert.position(a.start, 1, 5);
|
||||
assert.position(a.end, 1, 12)
|
||||
}, "test: wrap search is off by default":function() {
|
||||
var a = new Document(["abc", "juhu kinners 123", "456"]);
|
||||
a.getSelection().moveCursorTo(2, 1);
|
||||
var b = (new Search).set({needle:"kinners"});
|
||||
assert.equal(b.find(a), null)
|
||||
}, "test: wrap search should wrap at file end":function() {
|
||||
var a = new Document(["abc", "juhu kinners 123", "456"]);
|
||||
a.getSelection().moveCursorTo(2, 1);
|
||||
a = (new Search).set({needle:"kinners", wrap:true}).find(a);
|
||||
assert.position(a.start, 1, 5);
|
||||
assert.position(a.end, 1, 12)
|
||||
}, "test: wrap search with no match should return 'null'":function() {
|
||||
var a = new Document(["abc", "juhu kinners 123", "456"]);
|
||||
a.getSelection().moveCursorTo(2, 1);
|
||||
var b = (new Search).set({needle:"xyz", wrap:true});
|
||||
assert.equal(b.find(a), null)
|
||||
}, "test: case sensitive is by default off":function() {
|
||||
var a = new Document(["abc", "juhu kinners 123", "456"]), b = (new Search).set({needle:"JUHU"});
|
||||
assert.range(b.find(a), 1, 0, 1, 4)
|
||||
}, "test: case sensitive search":function() {
|
||||
var a = new Document(["abc", "juhu kinners 123", "456"]);
|
||||
a = (new Search).set({needle:"KINNERS", caseSensitive:true}).find(a);
|
||||
assert.equal(a, null)
|
||||
}, "test: whole word search should not match inside of words":function() {
|
||||
var a = new Document(["juhukinners", "juhu kinners 123", "456"]);
|
||||
a = (new Search).set({needle:"kinners", wholeWord:true}).find(a);
|
||||
assert.position(a.start, 1, 5);
|
||||
assert.position(a.end, 1, 12)
|
||||
}, "test: find backwards":function() {
|
||||
var a = new Document(["juhu juhu juhu juhu"]);
|
||||
a.getSelection().moveCursorTo(0, 10);
|
||||
a = (new Search).set({needle:"juhu", backwards:true}).find(a);
|
||||
assert.position(a.start, 0, 5);
|
||||
assert.position(a.end, 0, 9)
|
||||
}, "test: find in selection":function() {
|
||||
var a = new Document(["juhu", "juhu", "juhu", "juhu"]);
|
||||
a.getSelection().setSelectionAnchor(1, 0);
|
||||
a.getSelection().selectTo(3, 5);
|
||||
var b = (new Search).set({needle:"juhu", wrap:true, scope:Search.SELECTION}), c = b.find(a);
|
||||
assert.position(c.start, 1, 0);
|
||||
assert.position(c.end, 1, 4);
|
||||
a.getSelection().setSelectionAnchor(0, 2);
|
||||
a.getSelection().selectTo(3, 2);
|
||||
c = b.find(a);
|
||||
assert.position(c.start, 1, 0);
|
||||
assert.position(c.end, 1, 4)
|
||||
}, "test: find backwards in selection":function() {
|
||||
var a = new Document(["juhu", "juhu", "juhu", "juhu"]), b = (new Search).set({needle:"juhu", wrap:true, backwards:true, scope:Search.SELECTION});
|
||||
a.getSelection().setSelectionAnchor(0, 2);
|
||||
a.getSelection().selectTo(3, 2);
|
||||
var c = b.find(a);
|
||||
assert.position(c.start, 2, 0);
|
||||
assert.position(c.end, 2, 4);
|
||||
a.getSelection().setSelectionAnchor(0, 2);
|
||||
a.getSelection().selectTo(1, 2);
|
||||
assert.equal(b.find(a), null)
|
||||
}, "test: edge case - match directly before the cursor":function() {
|
||||
var a = new Document(["123", "123", "juhu"]), b = (new Search).set({needle:"juhu", wrap:true});
|
||||
a.getSelection().moveCursorTo(2, 5);
|
||||
a = b.find(a);
|
||||
assert.position(a.start, 2, 0);
|
||||
assert.position(a.end, 2, 4)
|
||||
}, "test: edge case - match backwards directly after the cursor":function() {
|
||||
var a = new Document(["123", "123", "juhu"]), b = (new Search).set({needle:"juhu", wrap:true, backwards:true});
|
||||
a.getSelection().moveCursorTo(2, 0);
|
||||
a = b.find(a);
|
||||
assert.position(a.start, 2, 0);
|
||||
assert.position(a.end, 2, 4)
|
||||
}, "test: find using a regular expression":function() {
|
||||
var a = new Document(["abc123 123 cd", "abc"]);
|
||||
a = (new Search).set({needle:"\\d+", regExp:true}).find(a);
|
||||
assert.position(a.start, 0, 3);
|
||||
assert.position(a.end, 0, 6)
|
||||
}, "test: find using a regular expression and whole word":function() {
|
||||
var a = new Document(["abc123 123 cd", "abc"]);
|
||||
a = (new Search).set({needle:"\\d+\\b", regExp:true, wholeWord:true}).find(a);
|
||||
assert.position(a.start, 0, 7);
|
||||
assert.position(a.end, 0, 10)
|
||||
}, "test: use regular expressions with capture groups":function() {
|
||||
var a = new Document([" ab: 12px", " <h1 abc"]);
|
||||
a = (new Search).set({needle:"(\\d+)", regExp:true}).find(a);
|
||||
assert.position(a.start, 0, 6);
|
||||
assert.position(a.end, 0, 8)
|
||||
}, "test: find all matches in selection":function() {
|
||||
var a = new Document(["juhu", "juhu", "juhu", "juhu"]), b = (new Search).set({needle:"uh", wrap:true, scope:Search.SELECTION});
|
||||
a.getSelection().setSelectionAnchor(0, 2);
|
||||
a.getSelection().selectTo(3, 2);
|
||||
a = b.findAll(a);
|
||||
assert.equal(a.length, 2);
|
||||
assert.position(a[0].start, 1, 1);
|
||||
assert.position(a[0].end, 1, 3);
|
||||
assert.position(a[1].start, 2, 1);
|
||||
assert.position(a[1].end, 2, 3)
|
||||
}, "test: replace() should return the replacement if the input matches the needle":function() {
|
||||
var a = (new Search).set({needle:"juhu"});
|
||||
assert.equal(a.replace("juhu", "kinners"), "kinners");
|
||||
assert.equal(a.replace("", "kinners"), null);
|
||||
assert.equal(a.replace(" juhu", "kinners"), null)
|
||||
}, "test: replace with a RegExp search":function() {
|
||||
var a = (new Search).set({needle:"\\d+", regExp:true});
|
||||
assert.equal(a.replace("123", "kinners"), "kinners");
|
||||
assert.equal(a.replace("01234", "kinners"), "kinners");
|
||||
assert.equal(a.replace("", "kinners"), null);
|
||||
assert.equal(a.replace("a12", "kinners"), null);
|
||||
assert.equal(a.replace("12a", "kinners"), null)
|
||||
}, "test: replace with RegExp match and capture groups":function() {
|
||||
var a = (new Search).set({needle:"ab(\\d\\d)", regExp:true});
|
||||
assert.equal(a.replace("ab12", "cd$1"), "cd12");
|
||||
assert.equal(a.replace("ab12", "-$&-"), "-ab12-");
|
||||
assert.equal(a.replace("ab12", "$$"), "$")
|
||||
}};
|
||||
module.exports = require("async/test").testcase(Test);
|
||||
module === require.main && module.exports.exec();
|
||||
|
|
@ -1,149 +0,0 @@
|
|||
/*
|
||||
LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
*/
|
||||
require.def(["ace/Document"], function(c) {
|
||||
TestCase("SelectionTest", {createTextDocument:function(a, b) {
|
||||
b = (new Array(b + 1)).join("a");
|
||||
a = (new Array(a)).join(b + "\n") + b;
|
||||
return new c(a)
|
||||
}, "test: move cursor to end of file should place the cursor on last row and column":function() {
|
||||
var a = this.createTextDocument(200, 10).getSelection();
|
||||
a.moveCursorFileEnd();
|
||||
assertPosition(199, 10, a.getCursor())
|
||||
}, "test: moveCursor to start of file should place the cursor on the first row and column":function() {
|
||||
var a = this.createTextDocument(200, 10).getSelection();
|
||||
a.moveCursorFileStart();
|
||||
assertPosition(0, 0, a.getCursor())
|
||||
}, "test: move selection lead to end of file":function() {
|
||||
var a = this.createTextDocument(200, 10).getSelection();
|
||||
a.moveCursorTo(100, 5);
|
||||
a.selectFileEnd();
|
||||
a = a.getRange();
|
||||
assertPosition(100, 5, a.start);
|
||||
assertPosition(199, 10, a.end)
|
||||
}, "test: move selection lead to start of file":function() {
|
||||
var a = this.createTextDocument(200, 10).getSelection();
|
||||
a.moveCursorTo(100, 5);
|
||||
a.selectFileStart();
|
||||
a = a.getRange();
|
||||
assertPosition(0, 0, a.start);
|
||||
assertPosition(100, 5, a.end)
|
||||
}, "test: move cursor word right":function() {
|
||||
var a = (new c("ab\n Juhu Kinners (abc, 12)\n cde")).getSelection();
|
||||
a.moveCursorDown();
|
||||
assertPosition(1, 0, a.getCursor());
|
||||
a.moveCursorWordRight();
|
||||
assertPosition(1, 1, a.getCursor());
|
||||
a.moveCursorWordRight();
|
||||
assertPosition(1, 5, a.getCursor());
|
||||
a.moveCursorWordRight();
|
||||
assertPosition(1, 6, a.getCursor());
|
||||
a.moveCursorWordRight();
|
||||
assertPosition(1, 13, a.getCursor());
|
||||
a.moveCursorWordRight();
|
||||
assertPosition(1, 15, a.getCursor());
|
||||
a.moveCursorWordRight();
|
||||
assertPosition(1, 18, a.getCursor());
|
||||
a.moveCursorWordRight();
|
||||
assertPosition(1, 20, a.getCursor());
|
||||
a.moveCursorWordRight();
|
||||
assertPosition(1, 22, a.getCursor());
|
||||
a.moveCursorWordRight();
|
||||
assertPosition(1, 23, a.getCursor());
|
||||
a.moveCursorWordRight();
|
||||
assertPosition(2, 0, a.getCursor())
|
||||
}, "test: select word right if cursor in word":function() {
|
||||
var a = (new c("Juhu Kinners")).getSelection();
|
||||
a.moveCursorTo(0, 2);
|
||||
a.moveCursorWordRight();
|
||||
assertPosition(0, 4, a.getCursor())
|
||||
}, "test: moveCursor word left":function() {
|
||||
var a = (new c("ab\n Juhu Kinners (abc, 12)\n cde")).getSelection();
|
||||
a.moveCursorDown();
|
||||
a.moveCursorLineEnd();
|
||||
assertPosition(1, 23, a.getCursor());
|
||||
a.moveCursorWordLeft();
|
||||
assertPosition(1, 22, a.getCursor());
|
||||
a.moveCursorWordLeft();
|
||||
assertPosition(1, 20, a.getCursor());
|
||||
a.moveCursorWordLeft();
|
||||
assertPosition(1, 18, a.getCursor());
|
||||
a.moveCursorWordLeft();
|
||||
assertPosition(1, 15, a.getCursor());
|
||||
a.moveCursorWordLeft();
|
||||
assertPosition(1, 13, a.getCursor());
|
||||
a.moveCursorWordLeft();
|
||||
assertPosition(1, 6, a.getCursor());
|
||||
a.moveCursorWordLeft();
|
||||
assertPosition(1, 5, a.getCursor());
|
||||
a.moveCursorWordLeft();
|
||||
assertPosition(1, 1, a.getCursor());
|
||||
a.moveCursorWordLeft();
|
||||
assertPosition(1, 0, a.getCursor());
|
||||
a.moveCursorWordLeft();
|
||||
assertPosition(0, 2, a.getCursor())
|
||||
}, "test: select word left if cursor in word":function() {
|
||||
var a = (new c("Juhu Kinners")).getSelection();
|
||||
a.moveCursorTo(0, 8);
|
||||
a.moveCursorWordLeft();
|
||||
assertPosition(0, 5, a.getCursor())
|
||||
}, "test: select word right and select":function() {
|
||||
var a = (new c("Juhu Kinners")).getSelection();
|
||||
a.moveCursorTo(0, 0);
|
||||
a.selectWordRight();
|
||||
a = a.getRange();
|
||||
assertPosition(0, 0, a.start);
|
||||
assertPosition(0, 4, a.end)
|
||||
}, "test: select word left and select":function() {
|
||||
var a = (new c("Juhu Kinners")).getSelection();
|
||||
a.moveCursorTo(0, 3);
|
||||
a.selectWordLeft();
|
||||
a = a.getRange();
|
||||
assertPosition(0, 0, a.start);
|
||||
assertPosition(0, 3, a.end)
|
||||
}, "test: select word with cursor in word should select the word":function() {
|
||||
var a = (new c("Juhu Kinners 123")).getSelection();
|
||||
a.moveCursorTo(0, 8);
|
||||
a.selectWord();
|
||||
a = a.getRange();
|
||||
assertPosition(0, 5, a.start);
|
||||
assertPosition(0, 12, a.end)
|
||||
}, "test: select word with cursor betwen white space and word should select the word":function() {
|
||||
var a = (new c("Juhu Kinners")).getSelection();
|
||||
a.moveCursorTo(0, 4);
|
||||
a.selectWord();
|
||||
var b = a.getRange();
|
||||
assertPosition(0, 0, b.start);
|
||||
assertPosition(0, 4, b.end);
|
||||
a.moveCursorTo(0, 5);
|
||||
a.selectWord();
|
||||
b = a.getRange();
|
||||
assertPosition(0, 5, b.start);
|
||||
assertPosition(0, 12, b.end)
|
||||
}, "test: select word with cursor in white space should select white space":function() {
|
||||
var a = (new c("Juhu Kinners")).getSelection();
|
||||
a.moveCursorTo(0, 5);
|
||||
a.selectWord();
|
||||
a = a.getRange();
|
||||
assertPosition(0, 4, a.start);
|
||||
assertPosition(0, 6, a.end)
|
||||
}, "test: moving cursor should fire a 'changeCursor' event":function() {
|
||||
var a = (new c("Juhu Kinners")).getSelection();
|
||||
a.moveCursorTo(0, 5);
|
||||
var b = false;
|
||||
a.addEventListener("changeCursor", function() {
|
||||
b = true
|
||||
});
|
||||
a.moveCursorTo(0, 6);
|
||||
assertTrue(b)
|
||||
}, "test: calling setCursor with the same position should not fire an event":function() {
|
||||
var a = (new c("Juhu Kinners")).getSelection();
|
||||
a.moveCursorTo(0, 5);
|
||||
var b = false;
|
||||
a.addEventListener("changeCursor", function() {
|
||||
b = true
|
||||
});
|
||||
a.moveCursorTo(0, 5);
|
||||
assertFalse(b)
|
||||
}})
|
||||
});
|
||||
|
|
@ -1,178 +1,185 @@
|
|||
/*
|
||||
LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
*/
|
||||
require.def(["ace/Document", "ace/Editor", "ace/mode/JavaScript", "ace/test/MockRenderer"], function(c, d, g, e) {
|
||||
TestCase("TextEditTest", {"test: delete line from the middle":function() {
|
||||
var b = new c("a\nb\nc\nd"), a = new d(new e, b);
|
||||
a.moveCursorTo(1, 1);
|
||||
a.removeLines();
|
||||
assertEquals("a\nc\nd", b.toString());
|
||||
assertPosition(1, 0, a.getCursorPosition());
|
||||
a.removeLines();
|
||||
assertEquals("a\nd", b.toString());
|
||||
assertPosition(1, 0, a.getCursorPosition());
|
||||
a.removeLines();
|
||||
assertEquals("a\n", b.toString());
|
||||
assertPosition(1, 0, a.getCursorPosition());
|
||||
a.removeLines();
|
||||
assertEquals("a\n", b.toString());
|
||||
assertPosition(1, 0, a.getCursorPosition())
|
||||
}, "test: delete multiple selected lines":function() {
|
||||
var b = new c("a\nb\nc\nd"), a = new d(new e, b);
|
||||
a.moveCursorTo(1, 1);
|
||||
a.getSelection().selectDown();
|
||||
a.removeLines();
|
||||
assertEquals("a\nd", b.toString());
|
||||
assertPosition(1, 0, a.getCursorPosition())
|
||||
}, "test: delete first line":function() {
|
||||
var b = new c("a\nb\nc"), a = new d(new e, b);
|
||||
a.removeLines();
|
||||
assertEquals("b\nc", b.toString());
|
||||
assertPosition(0, 0, a.getCursorPosition())
|
||||
}, "test: delete last":function() {
|
||||
var b = new c("a\nb\nc"), a = new d(new e, b);
|
||||
a.moveCursorTo(2, 1);
|
||||
a.removeLines();
|
||||
assertEquals("a\nb\n", b.toString());
|
||||
assertPosition(2, 0, a.getCursorPosition())
|
||||
}, "test: indent block":function() {
|
||||
var b = new c("a12345\nb12345\nc12345"), a = new d(new e, b);
|
||||
a.moveCursorTo(1, 3);
|
||||
a.getSelection().selectDown();
|
||||
a.blockIndent(" ");
|
||||
assertEquals("a12345\n b12345\n c12345", b.toString());
|
||||
assertPosition(2, 7, a.getCursorPosition());
|
||||
b = a.getSelectionRange();
|
||||
assertPosition(1, 7, b.start);
|
||||
assertPosition(2, 7, b.end)
|
||||
}, "test: outdent block":function() {
|
||||
var b = new c(" a12345\n b12345\n c12345"), a = new d(new e, b);
|
||||
a.moveCursorTo(0, 3);
|
||||
a.getSelection().selectDown();
|
||||
a.getSelection().selectDown();
|
||||
a.blockOutdent(" ");
|
||||
assertEquals(" a12345\nb12345\n c12345", b.toString());
|
||||
assertPosition(2, 1, a.getCursorPosition());
|
||||
var f = a.getSelectionRange();
|
||||
assertPosition(0, 1, f.start);
|
||||
assertPosition(2, 1, f.end);
|
||||
a.blockOutdent(" ");
|
||||
assertEquals(" a12345\nb12345\n c12345", b.toString());
|
||||
f = a.getSelectionRange();
|
||||
assertPosition(0, 1, f.start);
|
||||
assertPosition(2, 1, f.end)
|
||||
}, "test: outent without a selection should update cursor":function() {
|
||||
var b = new c(" 12"), a = new d(new e, b);
|
||||
a.moveCursorTo(0, 3);
|
||||
a.blockOutdent(" ");
|
||||
assertEquals(" 12", b.toString());
|
||||
assertPosition(0, 1, a.getCursorPosition())
|
||||
}, "test: comment lines should perserve selection":function() {
|
||||
var b = new c(" abc\ncde", new g), a = new d(new e, b);
|
||||
a.moveCursorTo(0, 2);
|
||||
a.getSelection().selectDown();
|
||||
a.toggleCommentLines();
|
||||
assertEquals("// abc\n//cde", b.toString());
|
||||
b = a.getSelectionRange();
|
||||
assertPosition(0, 4, b.start);
|
||||
assertPosition(1, 4, b.end)
|
||||
}, "test: uncomment lines should perserve selection":function() {
|
||||
var b = new c("// abc\n//cde", new g), a = new d(new e, b);
|
||||
a.moveCursorTo(0, 1);
|
||||
a.getSelection().selectDown();
|
||||
a.getSelection().selectRight();
|
||||
a.getSelection().selectRight();
|
||||
a.toggleCommentLines();
|
||||
assertEquals(" abc\ncde", b.toString());
|
||||
assertRange(0, 0, 1, 1, a.getSelectionRange())
|
||||
}, "test: comment lines - if the selection end is at the line start it should stay there":function() {
|
||||
var b = new c("abc\ncde", new g);
|
||||
b = new d(new e, b);
|
||||
b.moveCursorTo(0, 0);
|
||||
b.getSelection().selectDown();
|
||||
b.toggleCommentLines();
|
||||
assertRange(0, 2, 1, 0, b.getSelectionRange());
|
||||
b = new c("abc\ncde", new g);
|
||||
b = new d(new e, b);
|
||||
b.moveCursorTo(1, 0);
|
||||
b.getSelection().selectUp();
|
||||
b.toggleCommentLines();
|
||||
assertRange(0, 2, 1, 0, b.getSelectionRange())
|
||||
}, "test: move lines down should select moved lines":function() {
|
||||
var b = new c("11\n22\n33\n44"), a = new d(new e, b);
|
||||
a.moveCursorTo(0, 1);
|
||||
a.getSelection().selectDown();
|
||||
a.moveLinesDown();
|
||||
assertEquals("33\n11\n22\n44", b.toString());
|
||||
assertPosition(1, 0, a.getCursorPosition());
|
||||
assertPosition(3, 0, a.getSelection().getSelectionAnchor());
|
||||
assertPosition(1, 0, a.getSelection().getSelectionLead());
|
||||
a.moveLinesDown();
|
||||
assertEquals("33\n44\n11\n22", b.toString());
|
||||
assertPosition(2, 0, a.getCursorPosition());
|
||||
assertPosition(3, 2, a.getSelection().getSelectionAnchor());
|
||||
assertPosition(2, 0, a.getSelection().getSelectionLead());
|
||||
a.moveLinesDown();
|
||||
assertEquals("33\n44\n11\n22", b.toString());
|
||||
assertPosition(2, 0, a.getCursorPosition());
|
||||
assertPosition(3, 2, a.getSelection().getSelectionAnchor());
|
||||
assertPosition(2, 0, a.getSelection().getSelectionLead())
|
||||
}, "test: move lines up should select moved lines":function() {
|
||||
var b = new c("11\n22\n33\n44"), a = new d(new e, b);
|
||||
a.moveCursorTo(2, 1);
|
||||
a.getSelection().selectDown();
|
||||
a.moveLinesUp();
|
||||
assertEquals("11\n33\n44\n22", b.toString());
|
||||
assertPosition(1, 0, a.getCursorPosition());
|
||||
assertPosition(3, 0, a.getSelection().getSelectionAnchor());
|
||||
assertPosition(1, 0, a.getSelection().getSelectionLead());
|
||||
a.moveLinesUp();
|
||||
assertEquals("33\n44\n11\n22", b.toString());
|
||||
assertPosition(0, 0, a.getCursorPosition());
|
||||
assertPosition(2, 0, a.getSelection().getSelectionAnchor());
|
||||
assertPosition(0, 0, a.getSelection().getSelectionLead())
|
||||
}, "test: move line without active selection should move cursor to start of the moved line":function() {
|
||||
var b = new c("11\n22\n33\n44"), a = new d(new e, b);
|
||||
a.moveCursorTo(1, 1);
|
||||
a.clearSelection();
|
||||
a.moveLinesDown();
|
||||
assertEquals("11\n33\n22\n44", b.toString());
|
||||
assertPosition(2, 0, a.getCursorPosition());
|
||||
a.clearSelection();
|
||||
a.moveLinesUp();
|
||||
assertEquals("11\n22\n33\n44", b.toString());
|
||||
assertPosition(1, 0, a.getCursorPosition())
|
||||
}, "test: copy lines down should select lines and place cursor at the selection start":function() {
|
||||
var b = new c("11\n22\n33\n44"), a = new d(new e, b);
|
||||
a.moveCursorTo(1, 1);
|
||||
a.getSelection().selectDown();
|
||||
a.copyLinesDown();
|
||||
assertEquals("11\n22\n33\n22\n33\n44", b.toString());
|
||||
assertPosition(3, 0, a.getCursorPosition());
|
||||
assertPosition(5, 0, a.getSelection().getSelectionAnchor());
|
||||
assertPosition(3, 0, a.getSelection().getSelectionLead())
|
||||
}, "test: copy lines up should select lines and place cursor at the selection start":function() {
|
||||
var b = new c("11\n22\n33\n44"), a = new d(new e, b);
|
||||
a.moveCursorTo(1, 1);
|
||||
a.getSelection().selectDown();
|
||||
a.copyLinesUp();
|
||||
assertEquals("11\n22\n33\n22\n33\n44", b.toString());
|
||||
assertPosition(1, 0, a.getCursorPosition());
|
||||
assertPosition(3, 0, a.getSelection().getSelectionAnchor());
|
||||
assertPosition(1, 0, a.getSelection().getSelectionLead())
|
||||
}, "test: input a tab with soft tab should convert it to spaces":function() {
|
||||
var b = new c(""), a = new d(new e, b);
|
||||
b.setTabSize(2);
|
||||
b.setUseSoftTabs(true);
|
||||
a.onTextInput("\t");
|
||||
assertEquals(" ", b.toString());
|
||||
b.setTabSize(5);
|
||||
a.onTextInput("\t");
|
||||
assertEquals(" ", b.toString())
|
||||
}, "test: input tab without soft tabs should keep the tab character":function() {
|
||||
var b = new c(""), a = new d(new e, b);
|
||||
b.setUseSoftTabs(false);
|
||||
a.onTextInput("\t");
|
||||
assertEquals("\t", b.toString())
|
||||
}})
|
||||
});
|
||||
require("../../../support/paths");
|
||||
var dom = require("jsdom/level2/html").dom.level2.html, browser = require("jsdom/browser/index").windowAugmentation(dom);
|
||||
global.document = browser.document;
|
||||
global.window = browser.window;
|
||||
global.self = browser.self;
|
||||
global.navigator = browser.navigator;
|
||||
global.location = browser.location;
|
||||
var Document = require("../document"), Editor = require("../editor"), JavaScriptMode = require("../mode/javascript"), MockRenderer = require("./mockrenderer"), assert = require("./assertions"), Test = {"test: delete line from the middle":function() {
|
||||
var b = new Document("a\nb\nc\nd"), a = new Editor(new MockRenderer, b);
|
||||
a.moveCursorTo(1, 1);
|
||||
a.removeLines();
|
||||
assert.equal(b.toString(), "a\nc\nd");
|
||||
assert.position(a.getCursorPosition(), 1, 0);
|
||||
a.removeLines();
|
||||
assert.equal(b.toString(), "a\nd");
|
||||
assert.position(a.getCursorPosition(), 1, 0);
|
||||
a.removeLines();
|
||||
assert.equal(b.toString(), "a\n");
|
||||
assert.position(a.getCursorPosition(), 1, 0);
|
||||
a.removeLines();
|
||||
assert.equal(b.toString(), "a\n");
|
||||
assert.position(a.getCursorPosition(), 1, 0)
|
||||
}, "test: delete multiple selected lines":function() {
|
||||
var b = new Document("a\nb\nc\nd"), a = new Editor(new MockRenderer, b);
|
||||
a.moveCursorTo(1, 1);
|
||||
a.getSelection().selectDown();
|
||||
a.removeLines();
|
||||
assert.equal(b.toString(), "a\nd");
|
||||
assert.position(a.getCursorPosition(), 1, 0)
|
||||
}, "test: delete first line":function() {
|
||||
var b = new Document("a\nb\nc"), a = new Editor(new MockRenderer, b);
|
||||
a.removeLines();
|
||||
assert.equal(b.toString(), "b\nc");
|
||||
assert.position(a.getCursorPosition(), 0, 0)
|
||||
}, "test: delete last":function() {
|
||||
var b = new Document("a\nb\nc"), a = new Editor(new MockRenderer, b);
|
||||
a.moveCursorTo(2, 1);
|
||||
a.removeLines();
|
||||
assert.equal(b.toString(), "a\nb\n");
|
||||
assert.position(a.getCursorPosition(), 2, 0)
|
||||
}, "__test: indent block":function() {
|
||||
var b = new Document("a12345\nb12345\nc12345"), a = new Editor(new MockRenderer, b);
|
||||
a.moveCursorTo(1, 3);
|
||||
a.getSelection().selectDown();
|
||||
a.blockIndent(" ");
|
||||
assert.equal("a12345\n b12345\n c12345", b.toString());
|
||||
assert.position(a.getCursorPosition(), 2, 7);
|
||||
b = a.getSelectionRange();
|
||||
assert.position(b.start, 1, 7);
|
||||
assert.position(b.end, 2, 7)
|
||||
}, "__test: outdent block":function() {
|
||||
var b = new Document(" a12345\n b12345\n c12345"), a = new Editor(new MockRenderer, b);
|
||||
a.moveCursorTo(0, 3);
|
||||
a.getSelection().selectDown();
|
||||
a.getSelection().selectDown();
|
||||
a.blockOutdent(" ");
|
||||
assert.equal(b.toString(), " a12345\nb12345\n c12345");
|
||||
assert.position(a.getCursorPosition(), 2, 0);
|
||||
var c = a.getSelectionRange();
|
||||
assert.position(c.start, 0, 1);
|
||||
assert.position(c.end, 2, 1);
|
||||
a.blockOutdent(" ");
|
||||
assert.equal(b.toString(), "a12345\nb12345\nc12345");
|
||||
c = a.getSelectionRange();
|
||||
assert.position(c.start, 0, 1);
|
||||
assert.position(c.end, 2, 1)
|
||||
}, "test: outent without a selection should update cursor":function() {
|
||||
var b = new Document(" 12"), a = new Editor(new MockRenderer, b);
|
||||
a.moveCursorTo(0, 3);
|
||||
a.blockOutdent(" ");
|
||||
assert.equal(b.toString(), " 12");
|
||||
assert.position(a.getCursorPosition(), 0, 0)
|
||||
}, "test: comment lines should perserve selection":function() {
|
||||
var b = new Document(" abc\ncde", new JavaScriptMode), a = new Editor(new MockRenderer, b);
|
||||
a.moveCursorTo(0, 2);
|
||||
a.getSelection().selectDown();
|
||||
a.toggleCommentLines();
|
||||
assert.equal("// abc\n//cde", b.toString());
|
||||
b = a.getSelectionRange();
|
||||
assert.position(b.start, 0, 4);
|
||||
assert.position(b.end, 1, 4)
|
||||
}, "test: uncomment lines should perserve selection":function() {
|
||||
var b = new Document("// abc\n//cde", new JavaScriptMode), a = new Editor(new MockRenderer, b);
|
||||
a.moveCursorTo(0, 1);
|
||||
a.getSelection().selectDown();
|
||||
a.getSelection().selectRight();
|
||||
a.getSelection().selectRight();
|
||||
a.toggleCommentLines();
|
||||
assert.equal(" abc\ncde", b.toString());
|
||||
assert.range(a.getSelectionRange(), 0, 0, 1, 1)
|
||||
}, "test: comment lines - if the selection end is at the line start it should stay there":function() {
|
||||
var b = new Document("abc\ncde", new JavaScriptMode);
|
||||
b = new Editor(new MockRenderer, b);
|
||||
b.moveCursorTo(0, 0);
|
||||
b.getSelection().selectDown();
|
||||
b.toggleCommentLines();
|
||||
assert.range(b.getSelectionRange(), 0, 2, 1, 0);
|
||||
b = new Document("abc\ncde", new JavaScriptMode);
|
||||
b = new Editor(new MockRenderer, b);
|
||||
b.moveCursorTo(1, 0);
|
||||
b.getSelection().selectUp();
|
||||
b.toggleCommentLines();
|
||||
assert.range(b.getSelectionRange(), 0, 2, 1, 0)
|
||||
}, "test: move lines down should select moved lines":function() {
|
||||
var b = new Document("11\n22\n33\n44"), a = new Editor(new MockRenderer, b);
|
||||
a.moveCursorTo(0, 1);
|
||||
a.getSelection().selectDown();
|
||||
a.moveLinesDown();
|
||||
assert.equal("33\n11\n22\n44", b.toString());
|
||||
assert.position(a.getCursorPosition(), 1, 0);
|
||||
assert.position(a.getSelection().getSelectionAnchor(), 3, 0);
|
||||
assert.position(a.getSelection().getSelectionLead(), 1, 0);
|
||||
a.moveLinesDown();
|
||||
assert.equal("33\n44\n11\n22", b.toString());
|
||||
assert.position(a.getCursorPosition(), 2, 0);
|
||||
assert.position(a.getSelection().getSelectionAnchor(), 3, 2);
|
||||
assert.position(a.getSelection().getSelectionLead(), 2, 0);
|
||||
a.moveLinesDown();
|
||||
assert.equal("33\n44\n11\n22", b.toString());
|
||||
assert.position(a.getCursorPosition(), 2, 0);
|
||||
assert.position(a.getSelection().getSelectionAnchor(), 3, 2);
|
||||
assert.position(a.getSelection().getSelectionLead(), 2, 0)
|
||||
}, "__test: move lines up should select moved lines":function() {
|
||||
var b = new Document("11\n22\n33\n44"), a = new Editor(new MockRenderer, b);
|
||||
a.moveCursorTo(2, 1);
|
||||
a.getSelection().selectDown();
|
||||
a.moveLinesUp();
|
||||
assert.equal(b.toString(), "11\n33\n44\n22");
|
||||
assert.position(a.getCursorPosition(), 1, 0);
|
||||
assert.position(a.getSelection().getSelectionAnchor(), 3, 0);
|
||||
assert.position(a.getSelection().getSelectionLead(), 1, 0);
|
||||
a.moveLinesUp();
|
||||
assert.equal(b.toString(), "33\n44\n11\n22");
|
||||
assert.position(a.getCursorPosition(), 0, 0);
|
||||
assert.position(a.getSelection().getSelectionAnchor(), 2, 0);
|
||||
assert.position(a.getSelection().getSelectionLead(), 0, 0)
|
||||
}, "test: move line without active selection should move cursor to start of the moved line":function() {
|
||||
var b = new Document("11\n22\n33\n44"), a = new Editor(new MockRenderer, b);
|
||||
a.moveCursorTo(1, 1);
|
||||
a.clearSelection();
|
||||
a.moveLinesDown();
|
||||
assert.equal("11\n33\n22\n44", b.toString());
|
||||
assert.position(a.getCursorPosition(), 2, 0);
|
||||
a.clearSelection();
|
||||
a.moveLinesUp();
|
||||
assert.equal("11\n22\n33\n44", b.toString());
|
||||
assert.position(a.getCursorPosition(), 1, 0)
|
||||
}, "test: copy lines down should select lines and place cursor at the selection start":function() {
|
||||
var b = new Document("11\n22\n33\n44"), a = new Editor(new MockRenderer, b);
|
||||
a.moveCursorTo(1, 1);
|
||||
a.getSelection().selectDown();
|
||||
a.copyLinesDown();
|
||||
assert.equal("11\n22\n33\n22\n33\n44", b.toString());
|
||||
assert.position(a.getCursorPosition(), 3, 0);
|
||||
assert.position(a.getSelection().getSelectionAnchor(), 5, 0);
|
||||
assert.position(a.getSelection().getSelectionLead(), 3, 0)
|
||||
}, "test: copy lines up should select lines and place cursor at the selection start":function() {
|
||||
var b = new Document("11\n22\n33\n44"), a = new Editor(new MockRenderer, b);
|
||||
a.moveCursorTo(1, 1);
|
||||
a.getSelection().selectDown();
|
||||
a.copyLinesUp();
|
||||
assert.equal("11\n22\n33\n22\n33\n44", b.toString());
|
||||
assert.position(a.getCursorPosition(), 1, 0);
|
||||
assert.position(a.getSelection().getSelectionAnchor(), 3, 0);
|
||||
assert.position(a.getSelection().getSelectionLead(), 1, 0)
|
||||
}, "test: input a tab with soft tab should convert it to spaces":function() {
|
||||
var b = new Document(""), a = new Editor(new MockRenderer, b);
|
||||
b.setTabSize(2);
|
||||
b.setUseSoftTabs(true);
|
||||
a.onTextInput("\t");
|
||||
assert.equal(b.toString(), " ");
|
||||
b.setTabSize(5);
|
||||
a.onTextInput("\t");
|
||||
assert.equal(b.toString(), " ")
|
||||
}, "test: input tab without soft tabs should keep the tab character":function() {
|
||||
var b = new Document(""), a = new Editor(new MockRenderer, b);
|
||||
b.setUseSoftTabs(false);
|
||||
a.onTextInput("\t");
|
||||
assert.equal(b.toString(), "\t")
|
||||
}};
|
||||
module.exports = require("async/test").testcase(Test);
|
||||
module === require.main && module.exports.exec();
|
||||
|
|
@ -1,27 +1,28 @@
|
|||
/*
|
||||
LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
*/
|
||||
require.def(["ace/Document", "ace/VirtualRenderer"], function(c, d) {
|
||||
new TestCase("VirtualRendererTest", {"test: screen2text the column should be rounded to the next character edge":function() {
|
||||
var b = document.createElement("div");
|
||||
b.style.left = "0px";
|
||||
b.style.top = "0px";
|
||||
b.style.width = "100px";
|
||||
b.style.height = "100px";
|
||||
document.body.style.margin = "0px";
|
||||
document.body.style.padding = "0px";
|
||||
document.body.appendChild(b);
|
||||
var a = new d(b);
|
||||
a.setDocument(new c("1234"));
|
||||
a.characterWidth = 10;
|
||||
a.lineHeight = 15;
|
||||
assertPosition(0, 0, a.screenToTextCoordinates(0, 0));
|
||||
assertPosition(0, 0, a.screenToTextCoordinates(4, 0));
|
||||
assertPosition(0, 1, a.screenToTextCoordinates(5, 0));
|
||||
assertPosition(0, 1, a.screenToTextCoordinates(9, 0));
|
||||
assertPosition(0, 1, a.screenToTextCoordinates(10, 0));
|
||||
assertPosition(0, 1, a.screenToTextCoordinates(14, 0));
|
||||
assertPosition(0, 2, a.screenToTextCoordinates(15, 0));
|
||||
document.body.removeChild(b)
|
||||
}})
|
||||
});
|
||||
require("../../../support/paths");
|
||||
var Document = "../document", VirtualRenderer = "../virtual_renderer", assert = "../assertions", Test = {"test: screen2text the column should be rounded to the next character edge":function() {
|
||||
var b = document.createElement("div");
|
||||
b.style.left = "0px";
|
||||
b.style.top = "0px";
|
||||
b.style.width = "100px";
|
||||
b.style.height = "100px";
|
||||
document.body.style.margin = "0px";
|
||||
document.body.style.padding = "0px";
|
||||
document.body.appendChild(b);
|
||||
var a = new VirtualRenderer(b);
|
||||
a.setDocument(new Document("1234"));
|
||||
a.characterWidth = 10;
|
||||
a.lineHeight = 15;
|
||||
assert.position(a.screenToTextCoordinates(0, 0), 0, 0);
|
||||
assert.position(a.screenToTextCoordinates(4, 0), 0, 0);
|
||||
assert.position(a.screenToTextCoordinates(5, 0), 0, 1);
|
||||
assert.position(a.screenToTextCoordinates(9, 0), 0, 1);
|
||||
assert.position(a.screenToTextCoordinates(10, 0), 0, 1);
|
||||
assert.position(a.screenToTextCoordinates(14, 0), 0, 1);
|
||||
assert.position(a.screenToTextCoordinates(15, 0), 0, 2);
|
||||
document.body.removeChild(b)
|
||||
}};
|
||||
module.exports = require("async/test").testcase(Test);
|
||||
module === require.main && module.exports.exec();
|
||||
|
|
@ -6,12 +6,12 @@ define(["require", "exports", "module", 'text!ace/css/editor.css!.ace_editor {\n
|
|||
this.container = a;
|
||||
f.addCssClass(this.container, "ace_editor");
|
||||
this.setTheme(b);
|
||||
this.scroller = document.createElement("div");
|
||||
this.scroller.className = "ace_scroller";
|
||||
this.container.appendChild(this.scroller);
|
||||
this.$gutter = document.createElement("div");
|
||||
this.$gutter.className = "ace_gutter";
|
||||
this.container.appendChild(this.$gutter);
|
||||
this.scroller = document.createElement("div");
|
||||
this.scroller.className = "ace_scroller";
|
||||
this.container.appendChild(this.scroller);
|
||||
this.content = document.createElement("div");
|
||||
this.content.style.position = "absolute";
|
||||
this.scroller.appendChild(this.content);
|
||||
|
|
@ -196,7 +196,7 @@ define(["require", "exports", "module", 'text!ace/css/editor.css!.ace_editor {\n
|
|||
this.$updateScrollBar()
|
||||
}else {
|
||||
if(a & this.CHANGE_SCROLL) {
|
||||
a & this.CHANGE_TEXT || a & this.CHANGE_LINES ? this.$textLayer.scrollLines(this.layerConfig) : this.$textLayer.update(this.layerConfig);
|
||||
a & this.CHANGE_TEXT || a & this.CHANGE_LINES ? this.$textLayer.update(this.layerConfig) : this.$textLayer.scrollLines(this.layerConfig);
|
||||
this.showGutter && this.$gutterLayer.update(this.layerConfig);
|
||||
this.$markerLayer.update(this.layerConfig);
|
||||
this.$cursorLayer.update(this.layerConfig);
|
||||
|
|
@ -209,11 +209,6 @@ define(["require", "exports", "module", 'text!ace/css/editor.css!.ace_editor {\n
|
|||
if(a & this.CHANGE_LINES) {
|
||||
this.$updateLines();
|
||||
this.$updateScrollBar()
|
||||
}else {
|
||||
if(a & this.CHANGE_SCROLL) {
|
||||
this.$textLayer.scrollLines(this.layerConfig);
|
||||
this.showGutter && this.$gutterLayer.update(this.layerConfig)
|
||||
}
|
||||
}
|
||||
}a & this.CHANGE_GUTTER && this.showGutter && this.$gutterLayer.update(this.layerConfig);
|
||||
a & this.CHANGE_CURSOR && this.$cursorLayer.update(this.layerConfig);
|
||||
|
|
@ -363,7 +358,7 @@ define(["require", "exports", "module", 'text!ace/css/editor.css!.ace_editor {\n
|
|||
}
|
||||
var c = this;
|
||||
if(!a || typeof a == "string") {
|
||||
a = a || "ace/theme/TextMate";
|
||||
a = a || "ace/theme/textmate";
|
||||
d([a], function(e) {
|
||||
b(e)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -55,3 +55,9 @@ ace/mode/html.js
|
|||
----------------
|
||||
ace/mode/html_highlight_rules.js
|
||||
ace/mode/html.js
|
||||
|
||||
ace/mode/python.js
|
||||
----------------
|
||||
ace/mode/python_highlight_rules.js
|
||||
ace/mode/matching_brace_outdent.js
|
||||
ace/mode/python.js
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@
|
|||
<option value="js">JS Document</option>
|
||||
<option value="html">HTML Document</option>
|
||||
<option value="css">CSS Document</option>
|
||||
<option value="python">Python Document</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
|
|
@ -72,6 +73,7 @@
|
|||
<option value="xml">XML</option>
|
||||
<option value="html">HTML</option>
|
||||
<option value="css">CSS</option>
|
||||
<option value="python">Python</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
|
|
@ -132,10 +134,30 @@
|
|||
</html>
|
||||
</script>
|
||||
|
||||
<script type="text/editor" id="pythontext">#!/usr/local/bin/python
|
||||
|
||||
import string, sys
|
||||
|
||||
# If no arguments were given, print a helpful message
|
||||
if len(sys.argv)==1:
|
||||
print 'Usage: celsius temp1 temp2 ...'
|
||||
sys.exit(0)
|
||||
|
||||
# Loop over the arguments
|
||||
for i in sys.argv[1:]:
|
||||
try:
|
||||
fahrenheit=float(string.atoi(i))
|
||||
except string.atoi_error:
|
||||
print repr(i), "not a numeric value"
|
||||
else:
|
||||
celsius=(fahrenheit-32)*5.0/9.0
|
||||
print '%i\260F = %i\260C' % (int(fahrenheit), int(celsius+.5))
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
|
||||
require(
|
||||
{baseUrl: "../build"},
|
||||
{baseUrl: "../lib"},
|
||||
[
|
||||
"ace/lib/event",
|
||||
"ace/editor",
|
||||
|
|
@ -147,8 +169,9 @@ require(
|
|||
"ace/mode/html",
|
||||
"ace/mode/xml",
|
||||
"ace/mode/text",
|
||||
"ace/mode/python",
|
||||
"ace/undomanager"
|
||||
], function(event, Editor, Renderer, theme, Document, JavaScriptMode, CssMode, HtmlMode, XmlMode, TextMode, UndoManager) {
|
||||
], function(event, Editor, Renderer, theme, Document, JavaScriptMode, CssMode, HtmlMode, XmlMode, TextMode, PythonMode, UndoManager) {
|
||||
|
||||
var docs = {}
|
||||
|
||||
|
|
@ -164,6 +187,10 @@ docs.html = new Document(document.getElementById("htmltext").innerHTML);
|
|||
docs.html.setMode(new HtmlMode());
|
||||
docs.html.setUndoManager(new UndoManager());
|
||||
|
||||
docs.python = new Document(document.getElementById("pythontext").innerHTML);
|
||||
docs.python.setMode(new PythonMode());
|
||||
docs.python.setUndoManager(new UndoManager());
|
||||
|
||||
var docEl = document.getElementById("doc");
|
||||
|
||||
function onDocChange() {
|
||||
|
|
@ -183,6 +210,9 @@ function onDocChange() {
|
|||
else if (mode instanceof XmlMode) {
|
||||
modeEl.value = "xml"
|
||||
}
|
||||
else if (mode instanceof PythonMode) {
|
||||
modeEl.value = "python"
|
||||
}
|
||||
else {
|
||||
modeEl.value = "text"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@
|
|||
<option value="js">JS Document</option>
|
||||
<option value="html">HTML Document</option>
|
||||
<option value="css">CSS Document</option>
|
||||
<option value="python">Python Document</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
|
|
@ -71,6 +72,7 @@
|
|||
<option value="xml">XML</option>
|
||||
<option value="html">HTML</option>
|
||||
<option value="css">CSS</option>
|
||||
<option value="python">Python</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
|
|
@ -131,6 +133,26 @@
|
|||
</html>
|
||||
</script>
|
||||
|
||||
<script type="text/editor" id="pythontext">#!/usr/local/bin/python
|
||||
|
||||
import string, sys
|
||||
|
||||
# If no arguments were given, print a helpful message
|
||||
if len(sys.argv)==1:
|
||||
print 'Usage: celsius temp1 temp2 ...'
|
||||
sys.exit(0)
|
||||
|
||||
# Loop over the arguments
|
||||
for i in sys.argv[1:]:
|
||||
try:
|
||||
fahrenheit=float(string.atoi(i))
|
||||
except string.atoi_error:
|
||||
print repr(i), "not a numeric value"
|
||||
else:
|
||||
celsius=(fahrenheit-32)*5.0/9.0
|
||||
print '%i\260F = %i\260C' % (int(fahrenheit), int(celsius+.5))
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
|
||||
require(
|
||||
|
|
@ -146,8 +168,9 @@ require(
|
|||
"ace/mode/html",
|
||||
"ace/mode/xml",
|
||||
"ace/mode/text",
|
||||
"ace/mode/python",
|
||||
"ace/undomanager"
|
||||
], function(event, Editor, Renderer, theme, Document, JavaScriptMode, CssMode, HtmlMode, XmlMode, TextMode, UndoManager) {
|
||||
], function(event, Editor, Renderer, theme, Document, JavaScriptMode, CssMode, HtmlMode, XmlMode, TextMode, PythonMode, UndoManager) {
|
||||
|
||||
var docs = {}
|
||||
|
||||
|
|
@ -163,6 +186,10 @@ docs.html = new Document(document.getElementById("htmltext").innerHTML);
|
|||
docs.html.setMode(new HtmlMode());
|
||||
docs.html.setUndoManager(new UndoManager());
|
||||
|
||||
docs.python = new Document(document.getElementById("pythontext").innerHTML);
|
||||
docs.python.setMode(new PythonMode());
|
||||
docs.python.setUndoManager(new UndoManager());
|
||||
|
||||
var docEl = document.getElementById("doc");
|
||||
|
||||
function onDocChange() {
|
||||
|
|
@ -182,6 +209,9 @@ function onDocChange() {
|
|||
else if (mode instanceof XmlMode) {
|
||||
modeEl.value = "xml"
|
||||
}
|
||||
else if (mode instanceof PythonMode) {
|
||||
modeEl.value = "python"
|
||||
}
|
||||
else {
|
||||
modeEl.value = "text"
|
||||
}
|
||||
|
|
|
|||
116
lib/ace/mode/python.js
Normal file
116
lib/ace/mode/python.js
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Ajax.org Code Editor (ACE).
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ajax.org Services B.V.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("../lib/oop");
|
||||
var TextMode = require("./text");
|
||||
var Tokenizer = require("../tokenizer");
|
||||
var PythonHighlightRules = require("./python_highlight_rules");
|
||||
var MatchingBraceOutdent = require("./matching_brace_outdent");
|
||||
var Range = require("../range");
|
||||
|
||||
var Python = function() {
|
||||
this.$tokenizer = new Tokenizer(new PythonHighlightRules().getRules());
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
};
|
||||
oop.inherits(Python, TextMode);
|
||||
|
||||
(function() {
|
||||
|
||||
this.toggleCommentLines = function(state, doc, range) {
|
||||
var outdent = true;
|
||||
var outentedRows = [];
|
||||
var re = /^(\s*)#/;
|
||||
|
||||
for (var i=range.start.row; i<= range.end.row; i++) {
|
||||
if (!re.test(doc.getLine(i))) {
|
||||
outdent = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (outdent) {
|
||||
var deleteRange = new Range(0, 0, 0, 0);
|
||||
for (var i=range.start.row; i<= range.end.row; i++)
|
||||
{
|
||||
var line = doc.getLine(i).replace(re, "$1");
|
||||
deleteRange.start.row = i;
|
||||
deleteRange.end.row = i;
|
||||
deleteRange.end.column = line.length + 2;
|
||||
doc.replace(deleteRange, line);
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
else {
|
||||
return doc.indentRows(range, "#");
|
||||
}
|
||||
};
|
||||
|
||||
this.getNextLineIndent = function(state, line, tab) {
|
||||
var indent = this.$getIndent(line);
|
||||
|
||||
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
|
||||
var tokens = tokenizedLine.tokens;
|
||||
var endState = tokenizedLine.state;
|
||||
|
||||
if (tokens.length && tokens[tokens.length-1].type == "comment") {
|
||||
return indent;
|
||||
}
|
||||
|
||||
if (state == "start") {
|
||||
var match = line.match(/^.*[\{\(\[\:]\s*$/);
|
||||
if (match) {
|
||||
indent += tab;
|
||||
}
|
||||
}
|
||||
|
||||
return indent;
|
||||
};
|
||||
|
||||
this.checkOutdent = function(state, line, input) {
|
||||
return this.$outdent.checkOutdent(line, input);
|
||||
};
|
||||
|
||||
this.autoOutdent = function(state, doc, row) {
|
||||
return this.$outdent.autoOutdent(doc, row);
|
||||
};
|
||||
|
||||
}).call(Python.prototype);
|
||||
|
||||
return Python;
|
||||
});
|
||||
176
lib/ace/mode/python_highlight_rules.js
Normal file
176
lib/ace/mode/python_highlight_rules.js
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Ajax.org Code Editor (ACE).
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ajax.org Services B.V.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK *****
|
||||
*
|
||||
* TODO: python delimiters
|
||||
*/
|
||||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("../lib/oop");
|
||||
var lang = require("../lib/lang");
|
||||
var TextHighlightRules = require("./text_highlight_rules");
|
||||
|
||||
PythonHighlightRules = function() {
|
||||
|
||||
var keywords = lang.arrayToMap(
|
||||
("and|as|assert|break|class|continue|def|del|elif|else|except|exec|" +
|
||||
"finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|" +
|
||||
"raise|return|try|while|with|yield").split("|")
|
||||
);
|
||||
|
||||
var builtinConstants = lang.arrayToMap(
|
||||
("True|False|None|NotImplemented|Ellipsis|__debug__").split("|")
|
||||
);
|
||||
|
||||
var builtinFunctions = lang.arrayToMap(
|
||||
("abs|divmod|input|open|staticmethod|all|enumerate|int|ord|str|any|" +
|
||||
"eval|isinstance|pow|sum|basestring|execfile|issubclass|print|super|" +
|
||||
"binfile|iter|property|tuple|bool|filter|len|range|type|bytearray|" +
|
||||
"float|list|raw_input|unichr|callable|format|locals|reduce|unicode|" +
|
||||
"chr|frozenset|long|reload|vars|classmethod|getattr|map|repr|xrange|" +
|
||||
"cmp|globals|max|reversed|zip|compile|hasattr|memoryview|round|" +
|
||||
"__import__|complex|hash|min|set|apply|delattr|help|next|setattr|" +
|
||||
"buffer|dict|hex|object|slice|coerce|dir|id|oct|sorted|intern").split("|")
|
||||
);
|
||||
|
||||
var futureReserved = lang.arrayToMap(
|
||||
("").split("|")
|
||||
);
|
||||
|
||||
var strPre = "(?:(?:[rubRUB])|(?:[ubUB][rR]))?";
|
||||
|
||||
var decimalInteger = "(?:(?:[1-9]\\d*)|(?:0))";
|
||||
var octInteger = "(?:0[oO]?[0-7]+)";
|
||||
var hexInteger = "(?:0[xX][\\dA-Fa-f]+)";
|
||||
var binInteger = "(?:0[bB][01]+)";
|
||||
var integer = "(?:" + decimalInteger + "|" + octInteger + "|" + hexInteger + "|" + binInteger + ")";
|
||||
|
||||
var exponent = "(?:[eE][+-]?\\d+)";
|
||||
var fraction = "(?:\\.\\d+)";
|
||||
var intPart = "(?:\\d+)";
|
||||
var pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))";
|
||||
var exponentFloat = "(?:(?:" + pointFloat + "|" + intPart + ")" + exponent + ")";
|
||||
var floatNumber = "(?:" + exponentFloat + "|" + pointFloat + ")";
|
||||
|
||||
this.$rules = {
|
||||
"start" : [ {
|
||||
token : "comment",
|
||||
regex : "#.*$"
|
||||
}, {
|
||||
token : "string", // """ string
|
||||
regex : strPre + '"{3}(?:(?:.)|(?:^"{3}))*?"{3}'
|
||||
}, {
|
||||
token : "string", // multi line """ string start
|
||||
regex : strPre + '"{3}.*$',
|
||||
next : "qqstring"
|
||||
}, {
|
||||
token : "string", // " string
|
||||
regex : strPre + '"(?:(?:\\\\.)|(?:[^"\\\\]))*?"'
|
||||
}, {
|
||||
token : "string", // ''' string
|
||||
regex : strPre + "'{3}(?:(?:.)|(?:^'{3}))*?'{3}"
|
||||
}, {
|
||||
token : "string", // multi line ''' string start
|
||||
regex : strPre + "'{3}.*$",
|
||||
next : "qstring"
|
||||
}, {
|
||||
token : "string", // ' string
|
||||
regex : strPre + "'(?:(?:\\\\.)|(?:[^'\\\\]))*?'"
|
||||
}, {
|
||||
token : "constant.numeric", // imaginary
|
||||
regex : "(?:" + floatNumber + "|\\d+)[jJ]\\b"
|
||||
}, {
|
||||
token : "constant.numeric", // float
|
||||
regex : floatNumber
|
||||
}, {
|
||||
token : "constant.numeric", // long integer
|
||||
regex : integer + "[lL]\\b"
|
||||
}, {
|
||||
token : "constant.numeric", // integer
|
||||
regex : integer + "\\b"
|
||||
}, {
|
||||
token : function(value) {
|
||||
if (keywords[value])
|
||||
return "keyword";
|
||||
else if (builtinConstants[value])
|
||||
return "constant.language";
|
||||
else if (futureReserved[value])
|
||||
return "invalid.illegal";
|
||||
else if (builtinFunctions[value])
|
||||
return "support.function";
|
||||
else if (value == "debugger")
|
||||
return "invalid.deprecated";
|
||||
else
|
||||
return "identifier";
|
||||
},
|
||||
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
|
||||
}, {
|
||||
token : "keyword.operator",
|
||||
regex : "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|%|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|="
|
||||
}, {
|
||||
token : "lparen",
|
||||
regex : "[\\[\\(\\{]"
|
||||
}, {
|
||||
token : "rparen",
|
||||
regex : "[\\]\\)\\}]"
|
||||
}, {
|
||||
token : "text",
|
||||
regex : "\\s+"
|
||||
} ],
|
||||
"qqstring" : [ {
|
||||
token : "string", // multi line """ string end
|
||||
regex : '(?:^"{3})*?"{3}',
|
||||
next : "start"
|
||||
}, {
|
||||
token : "string",
|
||||
regex : '.+'
|
||||
} ],
|
||||
"qstring" : [ {
|
||||
token : "string", // multi line ''' string end
|
||||
regex : "(?:^'{3})*?'{3}",
|
||||
next : "start"
|
||||
}, {
|
||||
token : "string",
|
||||
regex : '.+'
|
||||
} ]
|
||||
};
|
||||
};
|
||||
|
||||
oop.inherits(PythonHighlightRules, TextHighlightRules);
|
||||
|
||||
return PythonHighlightRules;
|
||||
});
|
||||
|
|
@ -399,7 +399,7 @@ var VirtualRenderer = function(container, theme) {
|
|||
|
||||
var lineCount = Math.ceil(minHeight / this.lineHeight);
|
||||
var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
|
||||
var lastRow = Math.min(this.lines.length, firstRow + lineCount) - 1;
|
||||
var lastRow = Math.max(0, Math.min(this.lines.length, firstRow + lineCount) - 1);
|
||||
|
||||
var layerConfig = this.layerConfig = {
|
||||
width : longestLine,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue