Merge branch 'master' of https://github.com/ajaxorg/ace
Conflicts: plugins/cockpit/cli.js plugins/cockpit/lib/ui/plain.js plugins/cockpit/ui/plain.css plugins/cockpit/ui/plain.js plugins/pilot/canon.js plugins/pilot/lib/commands/history.js
This commit is contained in:
commit
0f505962d0
126 changed files with 3375 additions and 3518 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
|
||||
|
|
|
|||
|
|
@ -96,7 +96,8 @@ var setupPlugins = function(config, callback) {
|
|||
for (i = 0; i < packages.length; i++) {
|
||||
location.push({
|
||||
name: packages[i],
|
||||
main: "index"
|
||||
main: "index",
|
||||
lib: "."
|
||||
});
|
||||
knownPlugins.push(packages[i]);
|
||||
}
|
||||
|
|
@ -113,7 +114,7 @@ var setupPlugins = function(config, callback) {
|
|||
packagePaths: pluginPackageInfo,
|
||||
paths: paths
|
||||
});
|
||||
require(["pilot/plugin_manager", "pilot/settings"], function() {
|
||||
require(["pilot/fixoldbrowsers", "pilot/plugin_manager", "pilot/settings"], function() {
|
||||
var pluginsModule = require("pilot/plugin_manager");
|
||||
var settings = require("pilot/settings").settings;
|
||||
var catalog = pluginsModule.catalog;
|
||||
|
|
|
|||
|
|
@ -41,16 +41,17 @@ define(function(require, exports, module) {
|
|||
|
||||
exports.launch = function(env) {
|
||||
|
||||
var event = require("pilot/event").event;
|
||||
var event = require("pilot/event");
|
||||
var Editor = require("ace/editor").Editor;
|
||||
var Renderer = require("ace/virtual_renderer").VirtualRenderer;
|
||||
var theme = require("ace/theme/textmate");
|
||||
var Document = require("ace/document").Document;
|
||||
var JavaScriptMode = require("ace/mode/javascript").JavaScript;
|
||||
var CssMode = require("ace/mode/css").Css;
|
||||
var HtmlMode = require("ace/mode/html").Html;
|
||||
var XmlMode = require("ace/mode/xml").Xml;
|
||||
var TextMode = require("ace/mode/text").Text;
|
||||
var JavaScriptMode = require("ace/mode/javascript").Mode;
|
||||
var CssMode = require("ace/mode/css").Mode;
|
||||
var HtmlMode = require("ace/mode/html").Mode;
|
||||
var XmlMode = require("ace/mode/xml").Mode;
|
||||
var PythonMode = require("ace/mode/python").Mode;
|
||||
var TextMode = require("ace/mode/text").Mode;
|
||||
var UndoManager = require("ace/undomanager").UndoManager;
|
||||
|
||||
var docs = {};
|
||||
|
|
@ -67,6 +68,10 @@ exports.launch = function(env) {
|
|||
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");
|
||||
|
||||
var container = document.getElementById("editor");
|
||||
|
|
@ -89,6 +94,9 @@ exports.launch = function(env) {
|
|||
else if (mode instanceof XmlMode) {
|
||||
modeEl.value = "xml";
|
||||
}
|
||||
else if (mode instanceof PythonMode) {
|
||||
modeEl.value = "python";
|
||||
}
|
||||
else {
|
||||
modeEl.value = "text";
|
||||
}
|
||||
|
|
@ -111,7 +119,8 @@ exports.launch = function(env) {
|
|||
xml: new XmlMode(),
|
||||
html: new HtmlMode(),
|
||||
css: new CssMode(),
|
||||
javascript: new JavaScriptMode()
|
||||
javascript: new JavaScriptMode(),
|
||||
python: new PythonMode()
|
||||
};
|
||||
|
||||
function getMode() {
|
||||
|
|
@ -182,6 +191,8 @@ exports.launch = function(env) {
|
|||
mode = "html";
|
||||
} else if (/^.*\.css$/i.test(file.name)) {
|
||||
mode = "css";
|
||||
} else if (/^.*\.py$/i.test(file.name)) {
|
||||
mode = "python";
|
||||
}
|
||||
|
||||
env.editor.onTextInput(reader.result);
|
||||
|
|
|
|||
|
|
@ -1,322 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Editor</title>
|
||||
<meta name="author" content="Fabian Jakobs">
|
||||
|
||||
<style type="text/css" media="screen">
|
||||
|
||||
html {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
body {
|
||||
overflow: hidden;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font: sans-serif;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
font-family: Arial, Helvetica, sans-serif, Tahoma, Verdana;
|
||||
font-size: 12px;
|
||||
background: rgb(14, 98, 165);
|
||||
color: white;
|
||||
}
|
||||
|
||||
#editor {
|
||||
top: 55px;
|
||||
left: 0px;
|
||||
background: white;
|
||||
}
|
||||
|
||||
#controls {
|
||||
width: 100%;
|
||||
height: 55px;
|
||||
}
|
||||
|
||||
#jump {
|
||||
position: absolute;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border: 1px solid red;
|
||||
z-index: 10000;
|
||||
display: none;
|
||||
}
|
||||
|
||||
</style>
|
||||
<script src="require.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="../build/ace/editor.js" type="text/javascript" charset="utf-8"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="jump"></div>
|
||||
|
||||
<table id="controls">
|
||||
<tr>
|
||||
<td>
|
||||
<label for="doc">Document:</label>
|
||||
<select id="doc" size="1">
|
||||
<option value="js">JS Document</option>
|
||||
<option value="html">HTML Document</option>
|
||||
<option value="css">CSS Document</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<label for="mode">Mode:</label>
|
||||
<select id="mode" size="1">
|
||||
<option value="text">Plain Text</option>
|
||||
<option value="javascript">JavaScript</option>
|
||||
<option value="xml">XML</option>
|
||||
<option value="html">HTML</option>
|
||||
<option value="css">CSS</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<label for="theme">Theme:</label>
|
||||
<select id="theme" size="1">
|
||||
<option value="ace/theme/textmate">TextMate</option>
|
||||
<option value="ace/theme/eclipse">Eclipse</option>
|
||||
<option value="ace/theme/dawn">Dawn</option>
|
||||
<option value="ace/theme/idle_fingers">idleFingers</option>
|
||||
<option value="ace/theme/twilight">Twilight</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<label for="select_style">Full line selections</label>
|
||||
<input type="checkbox" name="select_style" id="select_style" checked>
|
||||
</td>
|
||||
<td>
|
||||
<label for="highlight_active">Highlight active line</label>
|
||||
<input type="checkbox" name="highlight_active" id="highlight_active" checked>
|
||||
</td>
|
||||
<td align="right">
|
||||
<img src="logo.png">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div id="editor">
|
||||
</div>
|
||||
|
||||
<script type="text/editor" id="jstext">function foo(items) {
|
||||
for (var i=0; i<items.length; i++) {
|
||||
alert(items[i] + "juhu");
|
||||
}
|
||||
}</script>
|
||||
|
||||
<script type="text/editor" id="csstext">.text-layer {
|
||||
font-family: Monaco, "Courier New", monospace;
|
||||
font-size: 12px;
|
||||
cursor: text;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="text/editor" id="htmltext"><html>
|
||||
<head>
|
||||
|
||||
<style type="text/css">
|
||||
.text-layer {
|
||||
font-family: Monaco, "Courier New", monospace;
|
||||
font-size: 12px;
|
||||
cursor: text;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="color:red">Juhu Kinners</h1>
|
||||
</body>
|
||||
</html>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
|
||||
require(
|
||||
{ baseUrl: "../build" },
|
||||
[
|
||||
"pilot/event",
|
||||
"ace/editor",
|
||||
"ace/virtual_renderer",
|
||||
"ace/theme/textmate",
|
||||
"ace/document",
|
||||
"ace/mode/javascript",
|
||||
"ace/mode/css",
|
||||
"ace/mode/html",
|
||||
"ace/mode/xml",
|
||||
"ace/mode/text",
|
||||
"ace/undomanager"
|
||||
], function(
|
||||
eventMod,
|
||||
editorMod,
|
||||
renderMod,
|
||||
theme,
|
||||
docMod,
|
||||
jsMod,
|
||||
cssMod,
|
||||
htmlMod,
|
||||
xmlMod,
|
||||
textMod,
|
||||
undoMod
|
||||
) {
|
||||
|
||||
var event = eventMod.event;
|
||||
var Editor = editorMod.Editor;
|
||||
var Renderer = renderMod.VirtualRenderer;
|
||||
var Document = docMod.Document;
|
||||
var JavaScriptMode = jsMod.JavaScript;
|
||||
var CssMode = cssMod.Css;
|
||||
var HtmlMode = htmlMod.Html;
|
||||
var XmlMode = xmlMod.Xml;
|
||||
var TextMode = textMod.Text;
|
||||
var UndoManager = undoMod.UndoManager;
|
||||
|
||||
var docs = {}
|
||||
|
||||
docs.js = new Document(document.getElementById("jstext").innerHTML);
|
||||
docs.js.setMode(new JavaScriptMode());
|
||||
docs.js.setUndoManager(new UndoManager());
|
||||
|
||||
docs.css = new Document(document.getElementById("csstext").innerHTML);
|
||||
docs.css.setMode(new CssMode());
|
||||
docs.css.setUndoManager(new UndoManager());
|
||||
|
||||
docs.html = new Document(document.getElementById("htmltext").innerHTML);
|
||||
docs.html.setMode(new HtmlMode());
|
||||
docs.html.setUndoManager(new UndoManager());
|
||||
|
||||
var docEl = document.getElementById("doc");
|
||||
|
||||
function onDocChange() {
|
||||
var doc = getDoc();
|
||||
editor.setDocument(doc);
|
||||
|
||||
var mode = doc.getMode();
|
||||
if (mode instanceof JavaScriptMode) {
|
||||
modeEl.value = "javascript"
|
||||
}
|
||||
else if (mode instanceof CssMode) {
|
||||
modeEl.value = "css"
|
||||
}
|
||||
else if (mode instanceof HtmlMode) {
|
||||
modeEl.value = "html"
|
||||
}
|
||||
else if (mode instanceof XmlMode) {
|
||||
modeEl.value = "xml"
|
||||
}
|
||||
else {
|
||||
modeEl.value = "text"
|
||||
}
|
||||
|
||||
editor.focus();
|
||||
}
|
||||
docEl.onchange = onDocChange;
|
||||
|
||||
function getDoc() {
|
||||
return docs[docEl.value];
|
||||
}
|
||||
|
||||
var modeEl = document.getElementById("mode");
|
||||
modeEl.onchange = function() {
|
||||
editor.getDocument().setMode(modes[modeEl.value] || modes.text);
|
||||
};
|
||||
|
||||
var modes = {
|
||||
text: new TextMode(),
|
||||
xml: new XmlMode(),
|
||||
html: new HtmlMode(),
|
||||
css: new CssMode(),
|
||||
javascript: new JavaScriptMode()
|
||||
};
|
||||
|
||||
function getMode() {
|
||||
return modes[modeEl.value];
|
||||
}
|
||||
|
||||
var themeEl = document.getElementById("theme");
|
||||
themeEl.onchange = function() {
|
||||
editor.setTheme(themeEl.value);
|
||||
};
|
||||
|
||||
var selectEl = document.getElementById("select_style");
|
||||
selectEl.onchange = function() {
|
||||
if (selectEl.checked) {
|
||||
editor.setSelectionStyle("line");
|
||||
} else {
|
||||
editor.setSelectionStyle("text");
|
||||
}
|
||||
};
|
||||
|
||||
var activeEl = document.getElementById("highlight_active");
|
||||
activeEl.onchange = function() {
|
||||
editor.setHighlightActiveLine(!!activeEl.checked);
|
||||
};
|
||||
|
||||
var container = document.getElementById("editor");
|
||||
var editor = new Editor(new Renderer(container, theme));
|
||||
onDocChange();
|
||||
|
||||
window.jump = function() {
|
||||
var jump = document.getElementById("jump")
|
||||
var cursor = editor.getCursorPosition()
|
||||
var pos = editor.renderer.textToScreenCoordinates(cursor.row, cursor.column);
|
||||
jump.style.left = pos.pageX + "px";
|
||||
jump.style.top = pos.pageY + "px";
|
||||
jump.style.display = "block";
|
||||
}
|
||||
|
||||
function onResize() {
|
||||
container.style.width = (document.documentElement.clientWidth - 4) + "px";
|
||||
container.style.height = (document.documentElement.clientHeight - 55 - 4) + "px";
|
||||
editor.resize();
|
||||
};
|
||||
|
||||
window.onresize = onResize;
|
||||
onResize();
|
||||
|
||||
event.addListener(container, "dragover", function(e) {
|
||||
return event.preventDefault(e);
|
||||
});
|
||||
|
||||
event.addListener(container, "drop", function(e) {
|
||||
try {
|
||||
var file = e.dataTransfer.files[0];
|
||||
} catch(e) {
|
||||
return event.stopEvent();
|
||||
}
|
||||
|
||||
if (window.FileReader) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
editor.getSelection().selectAll();
|
||||
|
||||
var mode = "text";
|
||||
if (/^.*\.js$/i.test(file.name)) {
|
||||
mode = "javascript";
|
||||
} else if (/^.*\.xml$/i.test(file.name)) {
|
||||
mode = "xml";
|
||||
} else if (/^.*\.html$/i.test(file.name)) {
|
||||
mode = "html";
|
||||
} else if (/^.*\.css$/i.test(file.name)) {
|
||||
mode = "css";
|
||||
}
|
||||
|
||||
editor.onTextInput(reader.result);
|
||||
|
||||
modeEl.value = mode;
|
||||
editor.getDocument().setMode(modes[mode]);
|
||||
}
|
||||
reader.readAsText(file);
|
||||
}
|
||||
|
||||
return event.preventDefault(e);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
79
editor.html
79
editor.html
|
|
@ -18,10 +18,9 @@
|
|||
overflow: hidden;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font: sans-serif;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
font-family: Arial, Helvetica, sans-serif, Tahoma, Verdana;
|
||||
font-family: Arial, Helvetica, sans-serif, Tahoma, Verdana, sans-serif;
|
||||
font-size: 12px;
|
||||
background: rgb(14, 98, 165);
|
||||
color: white;
|
||||
|
|
@ -53,28 +52,6 @@
|
|||
bottom: 0;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
require = {
|
||||
//urlArgs: "bust=" + (new Date()).getTime()
|
||||
};
|
||||
</script>
|
||||
<script src="demo/require.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="demo/boot.js" type="text/javascript"></script>
|
||||
<script>
|
||||
setupPlugins({
|
||||
pluginDirs: {
|
||||
"../demo": {
|
||||
singleFiles: ["demo_startup"]
|
||||
}
|
||||
}
|
||||
}, function(plugin_manager, settings) {
|
||||
var data = { env: { settings: settings } };
|
||||
plugin_manager.catalog.startupPlugins(data, plugin_manager.REASONS.APP_STARTUP).then(function() {
|
||||
var demo_startup = require("demo_startup");
|
||||
demo_startup.launch(data.env);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="jump"></div>
|
||||
|
|
@ -87,6 +64,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>
|
||||
|
|
@ -97,6 +75,7 @@
|
|||
<option value="xml">XML</option>
|
||||
<option value="html">HTML</option>
|
||||
<option value="css">CSS</option>
|
||||
<option value="python">Python</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
|
|
@ -136,8 +115,7 @@
|
|||
font-family: Monaco, "Courier New", monospace;
|
||||
font-size: 12px;
|
||||
cursor: text;
|
||||
}
|
||||
</script>
|
||||
}</script>
|
||||
|
||||
<script type="text/editor" id="htmltext"><html>
|
||||
<head>
|
||||
|
|
@ -154,10 +132,53 @@
|
|||
<body>
|
||||
<h1 style="color:red">Juhu Kinners</h1>
|
||||
</body>
|
||||
</html>
|
||||
</script>
|
||||
</html></script>
|
||||
|
||||
<input id=cockpit type=text/>
|
||||
<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>
|
||||
|
||||
<input id="cockpit" type="text"/>
|
||||
|
||||
|
||||
<script>
|
||||
require = {
|
||||
//urlArgs: "bust=" + (new Date()).getTime()
|
||||
};
|
||||
</script>
|
||||
<script src="demo/require.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="demo/boot.js" type="text/javascript"></script>
|
||||
<script>
|
||||
setupPlugins({
|
||||
pluginDirs: {
|
||||
"../demo": {
|
||||
singleFiles: ["demo_startup"]
|
||||
}
|
||||
}
|
||||
}, function(plugin_manager, settings) {
|
||||
var data = { env: { settings: settings } };
|
||||
plugin_manager.catalog.startupPlugins(data, plugin_manager.REASONS.APP_STARTUP).then(function() {
|
||||
var demo_startup = require("demo_startup");
|
||||
demo_startup.launch(data.env);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -62,7 +62,7 @@
|
|||
<br/>
|
||||
<br/> </p>
|
||||
<h2>Demo</h2>
|
||||
Check out the <a href="demo/editor-build.html">demo</a>.
|
||||
Check out the <a href="editor.html">demo</a>.
|
||||
<h2>Contact</h2>
|
||||
<p>Fabian Jakobs (fabian.jakobs@web.de)
|
||||
<br/> </p>
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var oop = require("pilot/oop");
|
||||
var EventEmitter = require("pilot/event_emitter").EventEmitter;
|
||||
|
||||
var BackgroundTokenizer = function(tokenizer, editor) {
|
||||
|
|
|
|||
|
|
@ -37,11 +37,11 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var lang = require("pilot/lang").lang;
|
||||
var oop = require("pilot/oop");
|
||||
var lang = require("pilot/lang");
|
||||
var EventEmitter = require("pilot/event_emitter").EventEmitter;
|
||||
var Selection = require("ace/selection").Selection;
|
||||
var TextMode = require("ace/mode/text").Text;
|
||||
var TextMode = require("ace/mode/text").Mode;
|
||||
var Range = require("ace/range").Range;
|
||||
|
||||
var Document = function(text, mode) {
|
||||
|
|
@ -56,7 +56,7 @@ var Document = function(text, mode) {
|
|||
this.setMode(mode);
|
||||
}
|
||||
|
||||
if (lang.isArray(text)) {
|
||||
if (Array.isArray(text)) {
|
||||
this.$insertLines(0, text);
|
||||
} else {
|
||||
this.$insert({row: 0, column: 0}, text);
|
||||
|
|
@ -622,20 +622,21 @@ var Document = function(text, mode) {
|
|||
return end;
|
||||
};
|
||||
|
||||
this.indentRows = function(range, indentString) {
|
||||
indentString.replace("\t", this.getTabString());
|
||||
for (var row=range.start.row; row<=range.end.row; row++) {
|
||||
this.indentRows = function(startRow, endRow, indentString) {
|
||||
indentString = indentString.replace("\t", this.getTabString());
|
||||
for (var row=startRow; row<=endRow; row++) {
|
||||
this.$insert({row: row, column:0}, indentString);
|
||||
}
|
||||
this.fireChangeEvent(range.start.row, range.end.row);
|
||||
this.fireChangeEvent(startRow, endRow);
|
||||
return indentString.length;
|
||||
};
|
||||
|
||||
this.outdentRows = function (range) {
|
||||
var deleteRange = new Range(0, 0, 0, 0),
|
||||
size = this.getTabSize();
|
||||
var rowRange = range.collapseRows();
|
||||
var deleteRange = new Range(0, 0, 0, 0);
|
||||
var size = this.getTabSize();
|
||||
|
||||
for (var i = range.start.row; i <= range.end.row; ++i) {
|
||||
for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) {
|
||||
var line = this.getLine(i);
|
||||
|
||||
deleteRange.start.row = i;
|
||||
|
|
@ -647,9 +648,9 @@ var Document = function(text, mode) {
|
|||
deleteRange.start.column = j;
|
||||
deleteRange.end.column = j + 1;
|
||||
} else {
|
||||
deleteRange.start.column = 0;
|
||||
deleteRange.end.column = j;
|
||||
}
|
||||
deleteRange.start.column = 0;
|
||||
deleteRange.end.column = j;
|
||||
}
|
||||
if (i == range.start.row)
|
||||
range.start.column -= deleteRange.end.column - deleteRange.start.column;
|
||||
if (i == range.end.row)
|
||||
|
|
@ -664,7 +665,7 @@ var Document = function(text, mode) {
|
|||
if (firstRow <= 0) return 0;
|
||||
|
||||
var removed = this.lines.slice(firstRow, lastRow + 1);
|
||||
this.$remove(new Range(firstRow, 0, lastRow + 1, 0));
|
||||
this.$remove(new Range(firstRow-1, this.lines[firstRow-1].length, lastRow, this.lines[lastRow].length));
|
||||
this.$insertLines(firstRow - 1, removed);
|
||||
|
||||
this.fireChangeEvent(firstRow - 1, lastRow);
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var event = require("pilot/event").event;
|
||||
var lang = require("pilot/lang").lang;
|
||||
var oop = require("pilot/oop");
|
||||
var event = require("pilot/event");
|
||||
var lang = require("pilot/lang");
|
||||
var TextInput = require("ace/textinput").TextInput;
|
||||
var KeyBinding = require("ace/keybinding").KeyBinding;
|
||||
var Document = require("ace/document").Document;
|
||||
|
|
@ -65,10 +65,10 @@ var Editor =function(renderer, doc) {
|
|||
});
|
||||
|
||||
var mouseTarget = renderer.getMouseEventTarget();
|
||||
event.addListener(mouseTarget, "mousedown", lang.bind(this.onMouseDown, this));
|
||||
event.addMultiMouseDownListener(mouseTarget, 0, 2, 500, lang.bind(this.onMouseDoubleClick, this));
|
||||
event.addMultiMouseDownListener(mouseTarget, 0, 3, 600, lang.bind(this.onMouseTripleClick, this));
|
||||
event.addMouseWheelListener(mouseTarget, lang.bind(this.onMouseWheel, this));
|
||||
event.addListener(mouseTarget, "mousedown", this.onMouseDown.bind(this));
|
||||
event.addMultiMouseDownListener(mouseTarget, 0, 2, 500, this.onMouseDoubleClick.bind(this));
|
||||
event.addMultiMouseDownListener(mouseTarget, 0, 3, 600, this.onMouseTripleClick.bind(this));
|
||||
event.addMouseWheelListener(mouseTarget, this.onMouseWheel.bind(this));
|
||||
|
||||
this.$selectionMarker = null;
|
||||
this.$highlightLineMarker = null;
|
||||
|
|
@ -128,26 +128,26 @@ var Editor =function(renderer, doc) {
|
|||
|
||||
this.doc = doc;
|
||||
|
||||
this.$onDocumentChange = lang.bind(this.onDocumentChange, this);
|
||||
this.$onDocumentChange = this.onDocumentChange.bind(this);
|
||||
doc.addEventListener("change", this.$onDocumentChange);
|
||||
this.renderer.setDocument(doc);
|
||||
|
||||
this.$onDocumentModeChange = lang.bind(this.onDocumentModeChange, this);
|
||||
this.$onDocumentModeChange = this.onDocumentModeChange.bind(this);
|
||||
doc.addEventListener("changeMode", this.$onDocumentModeChange);
|
||||
|
||||
this.$onDocumentChangeTabSize = lang.bind(this.renderer.updateText, this.renderer);
|
||||
this.$onDocumentChangeTabSize = this.renderer.updateText.bind(this.renderer);
|
||||
doc.addEventListener("changeTabSize", this.$onDocumentChangeTabSize);
|
||||
|
||||
this.$onDocumentChangeBreakpoint = lang.bind(this.onDocumentChangeBreakpoint, this);
|
||||
this.$onDocumentChangeBreakpoint = this.onDocumentChangeBreakpoint.bind(this);
|
||||
this.doc.addEventListener("changeBreakpoint", this.$onDocumentChangeBreakpoint);
|
||||
|
||||
this.selection = doc.getSelection();
|
||||
this.$desiredColumn = 0;
|
||||
|
||||
this.$onCursorChange = lang.bind(this.onCursorChange, this);
|
||||
this.$onCursorChange = this.onCursorChange.bind(this);
|
||||
this.selection.addEventListener("changeCursor", this.$onCursorChange);
|
||||
|
||||
this.$onSelectionChange = lang.bind(this.onSelectionChange, this);
|
||||
this.$onSelectionChange = this.onSelectionChange.bind(this);
|
||||
this.selection.addEventListener("changeSelection", this.$onSelectionChange);
|
||||
|
||||
this.onDocumentModeChange();
|
||||
|
|
@ -284,7 +284,7 @@ var Editor =function(renderer, doc) {
|
|||
var tokenizer = mode.getTokenizer();
|
||||
|
||||
if (!this.bgTokenizer) {
|
||||
var onUpdate = lang.bind(this.onTokenizerUpdate, this);
|
||||
var onUpdate = this.onTokenizerUpdate.bind(this);
|
||||
this.bgTokenizer = new BackgroundTokenizer(tokenizer, this);
|
||||
this.bgTokenizer.addEventListener("update", onUpdate);
|
||||
} else {
|
||||
|
|
@ -469,9 +469,7 @@ var Editor =function(renderer, doc) {
|
|||
outdent -= 1;
|
||||
_self.doc.replace(new Range(row, 0, row, line.length), line.substr(i));
|
||||
}
|
||||
end.column += _self.doc.indentRows(
|
||||
new Range(cursor.row + 1, 0, end.row, end.column),
|
||||
lineIndent);
|
||||
end.column += _self.doc.indentRows(cursor.row + 1, end.row, lineIndent);
|
||||
} else {
|
||||
if (shouldOutdent) {
|
||||
end.column += _self.mode.autoOutdent(lineState, _self.doc, cursor.row);
|
||||
|
|
@ -606,9 +604,9 @@ var Editor =function(renderer, doc) {
|
|||
var doc = this.doc,
|
||||
range = this.getSelectionRange();
|
||||
|
||||
if (range.start.row < range.end.row ||
|
||||
range.start.column < range.end.column) {
|
||||
var count = doc.indentRows(this.getSelectionRange(), "\t");
|
||||
if (range.start.row < range.end.row || range.start.column < range.end.column) {
|
||||
var rows = this.$getSelectedRows();
|
||||
var count = doc.indentRows(rows.first, rows.last, "\t");
|
||||
|
||||
this.selection.shiftSelection(count);
|
||||
} else {
|
||||
|
|
@ -631,8 +629,8 @@ var Editor =function(renderer, doc) {
|
|||
if (this.$readOnly)
|
||||
return;
|
||||
|
||||
var selection = this.doc.getSelection(),
|
||||
range = this.doc.outdentRows(selection.getRange());
|
||||
var selection = this.doc.getSelection();
|
||||
var range = this.doc.outdentRows(selection.getRange());
|
||||
|
||||
selection.setSelectionRange(range, selection.isBackwards());
|
||||
this.$updateDesiredColumn();
|
||||
|
|
@ -642,12 +640,10 @@ var Editor =function(renderer, doc) {
|
|||
if (this.$readOnly)
|
||||
return;
|
||||
|
||||
var rows = this.$getSelectedRows();
|
||||
|
||||
var range = new Range(rows.first, 0, rows.last, 0);
|
||||
var _self = this;
|
||||
this.bgTokenizer.getState(this.getCursorPosition().row, function(state) {
|
||||
var addedColumns = _self.mode.toggleCommentLines(state, _self.doc, range);
|
||||
var rows = _self.$getSelectedRows()
|
||||
var addedColumns = _self.mode.toggleCommentLines(state, _self.doc, rows.first, rows.last);
|
||||
_self.selection.shiftSelection(addedColumns);
|
||||
});
|
||||
};
|
||||
|
|
@ -715,16 +711,11 @@ var Editor =function(renderer, doc) {
|
|||
};
|
||||
|
||||
this.$getSelectedRows = function() {
|
||||
var range = this.getSelectionRange();
|
||||
var firstRow = range.start.row;
|
||||
var lastRow = range.end.row;
|
||||
if (range.end.column == 0 && (range.start.row !== range.end.row)) {
|
||||
lastRow -= 1;
|
||||
}
|
||||
var range = this.getSelectionRange().collapseRows();
|
||||
|
||||
return {
|
||||
first: firstRow,
|
||||
last: lastRow
|
||||
first: range.start.row,
|
||||
last: range.end.row
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var core = require("pilot/core").core;
|
||||
var event = require("pilot/event").event;
|
||||
var core = require("pilot/core");
|
||||
var event = require("pilot/event");
|
||||
var default_mac = require("ace/conf/keybindings/default_mac").bindings;
|
||||
var default_win = require("ace/conf/keybindings/default_win").bindings;
|
||||
var canon = require("pilot/canon");
|
||||
|
|
@ -49,14 +49,20 @@ var KeyBinding = function(element, editor, config) {
|
|||
|
||||
var _self = this;
|
||||
event.addKeyListener(element, function(e) {
|
||||
var hashId = 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0)
|
||||
| (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
|
||||
// opera on mac swaps ctrl and meta keys
|
||||
if (core.isOpera && core.isMac)
|
||||
var hashId = 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0)
|
||||
| (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0);
|
||||
else
|
||||
var hashId = 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0)
|
||||
| (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0);
|
||||
|
||||
var key = _self.keyNames[e.keyCode];
|
||||
|
||||
var commandName = (_self.config.reverse[hashId] || {})[(key
|
||||
|| String.fromCharCode(e.keyCode)).toLowerCase()];
|
||||
|
||||
var success = canon.exec(commandName);
|
||||
var success = canon.exec(commandName, {editor: editor});
|
||||
if (success) {
|
||||
return event.stopEvent(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var dom = require("pilot/dom").dom;
|
||||
var dom = require("pilot/dom");
|
||||
|
||||
var Cursor = function(parentEl) {
|
||||
this.element = document.createElement("div");
|
||||
|
|
|
|||
|
|
@ -37,8 +37,9 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var dom = require("pilot/dom").dom;
|
||||
var oop = require("pilot/oop");
|
||||
var dom = require("pilot/dom");
|
||||
var lang = require("pilot/lang");
|
||||
var EventEmitter = require("pilot/event_emitter").EventEmitter;
|
||||
|
||||
var Text = function(parentEl) {
|
||||
|
|
@ -91,32 +92,36 @@ var Text = function(parentEl) {
|
|||
},
|
||||
|
||||
this.$measureSizes = function() {
|
||||
var measureNode = document.createElement("div");
|
||||
var style = measureNode.style;
|
||||
|
||||
style.width = style.height = "auto";
|
||||
style.left = style.top = "-1000px";
|
||||
style.visibility = "hidden";
|
||||
style.position = "absolute";
|
||||
style.overflow = "visible";
|
||||
var n = 1000;
|
||||
if (!this.$measureNode) {
|
||||
var measureNode = this.$measureNode = document.createElement("div");
|
||||
var style = measureNode.style;
|
||||
|
||||
style.width = style.height = "auto";
|
||||
style.left = style.top = "-1000px";
|
||||
|
||||
style.visibility = "hidden";
|
||||
style.position = "absolute";
|
||||
style.overflow = "visible";
|
||||
style.whiteSpace = "nowrap";
|
||||
|
||||
// in FF 3.6 monospace fonts can have a fixed sub pixel width.
|
||||
// that's why we have to measure many characters
|
||||
// Note: characterWidth can be a float!
|
||||
measureNode.innerHTML = lang.stringRepeat("Xy", n);
|
||||
document.body.insertBefore(measureNode, document.body.firstChild);
|
||||
}
|
||||
|
||||
var style = this.$measureNode.style;
|
||||
for (var prop in this.$fontStyles) {
|
||||
var value = dom.computedStyle(this.element, prop);
|
||||
style[prop] = value;
|
||||
}
|
||||
|
||||
// in FF 3.6 monospace fonts can have a fixed sub pixel width.
|
||||
// that's why we have to measure many characters
|
||||
// Note: characterWidth can be a float!
|
||||
measureNode.innerHTML = new Array(1000).join("Xy");
|
||||
document.body.insertBefore(measureNode, document.body.firstChild);
|
||||
|
||||
var size = {
|
||||
height: measureNode.offsetHeight,
|
||||
width: measureNode.offsetWidth / 2000
|
||||
height: this.$measureNode.offsetHeight,
|
||||
width: this.$measureNode.offsetWidth / (n * 2)
|
||||
};
|
||||
|
||||
document.body.removeChild(measureNode);
|
||||
return size;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -37,17 +37,17 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var TextMode = require("ace/mode/text").Text;
|
||||
var oop = require("pilot/oop");
|
||||
var TextMode = require("ace/mode/text").Mode;
|
||||
var Tokenizer = require("ace/tokenizer").Tokenizer;
|
||||
var CssHighlightRules = require("ace/mode/css_highlight_rules").CssHighlightRules;
|
||||
var MatchingBraceOutdent = require("ace/mode/matching_brace_outdent").MatchingBraceOutdent;
|
||||
|
||||
var Css = function() {
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new CssHighlightRules().getRules());
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
};
|
||||
oop.inherits(Css, TextMode);
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
(function() {
|
||||
|
||||
|
|
@ -76,8 +76,8 @@ oop.inherits(Css, TextMode);
|
|||
return this.$outdent.autoOutdent(doc, row);
|
||||
};
|
||||
|
||||
}).call(Css.prototype);
|
||||
}).call(Mode.prototype);
|
||||
|
||||
exports.Css = Css;
|
||||
exports.Mode = Mode;
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var lang = require("pilot/lang").lang;
|
||||
var oop = require("pilot/oop");
|
||||
var lang = require("pilot/lang");
|
||||
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
||||
|
||||
var CssHighlightRules = function() {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var oop = require("pilot/oop");
|
||||
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
||||
|
||||
var DocCommentHighlightRules = function() {
|
||||
|
|
|
|||
|
|
@ -37,24 +37,24 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var TextMode = require("ace/mode/text").Text;
|
||||
var JavaScriptMode = require("ace/mode/javascript").JavaScript;
|
||||
var CssMode = require("ace/mode/css").Css;
|
||||
var oop = require("pilot/oop");
|
||||
var TextMode = require("ace/mode/text").Mode;
|
||||
var JavaScriptMode = require("ace/mode/javascript").Mode;
|
||||
var CssMode = require("ace/mode/css").Mode;
|
||||
var Tokenizer = require("ace/tokenizer").Tokenizer;
|
||||
var HtmlHighlightRules = require("ace/mode/html_highlight_rules").HtmlHighlightRules;
|
||||
|
||||
var Html = function() {
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new HtmlHighlightRules().getRules());
|
||||
|
||||
this.$js = new JavaScriptMode();
|
||||
this.$css = new CssMode();
|
||||
};
|
||||
oop.inherits(Html, TextMode);
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
(function() {
|
||||
|
||||
this.toggleCommentLines = function(state, doc, range) {
|
||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
||||
return this.$delegate("toggleCommentLines", arguments, function() {
|
||||
return 0;
|
||||
});
|
||||
|
|
@ -95,7 +95,7 @@ oop.inherits(Html, TextMode);
|
|||
return defaultHandler ? defaultHandler() : undefined;
|
||||
};
|
||||
|
||||
}).call(Html.prototype);
|
||||
}).call(Mode.prototype);
|
||||
|
||||
exports.Html = Html;
|
||||
exports.Mode = Mode;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var oop = require("pilot/oop");
|
||||
var CssHighlightRules = require("ace/mode/css_highlight_rules").CssHighlightRules;
|
||||
var JavaScriptHighlightRules = require("ace/mode/javascript_highlight_rules").JavaScriptHighlightRules;
|
||||
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
||||
|
|
|
|||
|
|
@ -37,27 +37,27 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var TextMode = require("ace/mode/text").Text;
|
||||
var oop = require("pilot/oop");
|
||||
var TextMode = require("ace/mode/text").Mode;
|
||||
var Tokenizer = require("ace/tokenizer").Tokenizer;
|
||||
var JavaScriptHighlightRules = require("ace/mode/javascript_highlight_rules").JavaScriptHighlightRules;
|
||||
var MatchingBraceOutdent = require("ace/mode/matching_brace_outdent").MatchingBraceOutdent;
|
||||
var Range = require("ace/range").Range;
|
||||
|
||||
var JavaScript = function() {
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new JavaScriptHighlightRules().getRules());
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
};
|
||||
oop.inherits(JavaScript, TextMode);
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
(function() {
|
||||
|
||||
this.toggleCommentLines = function(state, doc, range) {
|
||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
||||
var outdent = true;
|
||||
var outentedRows = [];
|
||||
var re = /^(\s*)\/\//;
|
||||
|
||||
for (var i=range.start.row; i<= range.end.row; i++) {
|
||||
for (var i=startRow; i<= endRow; i++) {
|
||||
if (!re.test(doc.getLine(i))) {
|
||||
outdent = false;
|
||||
break;
|
||||
|
|
@ -66,7 +66,7 @@ oop.inherits(JavaScript, TextMode);
|
|||
|
||||
if (outdent) {
|
||||
var deleteRange = new Range(0, 0, 0, 0);
|
||||
for (var i=range.start.row; i<= range.end.row; i++)
|
||||
for (var i=startRow; i<= endRow; i++)
|
||||
{
|
||||
var line = doc.getLine(i).replace(re, "$1");
|
||||
deleteRange.start.row = i;
|
||||
|
|
@ -77,7 +77,7 @@ oop.inherits(JavaScript, TextMode);
|
|||
return -2;
|
||||
}
|
||||
else {
|
||||
return doc.indentRows(range, "//");
|
||||
return doc.indentRows(startRow, endRow, "//");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -107,12 +107,7 @@ oop.inherits(JavaScript, TextMode);
|
|||
indent += " ";
|
||||
}
|
||||
indent += "* ";
|
||||
}{
|
||||
if (match[1]) {
|
||||
indent += " ";
|
||||
}
|
||||
indent += "* ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return indent;
|
||||
|
|
@ -126,7 +121,7 @@ oop.inherits(JavaScript, TextMode);
|
|||
return this.$outdent.autoOutdent(doc, row);
|
||||
};
|
||||
|
||||
}).call(JavaScript.prototype);
|
||||
}).call(Mode.prototype);
|
||||
|
||||
exports.JavaScript = JavaScript;
|
||||
exports.Mode = Mode;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var lang = require("pilot/lang").lang;
|
||||
var oop = require("pilot/oop");
|
||||
var lang = require("pilot/lang");
|
||||
var DocCommentHighlightRules = require("ace/mode/doc_comment_highlight_rules").DocCommentHighlightRules;
|
||||
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ JavaScriptHighlightRules = function() {
|
|||
);
|
||||
|
||||
var buildinConstants = lang.arrayToMap(
|
||||
("true|false|null|undefined|Infinity|NaN|undefined").split("|")
|
||||
("null|Infinity|NaN|undefined").split("|")
|
||||
);
|
||||
|
||||
var futureReserved = lang.arrayToMap(
|
||||
|
|
@ -96,6 +96,9 @@ JavaScriptHighlightRules = function() {
|
|||
}, {
|
||||
token : "constant.numeric", // float
|
||||
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
|
||||
}, {
|
||||
token : "constant.boolean", // float
|
||||
regex : "(?:true|false)\\b"
|
||||
}, {
|
||||
token : function(value) {
|
||||
if (value == "this")
|
||||
|
|
@ -116,13 +119,13 @@ JavaScriptHighlightRules = function() {
|
|||
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
|
||||
}, {
|
||||
token : "keyword.operator",
|
||||
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(in|instanceof|new|delete|typeof|void)"
|
||||
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
|
||||
}, {
|
||||
token : "lparen",
|
||||
regex : "[\\[\\(\\{]"
|
||||
regex : "[[({]"
|
||||
}, {
|
||||
token : "rparen",
|
||||
regex : "[\\]\\)\\}]"
|
||||
regex : "[\\])}]"
|
||||
}, {
|
||||
token : "text",
|
||||
regex : "\\s+"
|
||||
|
|
|
|||
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("pilot/oop");
|
||||
var TextMode = require("./text").Mode;
|
||||
var Tokenizer = require("../tokenizer").Tokenizer;
|
||||
var PythonHighlightRules = require("./python_highlight_rules").PythonHighlightRules;
|
||||
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
|
||||
var Range = require("../range").Range;
|
||||
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new PythonHighlightRules().getRules());
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
(function() {
|
||||
|
||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
||||
var outdent = true;
|
||||
var outentedRows = [];
|
||||
var re = /^(\s*)#/;
|
||||
|
||||
for (var i=startRow; i<= endRow; i++) {
|
||||
if (!re.test(doc.getLine(i))) {
|
||||
outdent = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (outdent) {
|
||||
var deleteRange = new Range(0, 0, 0, 0);
|
||||
for (var i=startRow; i<= endRow; 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(startRow, endRow, "#");
|
||||
}
|
||||
};
|
||||
|
||||
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(Mode.prototype);
|
||||
|
||||
exports.Mode = Mode;
|
||||
});
|
||||
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("pilot/oop");
|
||||
var lang = require("pilot/lang");
|
||||
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
||||
|
||||
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);
|
||||
|
||||
exports.PythonHighlightRules = PythonHighlightRules;
|
||||
});
|
||||
|
|
@ -40,7 +40,7 @@ define(function(require, exports, module) {
|
|||
var Tokenizer = require("ace/tokenizer").Tokenizer;
|
||||
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
||||
|
||||
var Text = function() {
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new TextHighlightRules().getRules());
|
||||
};
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ var Text = function() {
|
|||
return this.$tokenizer;
|
||||
};
|
||||
|
||||
this.toggleCommentLines = function(state, doc, range) {
|
||||
this.toggleCommentLines = function(state, doc, startRow, endRow) {
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ var Text = function() {
|
|||
return "";
|
||||
};
|
||||
|
||||
}).call(Text.prototype);
|
||||
}).call(Mode.prototype);
|
||||
|
||||
exports.Text = Text;
|
||||
exports.Mode = Mode;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -37,16 +37,16 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var TextMode = require("ace/mode/text").Text;
|
||||
var oop = require("pilot/oop");
|
||||
var TextMode = require("ace/mode/text").Mode;
|
||||
var Tokenizer = require("ace/tokenizer").Tokenizer;
|
||||
var XmlHighlightRules = require("ace/mode/xml_highlight_rules").XmlHighlightRules;
|
||||
|
||||
var Xml = function() {
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new XmlHighlightRules().getRules());
|
||||
};
|
||||
|
||||
oop.inherits(Xml, TextMode);
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
(function() {
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ oop.inherits(Xml, TextMode);
|
|||
return this.$getIndent(line);
|
||||
};
|
||||
|
||||
}).call(Xml.prototype);
|
||||
}).call(Mode.prototype);
|
||||
|
||||
exports.Xml = Xml;
|
||||
exports.Mode = Mode;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var oop = require("pilot/oop");
|
||||
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
|
||||
|
||||
var XmlHighlightRules = function() {
|
||||
|
|
|
|||
|
|
@ -137,6 +137,13 @@ var Range = function(startRow, startColumn, endRow, endColumn) {
|
|||
this.clone = function() {
|
||||
return Range.fromPoints(this.start, this.end);
|
||||
};
|
||||
|
||||
this.collapseRows = function() {
|
||||
if (this.end.column == 0)
|
||||
return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
|
||||
else
|
||||
return new Range(this.start.row, 0, this.end.row, 0)
|
||||
};
|
||||
|
||||
this.toScreenRange = function(doc) {
|
||||
return new Range(
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var event = require("pilot/event").event;
|
||||
var event = require("pilot/event");
|
||||
|
||||
var RenderLoop = function(onRender) {
|
||||
this.onRender = onRender;
|
||||
|
|
|
|||
|
|
@ -37,10 +37,9 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var lang = require("pilot/lang").lang;
|
||||
var dom = require("pilot/dom").dom;
|
||||
var event = require("pilot/event").event;
|
||||
var oop = require("pilot/oop");
|
||||
var dom = require("pilot/dom");
|
||||
var event = require("pilot/event");
|
||||
var EventEmitter = require("pilot/event_emitter").EventEmitter;
|
||||
|
||||
var ScrollBar = function(parent) {
|
||||
|
|
@ -55,14 +54,14 @@ var ScrollBar = function(parent) {
|
|||
this.width = dom.scrollbarWidth();
|
||||
this.element.style.width = this.width;
|
||||
|
||||
event.addListener(this.element, "scroll", lang.bind(this.onScroll, this));
|
||||
event.addListener(this.element, "scroll", this.onScroll.bind(this));
|
||||
};
|
||||
|
||||
(function() {
|
||||
oop.implement(this, EventEmitter);
|
||||
|
||||
this.onScroll = function() {
|
||||
this.$dispatchEvent("scroll", {data: this.element.scrollTop});
|
||||
this._dispatchEvent("scroll", {data: this.element.scrollTop});
|
||||
};
|
||||
|
||||
this.getWidth = function() {
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var lang = require("pilot/lang").lang;
|
||||
var oop = require("pilot/oop").oop;
|
||||
var lang = require("pilot/lang");
|
||||
var oop = require("pilot/oop");
|
||||
var Range = require("ace/range").Range;
|
||||
|
||||
var Search = function() {
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var lang = require("pilot/lang").lang;
|
||||
var oop = require("pilot/oop");
|
||||
var lang = require("pilot/lang");
|
||||
var EventEmitter = require("pilot/event_emitter").EventEmitter;
|
||||
var Range = require("ace/range").Range;
|
||||
|
||||
|
|
|
|||
|
|
@ -35,14 +35,26 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require({
|
||||
paths: {
|
||||
"ace": "../src/ace"
|
||||
}},
|
||||
["ace/test/assertions", "ace/test/ChangeDocumentTest"],
|
||||
function(a) {
|
||||
console.log(a)
|
||||
alert("a " + a)
|
||||
}
|
||||
);
|
||||
require("../../../support/paths");
|
||||
|
||||
var async = require("async");
|
||||
|
||||
async.concat(
|
||||
require("./change_document_test"),
|
||||
require("./document_test"),
|
||||
require("./event_emitter_test"),
|
||||
require("./navigation_test"),
|
||||
require("./range_test"),
|
||||
require("./search_test"),
|
||||
require("./selection_test"),
|
||||
require("./text_edit_test"),
|
||||
require("./mode/css_test"),
|
||||
require("./mode/css_tokenizer_test"),
|
||||
require("./mode/html_test"),
|
||||
require("./mode/html_tokenizer_test"),
|
||||
require("./mode/javascript_test"),
|
||||
require("./mode/javascript_tokenizer_test"),
|
||||
require("./mode/text_test"),
|
||||
require("./mode/xml_test"),
|
||||
require("./mode/xml_tokenizer_test")
|
||||
).exec();
|
||||
|
|
|
|||
|
|
@ -36,20 +36,12 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require("../../../support/paths");
|
||||
require("./mockdom");
|
||||
|
||||
var dom = require('jsdom/level2/html').dom.level2.html;
|
||||
var 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"),
|
||||
Text = require("../mode/text"),
|
||||
JavaScriptMode = require("../mode/javascript"),
|
||||
var Document = require("../document").Document,
|
||||
Editor = require("../editor").Editor,
|
||||
Text = require("../mode/text").Mode,
|
||||
JavaScriptMode = require("../mode/javascript").Mode,
|
||||
MockRenderer = require("./mockrenderer"),
|
||||
assert = require("./assertions");
|
||||
|
||||
|
|
|
|||
|
|
@ -36,12 +36,12 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require("../../../support/paths");
|
||||
require("./mockdom");
|
||||
|
||||
var Document = require("../document"),
|
||||
UndoManager = require("../undomanager"),
|
||||
//Editor = require("../editor"),
|
||||
var Document = require("../document").Document,
|
||||
UndoManager = require("../undomanager").UndoManager,
|
||||
MockRenderer = require("./mockrenderer"),
|
||||
Range = require("../range"),
|
||||
Range = require("../range").Range,
|
||||
assert = require("./assertions"),
|
||||
async = require("async");
|
||||
|
||||
|
|
@ -81,39 +81,35 @@ var Test = {
|
|||
},
|
||||
|
||||
"test: move lines down" : function() {
|
||||
var doc = new Document(["1", "2", "3", "4"]);
|
||||
var doc = new Document(["a1", "a2", "a3", "a4"]);
|
||||
|
||||
console.log(doc.toString().replace(/\n/g, "\\n"));
|
||||
doc.moveLinesDown(0, 1);
|
||||
console.log(doc.toString().replace(/\n/g, "\\n"));
|
||||
assert.equal(doc.toString(), ["3", "1", "2", "4"].join("\n"));
|
||||
assert.equal(doc.toString(), ["a3", "a1", "a2", "a4"].join("\n"));
|
||||
|
||||
doc.moveLinesDown(1, 2);
|
||||
assert.equal(doc.toString(), ["3", "4", "1", "2"].join("\n"));
|
||||
assert.equal(doc.toString(), ["a3", "a4", "a1", "a2"].join("\n"));
|
||||
|
||||
doc.moveLinesDown(2, 3);
|
||||
assert.equal(doc.toString(), ["3", "4", "1", "2"].join("\n"));
|
||||
assert.equal(doc.toString(), ["a3", "a4", "a1", "a2"].join("\n"));
|
||||
|
||||
doc.moveLinesDown(2, 2);
|
||||
assert.equal(doc.toString(), ["3", "4", "2", "1"].join("\n"));
|
||||
assert.equal(doc.toString(), ["a3", "a4", "a2", "a1"].join("\n"));
|
||||
},
|
||||
|
||||
"__test: move lines up" : function() {
|
||||
var doc = new Document(["1", "2", "3", "4"]);
|
||||
"test: move lines up" : function() {
|
||||
var doc = new Document(["a1", "a2", "a3", "a4"]);
|
||||
|
||||
console.log(doc.toString().replace(/\n/g, "\\n"));
|
||||
doc.moveLinesUp(2, 3);
|
||||
console.log(doc.toString().replace(/\n/g, "\\n"));
|
||||
assert.equal(doc.toString(), ["1", "3", "4", "2"].join("\n"));
|
||||
assert.equal(doc.toString(), ["a1", "a3", "a4", "a2"].join("\n"));
|
||||
|
||||
doc.moveLinesUp(1, 2);
|
||||
assert.equal(doc.toString(), ["3", "4", "1", "2"].join("\n"));
|
||||
assert.equal(doc.toString(), ["a3", "a4", "a1", "a2"].join("\n"));
|
||||
|
||||
doc.moveLinesUp(0, 1);
|
||||
assert.equal(doc.toString(), ["3", "4", "1", "2"].join("\n"));
|
||||
assert.equal(doc.toString(), ["a3", "a4", "a1", "a2"].join("\n"));
|
||||
|
||||
doc.moveLinesUp(2, 2);
|
||||
assert.equal(doc.toString(), ["3", "1", "4", "2"].join("\n"));
|
||||
assert.equal(doc.toString(), ["a3", "a1", "a4", "a2"].join("\n"));
|
||||
},
|
||||
|
||||
"test: duplicate lines" : function() {
|
||||
|
|
@ -178,49 +174,6 @@ var Test = {
|
|||
assert.equal(["4", "5", "6"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"__test: undo/redo for delete line" : function() {
|
||||
var doc = new Document(["111", "222", "333"]);
|
||||
var undoManager = new UndoManager();
|
||||
doc.setUndoManager(undoManager);
|
||||
|
||||
var initialText = doc.toString();
|
||||
|
||||
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.removeLines();
|
||||
var step1 = doc.toString();
|
||||
assert.equal(step1, "222\n333");
|
||||
doc.$informUndoManager.call();
|
||||
|
||||
editor.removeLines();
|
||||
var step2 = doc.toString();
|
||||
assert.equal(step2, "333");
|
||||
doc.$informUndoManager.call();
|
||||
|
||||
editor.removeLines();
|
||||
var step3 = doc.toString();
|
||||
assert.equal(step3, "");
|
||||
doc.$informUndoManager.call();
|
||||
|
||||
|
||||
undoManager.undo();
|
||||
doc.$informUndoManager.call();
|
||||
assert.equal(doc.toString(), step2);
|
||||
|
||||
undoManager.undo();
|
||||
doc.$informUndoManager.call();
|
||||
assert.equal(doc.toString(), step1);
|
||||
|
||||
undoManager.undo();
|
||||
doc.$informUndoManager.call();
|
||||
assert.equal(doc.toString(), initialText);
|
||||
|
||||
undoManager.undo();
|
||||
doc.$informUndoManager.call();
|
||||
assert.equal(doc.toString(), initialText);
|
||||
},
|
||||
|
||||
"test: convert document to screen coordinates" : function() {
|
||||
var doc = new Document("01234\t567890\t1234");
|
||||
doc.setTabSize(4);
|
||||
|
|
|
|||
|
|
@ -37,17 +37,17 @@
|
|||
|
||||
require("../../../support/paths");
|
||||
|
||||
var oop = require("../lib/oop");
|
||||
MEventEmitter = require("../event_emitter"),
|
||||
var oop = require("pilot/oop");
|
||||
EventEmitter = require("pilot/event_emitter").EventEmitter,
|
||||
assert = require("./assertions");
|
||||
|
||||
var EventEmitter = function() {};
|
||||
var Emitter = function() {};
|
||||
|
||||
oop.implement(EventEmitter.prototype, EventEmitter);
|
||||
oop.implement(Emitter.prototype, EventEmitter);
|
||||
|
||||
var Test = {
|
||||
"test: dispatch event with no data" : function() {
|
||||
var emitter = new EventEmitter();
|
||||
var emitter = new Emitter();
|
||||
|
||||
var called = false;
|
||||
emitter.addEventListener("juhu", function(e) {
|
||||
|
|
@ -55,7 +55,7 @@ var Test = {
|
|||
assert.equal(e.type, "juhu");
|
||||
});
|
||||
|
||||
emitter.$dispatchEvent("juhu");
|
||||
emitter._dispatchEvent("juhu");
|
||||
assert.true(called);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
8
lib/ace/test/mockdom.js
Normal file
8
lib/ace/test/mockdom.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
var dom = require('jsdom/level2/html').dom.level2.html;
|
||||
var 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;
|
||||
|
|
@ -116,6 +116,9 @@ MockRenderer.prototype.setBreakpoints = function() {
|
|||
MockRenderer.prototype.updateFull = function() {
|
||||
};
|
||||
|
||||
MockRenderer.prototype.updateText = function() {
|
||||
};
|
||||
|
||||
MockRenderer.prototype.showCursor = function() {
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -35,19 +35,13 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require.def([
|
||||
"ace/Document",
|
||||
"ace/Range",
|
||||
"ace/mode/Css"
|
||||
], function(
|
||||
Document,
|
||||
Range,
|
||||
cssMod
|
||||
) {
|
||||
require("../../../../support/paths");
|
||||
|
||||
var CssMode = cssMod.Css;
|
||||
var CssTest = new TestCase("mode.CssTest", {
|
||||
var Document = require("ace/document").Document;
|
||||
var CssMode = require("ace/mode/css").Mode;
|
||||
var assert = require("../assertions");
|
||||
|
||||
var Test = {
|
||||
setUp : function() {
|
||||
this.mode = new CssMode();
|
||||
},
|
||||
|
|
@ -55,26 +49,28 @@ var CssTest = new TestCase("mode.CssTest", {
|
|||
"test: toggle comment lines should not do anything" : function() {
|
||||
var doc = new Document([" abc", "cde", "fg"].join("\n"));
|
||||
|
||||
var range = new Range(0, 3, 1, 1);
|
||||
var comment = this.mode.toggleCommentLines("start", doc, range);
|
||||
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
var comment = this.mode.toggleCommentLines("start", doc, 0, 1);
|
||||
assert.equal([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
|
||||
"test: lines should keep indentation" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " abc", " "));
|
||||
assertEquals("\t", this.mode.getNextLineIndent("start", "\tabc", " "));
|
||||
assert.equal(" ", this.mode.getNextLineIndent("start", " abc", " "));
|
||||
assert.equal("\t", this.mode.getNextLineIndent("start", "\tabc", " "));
|
||||
},
|
||||
|
||||
"test: new line after { should increase indent" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " abc{", " "));
|
||||
assertEquals("\t ", this.mode.getNextLineIndent("start", "\tabc { ", " "));
|
||||
assert.equal(" ", this.mode.getNextLineIndent("start", " abc{", " "));
|
||||
assert.equal("\t ", this.mode.getNextLineIndent("start", "\tabc { ", " "));
|
||||
},
|
||||
|
||||
"test: no indent increase after { in a comment" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " /*{", " "));
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " /*{ ", " "));
|
||||
assert.equal(" ", this.mode.getNextLineIndent("start", " /*{", " "));
|
||||
assert.equal(" ", this.mode.getNextLineIndent("start", " /*{ ", " "));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
module.exports = require("async/test").testcase(Test);
|
||||
|
||||
if (module === require.main)
|
||||
module.exports.exec()
|
||||
|
|
@ -35,15 +35,12 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require.def([
|
||||
"ace/mode/Css"
|
||||
], function(
|
||||
cssMod
|
||||
) {
|
||||
|
||||
var CssMode = cssMod.Css;
|
||||
var CssTest = new TestCase("mode.CssTest", {
|
||||
require("../../../../support/paths");
|
||||
|
||||
var CssMode = require("ace/mode/css").Mode;
|
||||
var assert = require("../assertions");
|
||||
|
||||
var Test = {
|
||||
setUp : function() {
|
||||
this.tokenizer = new CssMode().getTokenizer();
|
||||
},
|
||||
|
|
@ -52,32 +49,35 @@ var CssTest = new TestCase("mode.CssTest", {
|
|||
var line = "-12px";
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
assertEquals(1, tokens.length);
|
||||
assertEquals("number", tokens[0].type);
|
||||
assert.equal(1, tokens.length);
|
||||
assert.equal("constant.numeric", tokens[0].type);
|
||||
},
|
||||
|
||||
"test: tokenize hex3 color" : function() {
|
||||
var tokens = this.tokenizer.getLineTokens("#abc", "start").tokens;
|
||||
|
||||
assertEquals(1, tokens.length);
|
||||
assertEquals("number", tokens[0].type);
|
||||
assert.equal(1, tokens.length);
|
||||
assert.equal("constant.numeric", tokens[0].type);
|
||||
},
|
||||
|
||||
"test: tokenize hex6 color" : function() {
|
||||
var tokens = this.tokenizer.getLineTokens("#abc012", "start").tokens;
|
||||
|
||||
assertEquals(1, tokens.length);
|
||||
assertEquals("number", tokens[0].type);
|
||||
assert.equal(1, tokens.length);
|
||||
assert.equal("constant.numeric", tokens[0].type);
|
||||
},
|
||||
|
||||
"test: tokenize parens" : function() {
|
||||
var tokens = this.tokenizer.getLineTokens("{()}", "start").tokens;
|
||||
|
||||
assertEquals(3, tokens.length);
|
||||
assertEquals("lparen", tokens[0].type);
|
||||
assertEquals("text", tokens[1].type);
|
||||
assertEquals("rparen", tokens[2].type);
|
||||
assert.equal(3, tokens.length);
|
||||
assert.equal("lparen", tokens[0].type);
|
||||
assert.equal("text", tokens[1].type);
|
||||
assert.equal("rparen", tokens[2].type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
module.exports = require("async/test").testcase(Test);
|
||||
|
||||
if (module === require.main)
|
||||
module.exports.exec()
|
||||
|
|
@ -35,20 +35,15 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require.def([
|
||||
"ace/Document",
|
||||
"ace/Range",
|
||||
"ace/mode/Html"
|
||||
], function(
|
||||
Document,
|
||||
Range,
|
||||
htmlMod
|
||||
) {
|
||||
require("../../../../support/paths");
|
||||
|
||||
var Document = require("ace/document").Document;
|
||||
var Range = require("ace/range").Range;
|
||||
var HtmlMode = require("ace/mode/html").Mode;
|
||||
var assert = require("../assertions");
|
||||
|
||||
var HtmlMode = htmlMod.Html;
|
||||
var HtmlTest = new TestCase("mode.HtmlTest", {
|
||||
|
||||
setUp : function() {
|
||||
var Test = {
|
||||
setUp : function() {
|
||||
this.mode = new HtmlMode();
|
||||
},
|
||||
|
||||
|
|
@ -56,15 +51,18 @@ var HtmlTest = new TestCase("mode.HtmlTest", {
|
|||
var doc = new Document([" abc", "cde", "fg"]);
|
||||
|
||||
var range = new Range(0, 3, 1, 1);
|
||||
var comment = this.mode.toggleCommentLines("start", doc, range);
|
||||
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
var comment = this.mode.toggleCommentLines("start", doc, 0, 1);
|
||||
assert.equal([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: next line indent should be the same as the current line indent" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " abc"));
|
||||
assertEquals("", this.mode.getNextLineIndent("start", "abc"));
|
||||
assertEquals("\t", this.mode.getNextLineIndent("start", "\tabc"));
|
||||
assert.equal(" ", this.mode.getNextLineIndent("start", " abc"));
|
||||
assert.equal("", this.mode.getNextLineIndent("start", "abc"));
|
||||
assert.equal("\t", this.mode.getNextLineIndent("start", "\tabc"));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
module.exports = require("async/test").testcase(Test);
|
||||
|
||||
if (module === require.main)
|
||||
module.exports.exec()
|
||||
|
|
@ -35,15 +35,12 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require.def([
|
||||
"ace/mode/Html"
|
||||
], function(
|
||||
htmlMod
|
||||
) {
|
||||
|
||||
var HtmlMode = htmlMod.Html;
|
||||
var HtmlTest = new TestCase("mode.HtmlTest", {
|
||||
require("../../../../support/paths");
|
||||
|
||||
var HtmlMode = require("ace/mode/html").Mode;
|
||||
var assert = require("../assertions");
|
||||
|
||||
var Test = {
|
||||
setUp : function() {
|
||||
this.tokenizer = new HtmlMode().getTokenizer();
|
||||
},
|
||||
|
|
@ -53,19 +50,22 @@ var HtmlTest = new TestCase("mode.HtmlTest", {
|
|||
var line = "<script a='a'>var</script>'123'";
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
//assertEquals(10, tokens.length);
|
||||
assertEquals("text", tokens[0].type);
|
||||
assertEquals("keyword", tokens[1].type);
|
||||
assertEquals("text", tokens[2].type);
|
||||
assertEquals("keyword", tokens[3].type);
|
||||
assertEquals("text", tokens[4].type);
|
||||
assertEquals("string", tokens[5].type);
|
||||
assertEquals("text", tokens[6].type);
|
||||
assertEquals("keyword", tokens[7].type);
|
||||
assertEquals("text", tokens[8].type);
|
||||
assertEquals("keyword", tokens[9].type);
|
||||
assertEquals("text", tokens[10].type);
|
||||
//assert.equal(10, tokens.length);
|
||||
assert.equal("text", tokens[0].type);
|
||||
assert.equal("keyword", tokens[1].type);
|
||||
assert.equal("text", tokens[2].type);
|
||||
assert.equal("keyword", tokens[3].type);
|
||||
assert.equal("text", tokens[4].type);
|
||||
assert.equal("string", tokens[5].type);
|
||||
assert.equal("text", tokens[6].type);
|
||||
assert.equal("keyword", tokens[7].type);
|
||||
assert.equal("text", tokens[8].type);
|
||||
assert.equal("keyword", tokens[9].type);
|
||||
assert.equal("text", tokens[10].type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
module.exports = require("async/test").testcase(Test);
|
||||
|
||||
if (module === require.main)
|
||||
module.exports.exec()
|
||||
|
|
@ -35,117 +35,116 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require.def([
|
||||
"ace/Document",
|
||||
"ace/Range",
|
||||
"ace/Tokenizer",
|
||||
"ace/mode/JavaScript"
|
||||
], function(
|
||||
Document,
|
||||
Range,
|
||||
Tokenizer,
|
||||
jsMod
|
||||
) {
|
||||
require("../../../../support/paths");
|
||||
|
||||
var Document = require("ace/document").Document;
|
||||
var Tokenizer = require("ace/tokenizer").Tokenizer;
|
||||
var JavaScriptMode = require("ace/mode/javascript").Mode;
|
||||
var assert = require("../assertions");
|
||||
|
||||
var JavaScriptMode = jsMod.JavaScript;
|
||||
var JavaScriptTest = new TestCase("mode.JavaScriptTest", {
|
||||
|
||||
setUp : function() {
|
||||
var Test = {
|
||||
setUp : function() {
|
||||
this.mode = new JavaScriptMode();
|
||||
},
|
||||
|
||||
"test: getTokenizer() (smoke test)" : function() {
|
||||
var tokenizer = this.mode.getTokenizer();
|
||||
|
||||
assertTrue(tokenizer instanceof Tokenizer);
|
||||
assert.ok(tokenizer instanceof Tokenizer);
|
||||
|
||||
var tokens = tokenizer.getLineTokens("'juhu'", "start").tokens;
|
||||
assertEquals("string", tokens[0].type);
|
||||
assert.equal("string", tokens[0].type);
|
||||
},
|
||||
|
||||
"test: toggle comment lines should prepend '//' to each line" : function() {
|
||||
var doc = new Document([" abc", "cde", "fg"]);
|
||||
|
||||
var range = new Range(0, 3, 1, 1);
|
||||
var comment = this.mode.toggleCommentLines("start", doc, range);
|
||||
assertEquals(["// abc", "//cde", "fg"].join("\n"), doc.toString());
|
||||
var comment = this.mode.toggleCommentLines("start", doc, 0, 1);
|
||||
assert.equal(["// abc", "//cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: toggle comment on commented lines should remove leading '//' chars" : function() {
|
||||
var doc = new Document(["// abc", "//cde", "fg"]);
|
||||
|
||||
var range = new Range(0, 3, 1, 1);
|
||||
var comment = this.mode.toggleCommentLines("start", doc, range);
|
||||
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
var comment = this.mode.toggleCommentLines("start", doc, 0, 1);
|
||||
assert.equal([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: toggle comment lines twice should return the original text" : function() {
|
||||
var doc = new Document([" abc", "cde", "fg"]);
|
||||
|
||||
this.mode.toggleCommentLines("start", doc, 0, 2);
|
||||
this.mode.toggleCommentLines("start", doc, 0, 2);
|
||||
assert.equal([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: toggle comment on multiple lines with one commented line prepend '//' to each line" : function() {
|
||||
var doc = new Document(["// abc", "//cde", "fg"]);
|
||||
|
||||
var range = new Range(0, 3, 2, 1);
|
||||
var comment = this.mode.toggleCommentLines("start", doc, range);
|
||||
assertEquals(["//// abc", "////cde", "//fg"].join("\n"), doc.toString());
|
||||
var comment = this.mode.toggleCommentLines("start", doc, 0, 2);
|
||||
assert.equal(["//// abc", "////cde", "//fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: toggle comment on a comment line with leading white space": function() {
|
||||
var doc = new Document(["//cde", " //fg"]);
|
||||
|
||||
var range = new Range(0, 3, 1, 1);
|
||||
var comment = this.mode.toggleCommentLines("start", doc, range);
|
||||
assertEquals(["cde", " fg"].join("\n"), doc.toString());
|
||||
var comment = this.mode.toggleCommentLines("start", doc, 0, 1);
|
||||
assert.equal(["cde", " fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: auto indent after opening brace" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", "if () {", " "));
|
||||
assert.equal(" ", this.mode.getNextLineIndent("start", "if () {", " "));
|
||||
},
|
||||
|
||||
"test: no auto indent after opening brace in multi line comment" : function() {
|
||||
assertEquals("", this.mode.getNextLineIndent("start", "/*if () {", " "));
|
||||
assertEquals(" ", this.mode.getNextLineIndent("comment", " abcd", " "));
|
||||
assert.equal("", this.mode.getNextLineIndent("start", "/*if () {", " "));
|
||||
assert.equal(" ", this.mode.getNextLineIndent("comment", " abcd", " "));
|
||||
},
|
||||
|
||||
"test: no auto indent after opening brace in single line comment" : function() {
|
||||
assertEquals("", this.mode.getNextLineIndent("start", "//if () {", " "));
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " //if () {", " "));
|
||||
assert.equal("", this.mode.getNextLineIndent("start", "//if () {", " "));
|
||||
assert.equal(" ", this.mode.getNextLineIndent("start", " //if () {", " "));
|
||||
},
|
||||
|
||||
"test: no auto indent should add to existing indent" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " if () {", " "));
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " cde", " "));
|
||||
assert.equal(" ", this.mode.getNextLineIndent("start", " if () {", " "));
|
||||
assert.equal(" ", this.mode.getNextLineIndent("start", " cde", " "));
|
||||
},
|
||||
|
||||
"test: special indent in doc comments" : function() {
|
||||
assertEquals(" * ", this.mode.getNextLineIndent("doc-start", "/**", " "));
|
||||
assertEquals(" * ", this.mode.getNextLineIndent("doc-start", " /**", " "));
|
||||
assertEquals(" * ", this.mode.getNextLineIndent("doc-start", " *", " "));
|
||||
assertEquals(" * ", this.mode.getNextLineIndent("doc-start", " *", " "));
|
||||
assertEquals(" ", this.mode.getNextLineIndent("doc-start", " abc", " "));
|
||||
assert.equal(" * ", this.mode.getNextLineIndent("doc-start", "/**", " "));
|
||||
assert.equal(" * ", this.mode.getNextLineIndent("doc-start", " /**", " "));
|
||||
assert.equal(" * ", this.mode.getNextLineIndent("doc-start", " *", " "));
|
||||
assert.equal(" * ", this.mode.getNextLineIndent("doc-start", " *", " "));
|
||||
assert.equal(" ", this.mode.getNextLineIndent("doc-start", " abc", " "));
|
||||
},
|
||||
|
||||
"test: no indent after doc comments" : function() {
|
||||
assertEquals("", this.mode.getNextLineIndent("doc-start", " */", " "));
|
||||
assert.equal("", this.mode.getNextLineIndent("doc-start", " */", " "));
|
||||
},
|
||||
|
||||
"test: trigger outdent if line is space and new text starts with closing brace" : function() {
|
||||
assertTrue(this.mode.checkOutdent("start", " ", " }"));
|
||||
assertFalse(this.mode.checkOutdent("start", " a ", " }"));
|
||||
assertFalse(this.mode.checkOutdent("start", "", "}"));
|
||||
assertFalse(this.mode.checkOutdent("start", " ", "a }"));
|
||||
assertFalse(this.mode.checkOutdent("start", " }", "}"));
|
||||
assert.ok(this.mode.checkOutdent("start", " ", " }"));
|
||||
assert.equal(this.mode.checkOutdent("start", " a ", " }"));
|
||||
assert.equal(this.mode.checkOutdent("start", "", "}"));
|
||||
assert.equal(this.mode.checkOutdent("start", " ", "a }"));
|
||||
assert.equal(this.mode.checkOutdent("start", " }", "}"));
|
||||
},
|
||||
|
||||
"test: auto outdent should indent the line with the same indent as the line with the matching opening brace" : function() {
|
||||
var doc = new Document([" function foo() {", " bla", " }"]);
|
||||
this.mode.autoOutdent("start", doc, 2);
|
||||
assertEquals(" }", doc.getLine(2));
|
||||
assert.equal(" }", doc.getLine(2));
|
||||
},
|
||||
|
||||
"test: no auto outdent if no matching brace is found" : function() {
|
||||
var doc = new Document([" function foo()", " bla", " }"]);
|
||||
this.mode.autoOutdent("start", doc, 2);
|
||||
assertEquals(" }", doc.getLine(2));
|
||||
assert.equal(" }", doc.getLine(2));
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
module.exports = require("async/test").testcase(Test);
|
||||
|
||||
});
|
||||
if (module === require.main)
|
||||
module.exports.exec()
|
||||
|
|
@ -35,15 +35,12 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require.def([
|
||||
"ace/mode/JavaScript"
|
||||
], function(
|
||||
jsMod
|
||||
) {
|
||||
|
||||
var JavaScriptMode = jsMod.JavaScript;
|
||||
var JavaScriptTokenizerTest = new TestCase("mode.JavaScriptTokenizerTest", {
|
||||
require("../../../../support/paths");
|
||||
|
||||
var JavaScriptMode = require("ace/mode/javascript").Mode;
|
||||
var assert = require("../assertions");
|
||||
|
||||
var Test = {
|
||||
setUp : function() {
|
||||
this.tokenizer = new JavaScriptMode().getTokenizer();
|
||||
},
|
||||
|
|
@ -53,10 +50,12 @@ var JavaScriptTokenizerTest = new TestCase("mode.JavaScriptTokenizerTest", {
|
|||
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
assertEquals(3, tokens.length);
|
||||
assertEquals("identifier", tokens[0].type);
|
||||
assertEquals("text", tokens[1].type);
|
||||
assertEquals("keyword", tokens[2].type);
|
||||
assert.equal(5, tokens.length);
|
||||
assert.equal("identifier", tokens[0].type);
|
||||
assert.equal("text", tokens[1].type);
|
||||
assert.equal("keyword.operator", tokens[2].type);
|
||||
assert.equal("text", tokens[3].type);
|
||||
assert.equal("keyword", tokens[4].type);
|
||||
},
|
||||
|
||||
"test: tokenize doc comment" : function() {
|
||||
|
|
@ -64,12 +63,12 @@ var JavaScriptTokenizerTest = new TestCase("mode.JavaScriptTokenizerTest", {
|
|||
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
assertEquals(5, tokens.length);
|
||||
assertEquals("identifier", tokens[0].type);
|
||||
assertEquals("text", tokens[1].type);
|
||||
assertEquals("doc-comment", tokens[2].type);
|
||||
assertEquals("text", tokens[3].type);
|
||||
assertEquals("identifier", tokens[4].type);
|
||||
assert.equal(5, tokens.length);
|
||||
assert.equal("identifier", tokens[0].type);
|
||||
assert.equal("text", tokens[1].type);
|
||||
assert.equal("comment.doc", tokens[2].type);
|
||||
assert.equal("text", tokens[3].type);
|
||||
assert.equal("identifier", tokens[4].type);
|
||||
},
|
||||
|
||||
"test: tokenize doc comment with tag" : function() {
|
||||
|
|
@ -77,10 +76,10 @@ var JavaScriptTokenizerTest = new TestCase("mode.JavaScriptTokenizerTest", {
|
|||
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
assertEquals(3, tokens.length);
|
||||
assertEquals("doc-comment", tokens[0].type);
|
||||
assertEquals("doc-comment-tag", tokens[1].type);
|
||||
assertEquals("doc-comment", tokens[2].type);
|
||||
assert.equal(3, tokens.length);
|
||||
assert.equal("comment.doc", tokens[0].type);
|
||||
assert.equal("comment.doc.tag", tokens[1].type);
|
||||
assert.equal("comment.doc", tokens[2].type);
|
||||
},
|
||||
|
||||
"test: tokenize parens" : function() {
|
||||
|
|
@ -88,11 +87,14 @@ var JavaScriptTokenizerTest = new TestCase("mode.JavaScriptTokenizerTest", {
|
|||
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
assertEquals(3, tokens.length);
|
||||
assertEquals("lparen", tokens[0].type);
|
||||
assertEquals("text", tokens[1].type);
|
||||
assertEquals("rparen", tokens[2].type);
|
||||
assert.equal(3, tokens.length);
|
||||
assert.equal("lparen", tokens[0].type);
|
||||
assert.equal("text", tokens[1].type);
|
||||
assert.equal("rparen", tokens[2].type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
module.exports = require("async/test").testcase(Test);
|
||||
|
||||
if (module === require.main)
|
||||
module.exports.exec()
|
||||
|
|
@ -35,19 +35,13 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require.def([
|
||||
"ace/Document",
|
||||
"ace/Range",
|
||||
"ace/mode/Text"
|
||||
], function(
|
||||
Document,
|
||||
Range,
|
||||
textMod
|
||||
) {
|
||||
require("../../../../support/paths");
|
||||
|
||||
var TextMode = textMod.Text;
|
||||
var TextTest = new TestCase("mode.TextTest", {
|
||||
var Document = require("ace/document").Document;
|
||||
var TextMode = require("ace/mode/text").Mode;
|
||||
var assert = require("../assertions");
|
||||
|
||||
var Test = {
|
||||
setUp : function() {
|
||||
this.mode = new TextMode();
|
||||
},
|
||||
|
|
@ -55,15 +49,17 @@ var TextTest = new TestCase("mode.TextTest", {
|
|||
"test: toggle comment lines should not do anything" : function() {
|
||||
var doc = new Document([" abc", "cde", "fg"]);
|
||||
|
||||
var range = new Range(0, 3, 1, 1);
|
||||
var comment = this.mode.toggleCommentLines("start", doc, range);
|
||||
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
var comment = this.mode.toggleCommentLines("start", doc, 0, 1);
|
||||
assert.equal([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
|
||||
"text: lines should not be indented" : function() {
|
||||
assertEquals("", this.mode.getNextLineIndent("start", " abc", " "));
|
||||
assert.equal("", this.mode.getNextLineIndent("start", " abc", " "));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
module.exports = require("async/test").testcase(Test);
|
||||
|
||||
if (module === require.main)
|
||||
module.exports.exec()
|
||||
|
|
@ -35,21 +35,14 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require.def([
|
||||
"ace/Document",
|
||||
"ace/Range",
|
||||
"ace/Tokenizer",
|
||||
"ace/mode/Xml"
|
||||
], function(
|
||||
Document,
|
||||
Range,
|
||||
Tokenizer,
|
||||
xmlMod
|
||||
) {
|
||||
require("../../../../support/paths");
|
||||
|
||||
var XmlMode = xmlMod.Xml;
|
||||
var XmlTest = new TestCase("mode.XmlTest", {
|
||||
var Document = require("ace/document").Document;
|
||||
var Tokenizer = require("ace/tokenizer").Tokenizer;
|
||||
var XmlMode = require("ace/mode/xml").Mode;
|
||||
var assert = require("../assertions");
|
||||
|
||||
var Test = {
|
||||
setUp : function() {
|
||||
this.mode = new XmlMode();
|
||||
},
|
||||
|
|
@ -57,25 +50,27 @@ var XmlTest = new TestCase("mode.XmlTest", {
|
|||
"test: getTokenizer() (smoke test)" : function() {
|
||||
var tokenizer = this.mode.getTokenizer();
|
||||
|
||||
assertTrue(tokenizer instanceof Tokenizer);
|
||||
assert.ok(tokenizer instanceof Tokenizer);
|
||||
|
||||
var tokens = tokenizer.getLineTokens("<juhu>", "start").tokens;
|
||||
assertEquals("keyword", tokens[1].type);
|
||||
assert.equal("keyword", tokens[1].type);
|
||||
},
|
||||
|
||||
"test: toggle comment lines should not do anything" : function() {
|
||||
var doc = new Document([" abc", "cde", "fg"]);
|
||||
|
||||
var range = new Range(0, 3, 1, 1);
|
||||
var comment = this.mode.toggleCommentLines("start", doc, range);
|
||||
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
var comment = this.mode.toggleCommentLines("start", doc, 0, 1);
|
||||
assert.equal([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: next line indent should be the same as the current line indent" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " abc"));
|
||||
assertEquals("", this.mode.getNextLineIndent("start", "abc"));
|
||||
assertEquals("\t", this.mode.getNextLineIndent("start", "\tabc"));
|
||||
assert.equal(" ", this.mode.getNextLineIndent("start", " abc"));
|
||||
assert.equal("", this.mode.getNextLineIndent("start", "abc"));
|
||||
assert.equal("\t", this.mode.getNextLineIndent("start", "\tabc"));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
module.exports = require("async/test").testcase(Test);
|
||||
|
||||
if (module === require.main)
|
||||
module.exports.exec()
|
||||
|
|
@ -35,15 +35,13 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require.def([
|
||||
"ace/mode/Xml"
|
||||
], function(
|
||||
xmlMod
|
||||
) {
|
||||
|
||||
var XmlMode = xmlMod.Xml;
|
||||
var XmlTest = new TestCase("mode.XmlTest", {
|
||||
require("../../../../support/paths");
|
||||
|
||||
var XmlMode = require("ace/mode/xml").Mode;
|
||||
var assert = require("../assertions");
|
||||
|
||||
var Test = {
|
||||
setUp : function() {
|
||||
this.tokenizer = new XmlMode().getTokenizer();
|
||||
},
|
||||
|
|
@ -53,13 +51,16 @@ var XmlTest = new TestCase("mode.XmlTest", {
|
|||
var line = "<Juhu>//Juhu Kinners</Kinners>";
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
assertEquals(5, tokens.length);
|
||||
assertEquals("text", tokens[0].type);
|
||||
assertEquals("keyword", tokens[1].type);
|
||||
assertEquals("text", tokens[2].type);
|
||||
assertEquals("keyword", tokens[3].type);
|
||||
assertEquals("text", tokens[4].type);
|
||||
assert.equal(5, tokens.length);
|
||||
assert.equal("text", tokens[0].type);
|
||||
assert.equal("keyword", tokens[1].type);
|
||||
assert.equal("text", tokens[2].type);
|
||||
assert.equal("keyword", tokens[3].type);
|
||||
assert.equal("text", tokens[4].type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
module.exports = require("async/test").testcase(Test);
|
||||
|
||||
if (module === require.main)
|
||||
module.exports.exec()
|
||||
|
|
@ -36,21 +36,12 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require("../../../support/paths");
|
||||
require("./mockdom");
|
||||
|
||||
var dom = require('jsdom/level2/html').dom.level2.html;
|
||||
var 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"),
|
||||
var Document = require("../Document").Document,
|
||||
Editor = require("../Editor").Editor,
|
||||
MockRenderer = require("./mockrenderer"),
|
||||
assert = require("./assertions");
|
||||
|
||||
|
||||
var Test = {
|
||||
createTextDocument : function(rows, cols) {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
require("../../../support/paths");
|
||||
|
||||
var Range = require("../range"),
|
||||
var Range = require("../range").Range,
|
||||
assert = require("./assertions");
|
||||
|
||||
var Test = {
|
||||
|
|
@ -144,6 +144,20 @@ var Test = {
|
|||
|
||||
var range = range.extend(6, 10);
|
||||
assert.range(range, 1, 4, 6, 10);
|
||||
},
|
||||
|
||||
"test: collapse rows" : function() {
|
||||
var range = new Range(0, 2, 1, 2);
|
||||
assert.range(range.collapseRows(), 0, 0, 1, 0);
|
||||
|
||||
var range = new Range(2, 2, 3, 1);
|
||||
assert.range(range.collapseRows(), 2, 0, 3, 0);
|
||||
|
||||
var range = new Range(2, 2, 3, 0);
|
||||
assert.range(range.collapseRows(), 2, 0, 2, 0);
|
||||
|
||||
var range = new Range(2, 0, 2, 0);
|
||||
assert.range(range.collapseRows(), 2, 0, 2, 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@
|
|||
|
||||
require("../../../support/paths");
|
||||
|
||||
var Document = require("../document"),
|
||||
Search = require("../search"),
|
||||
var Document = require("../document").Document,
|
||||
Search = require("../search").Search,
|
||||
assert = require("./assertions");
|
||||
|
||||
var Test = {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
require("../../../support/paths");
|
||||
|
||||
var Document = require("../document"),
|
||||
var Document = require("../document").Document,
|
||||
assert = require("./assertions");
|
||||
|
||||
var Test = {
|
||||
|
|
|
|||
|
|
@ -36,19 +36,12 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require("../../../support/paths");
|
||||
require("./mockdom");
|
||||
|
||||
var dom = require('jsdom/level2/html').dom.level2.html;
|
||||
var 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").JavaScript,
|
||||
var Document = require("../document").Document,
|
||||
Editor = require("../editor").Editor,
|
||||
JavaScriptMode = require("../mode/javascript").Mode,
|
||||
UndoManager = require("../undomanager").UndoManager,
|
||||
MockRenderer = require("./mockrenderer"),
|
||||
assert = require("./assertions");
|
||||
|
||||
|
|
@ -112,17 +105,16 @@ var Test = {
|
|||
assert.position(editor.getCursorPosition(), 2, 0);
|
||||
},
|
||||
|
||||
"__test: indent block" : function() {
|
||||
"test: indent block" : function() {
|
||||
var doc = new Document(["a12345", "b12345", "c12345"].join("\n"));
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(1, 3);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.blockIndent(" ");
|
||||
editor.indent();
|
||||
|
||||
assert.equal(["a12345", " b12345", " c12345"].join("\n"),
|
||||
doc.toString());
|
||||
assert.equal(["a12345", " b12345", " c12345"].join("\n"), doc.toString());
|
||||
|
||||
assert.position(editor.getCursorPosition(), 2, 7);
|
||||
|
||||
|
|
@ -131,30 +123,40 @@ var Test = {
|
|||
assert.position(range.end, 2, 7);
|
||||
},
|
||||
|
||||
"__test: outdent block" : function() {
|
||||
"test: indent selected lines" : function() {
|
||||
var doc = new Document(["a12345", "b12345", "c12345"].join("\n"));
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.indent();
|
||||
assert.equal(["a12345", " b12345", "c12345"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: outdent block" : function() {
|
||||
var doc = new Document([" a12345", " b12345", " c12345"].join("\n"));
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(0, 3);
|
||||
editor.getSelection().selectDown();
|
||||
editor.moveCursorTo(0, 5);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.blockOutdent(" ");
|
||||
editor.blockOutdent();
|
||||
assert.equal(doc.toString(), [" a12345", "b12345", " c12345"].join("\n"));
|
||||
|
||||
assert.position(editor.getCursorPosition(), 2, 0);
|
||||
assert.position(editor.getCursorPosition(), 2, 1);
|
||||
|
||||
var range = editor.getSelectionRange();
|
||||
assert.position(range.start, 0, 1);
|
||||
assert.position(range.end, 2, 1);
|
||||
|
||||
|
||||
editor.blockOutdent(" ");
|
||||
editor.blockOutdent();
|
||||
assert.equal(doc.toString(), ["a12345", "b12345", "c12345"].join("\n"));
|
||||
|
||||
var range = editor.getSelectionRange();
|
||||
assert.position(range.start, 0, 1);
|
||||
assert.position(range.end, 2, 1);
|
||||
assert.position(range.start, 0, 0);
|
||||
assert.position(range.end, 2, 0);
|
||||
},
|
||||
|
||||
"test: outent without a selection should update cursor" : function() {
|
||||
|
|
@ -174,7 +176,6 @@ var Test = {
|
|||
|
||||
editor.moveCursorTo(0, 2);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assert.equal(["// abc", "//cde"].join("\n"), doc.toString());
|
||||
|
|
@ -198,6 +199,21 @@ var Test = {
|
|||
assert.equal([" abc", "cde"].join("\n"), doc.toString());
|
||||
assert.range(editor.getSelectionRange(), 0, 0, 1, 1);
|
||||
},
|
||||
|
||||
"test: toggle comment lines twice should return the original text" : function() {
|
||||
var doc = new Document([" abc", "cde", "fg"], new JavaScriptMode());
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assert.equal([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
|
||||
"test: comment lines - if the selection end is at the line start it should stay there": function() {
|
||||
//select down
|
||||
|
|
@ -248,7 +264,7 @@ var Test = {
|
|||
assert.position(editor.getSelection().getSelectionLead(), 2, 0);
|
||||
},
|
||||
|
||||
"__test: move lines up should select moved lines" : function() {
|
||||
"test: move lines up should select moved lines" : function() {
|
||||
var doc = new Document(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
|
|
@ -340,6 +356,49 @@ var Test = {
|
|||
|
||||
editor.onTextInput("\t");
|
||||
assert.equal(doc.toString(), "\t");
|
||||
},
|
||||
|
||||
"test: undo/redo for delete line" : function() {
|
||||
var doc = new Document(["111", "222", "333"]);
|
||||
var undoManager = new UndoManager();
|
||||
doc.setUndoManager(undoManager);
|
||||
|
||||
var initialText = doc.toString();
|
||||
|
||||
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.removeLines();
|
||||
var step1 = doc.toString();
|
||||
assert.equal(step1, "222\n333");
|
||||
doc.$informUndoManager.call();
|
||||
|
||||
editor.removeLines();
|
||||
var step2 = doc.toString();
|
||||
assert.equal(step2, "333");
|
||||
doc.$informUndoManager.call();
|
||||
|
||||
editor.removeLines();
|
||||
var step3 = doc.toString();
|
||||
assert.equal(step3, "");
|
||||
doc.$informUndoManager.call();
|
||||
|
||||
|
||||
undoManager.undo();
|
||||
doc.$informUndoManager.call();
|
||||
assert.equal(doc.toString(), step2);
|
||||
|
||||
undoManager.undo();
|
||||
doc.$informUndoManager.call();
|
||||
assert.equal(doc.toString(), step1);
|
||||
|
||||
undoManager.undo();
|
||||
doc.$informUndoManager.call();
|
||||
assert.equal(doc.toString(), initialText);
|
||||
|
||||
undoManager.undo();
|
||||
doc.$informUndoManager.call();
|
||||
assert.equal(doc.toString(), initialText);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -36,10 +36,11 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require("../../../support/paths");
|
||||
require("./mockdom");
|
||||
|
||||
var Document = "../document",
|
||||
VirtualRenderer = "../virtual_renderer",
|
||||
assert = "../assertions";
|
||||
var Document = require("../document").Document,
|
||||
VirtualRenderer = require("../virtual_renderer").VirtualRenderer,
|
||||
assert = require("./assertions");
|
||||
|
||||
var Test = {
|
||||
"test: screen2text the column should be rounded to the next character edge" : function() {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var event = require("pilot/event").event;
|
||||
var event = require("pilot/event");
|
||||
|
||||
var TextInput = function(parentNode, host) {
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var dom = require("pilot/dom").dom;
|
||||
var dom = require("pilot/dom");
|
||||
|
||||
var cssText = ".ace-clouds .ace_editor {\
|
||||
border: 2px solid rgb(159, 159, 159);\
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var dom = require("pilot/dom").dom;
|
||||
var dom = require("pilot/dom");
|
||||
|
||||
var cssText = ".ace-clouds-midnight .ace_editor {\
|
||||
border: 2px solid rgb(159, 159, 159);\
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var dom = require("pilot/dom").dom;
|
||||
var dom = require("pilot/dom");
|
||||
|
||||
var cssText = ".ace-cobalt .ace_editor {\
|
||||
border: 2px solid rgb(159, 159, 159);\
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var dom = require("pilot/dom").dom;
|
||||
var dom = require("pilot/dom");
|
||||
|
||||
var cssText = ".ace-dawn .ace_editor {\
|
||||
border: 2px solid rgb(159, 159, 159);\
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var dom = require("pilot/dom").dom;
|
||||
var dom = require("pilot/dom");
|
||||
var cssText = require("text!ace/theme/eclipse.css");
|
||||
|
||||
// import CSS once
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var dom = require("pilot/dom").dom;
|
||||
var dom = require("pilot/dom");
|
||||
|
||||
var cssText = ".ace-idle-fingers .ace_editor {\
|
||||
border: 2px solid rgb(159, 159, 159);\
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var dom = require("pilot/dom").dom;
|
||||
var dom = require("pilot/dom");
|
||||
|
||||
var cssText = ".ace-kr-theme .ace_editor {\
|
||||
border: 2px solid rgb(159, 159, 159);\
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var dom = require("pilot/dom").dom;
|
||||
var dom = require("pilot/dom");
|
||||
|
||||
var cssText = ".ace-mono-industrial .ace_editor {\
|
||||
border: 2px solid rgb(159, 159, 159);\
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var dom = require("pilot/dom").dom;
|
||||
var dom = require("pilot/dom");
|
||||
|
||||
var cssText = ".ace-monokai .ace_editor {\
|
||||
border: 2px solid rgb(159, 159, 159);\
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var dom = require("pilot/dom").dom;
|
||||
var dom = require("pilot/dom");
|
||||
var cssText = require("text!ace/theme/tm.css");
|
||||
|
||||
// import CSS once
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var dom = require("pilot/dom").dom;
|
||||
var dom = require("pilot/dom");
|
||||
|
||||
var cssText = ".ace-twilight .ace_editor {\
|
||||
border: 2px solid rgb(159, 159, 159);\
|
||||
|
|
|
|||
|
|
@ -77,8 +77,6 @@ var Tokenizer = function(rules) {
|
|||
if (re.lastIndex == lastIndex) { throw new Error("tokenizer error"); }
|
||||
lastIndex = re.lastIndex;
|
||||
|
||||
window.LOG && console.log(currentState, match);
|
||||
|
||||
for ( var i = 0; i < state.length; i++) {
|
||||
if (match[i + 1]) {
|
||||
if (typeof state[i].token == "function") {
|
||||
|
|
@ -118,8 +116,6 @@ var Tokenizer = function(rules) {
|
|||
tokens.push(token);
|
||||
}
|
||||
|
||||
window.LOG && console.log(tokens, currentState);
|
||||
|
||||
return {
|
||||
tokens : tokens,
|
||||
state : currentState
|
||||
|
|
|
|||
|
|
@ -37,10 +37,9 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("pilot/oop").oop;
|
||||
var lang = require("pilot/lang").lang;
|
||||
var dom = require("pilot/dom").dom;
|
||||
var event = require("pilot/event").event;
|
||||
var oop = require("pilot/oop");
|
||||
var dom = require("pilot/dom");
|
||||
var event = require("pilot/event");
|
||||
var GutterLayer = require("ace/layer/gutter").Gutter;
|
||||
var MarkerLayer = require("ace/layer/marker").Marker;
|
||||
var TextLayer = require("ace/layer/text").Text;
|
||||
|
|
@ -85,7 +84,7 @@ var VirtualRenderer = function(container, theme) {
|
|||
this.layers = [ this.$markerLayer, textLayer, this.$cursorLayer ];
|
||||
|
||||
this.scrollBar = new ScrollBar(container);
|
||||
this.scrollBar.addEventListener("scroll", lang.bind(this.onScroll, this));
|
||||
this.scrollBar.addEventListener("scroll", this.onScroll.bind(this));
|
||||
|
||||
this.scrollTop = 0;
|
||||
|
||||
|
|
@ -101,8 +100,8 @@ var VirtualRenderer = function(container, theme) {
|
|||
|
||||
self.$loop.schedule(self.CHANGE_FULL);
|
||||
});
|
||||
event.addListener(this.$gutter, "click", lang.bind(this.$onGutterClick, this));
|
||||
event.addListener(this.$gutter, "dblclick", lang.bind(this.$onGutterClick, this));
|
||||
event.addListener(this.$gutter, "click", this.$onGutterClick.bind(this));
|
||||
event.addListener(this.$gutter, "dblclick", this.$onGutterClick.bind(this));
|
||||
|
||||
this.$size = {
|
||||
width: 0,
|
||||
|
|
@ -111,7 +110,7 @@ var VirtualRenderer = function(container, theme) {
|
|||
scrollerWidth: 0
|
||||
};
|
||||
|
||||
this.$loop = new RenderLoop(lang.bind(this.$renderChanges, this));
|
||||
this.$loop = new RenderLoop(this.$renderChanges.bind(this));
|
||||
this.$loop.schedule(this.CHANGE_FULL);
|
||||
|
||||
this.$updatePrintMargin();
|
||||
|
|
@ -185,7 +184,7 @@ var VirtualRenderer = function(container, theme) {
|
|||
* Triggers resize of the editor
|
||||
*/
|
||||
this.onResize = function() {
|
||||
this.$loop.schedule(this.CHANGE_SIZE);
|
||||
var changes = this.CHANGE_SIZE;
|
||||
|
||||
var height = dom.getInnerHeight(this.container);
|
||||
if (this.$size.height != height) {
|
||||
|
|
@ -196,7 +195,7 @@ var VirtualRenderer = function(container, theme) {
|
|||
|
||||
if (this.doc) {
|
||||
this.scrollToY(this.getScrollTop());
|
||||
this.$loop.schedule(this.CHANGE_FULL);
|
||||
changes = changes | this.CHANGE_FULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -211,6 +210,7 @@ var VirtualRenderer = function(container, theme) {
|
|||
|
||||
this.$size.scrollerWidth = this.scroller.clientWidth;
|
||||
this.$size.scrollerHeight = this.scroller.clientHeight;
|
||||
this.$loop.schedule(changes);
|
||||
};
|
||||
|
||||
this.setTokenizer = function(tokenizer) {
|
||||
|
|
@ -373,7 +373,8 @@ var VirtualRenderer = function(container, theme) {
|
|||
else if (changes & this.CHANGE_LINES) {
|
||||
this.$updateLines();
|
||||
this.$updateScrollBar();
|
||||
} if (changes & this.CHANGE_GUTTER) {
|
||||
this.showGutter && this.$gutterLayer.update(this.layerConfig);
|
||||
} else if (changes & this.CHANGE_GUTTER) {
|
||||
this.showGutter && this.$gutterLayer.update(this.layerConfig);
|
||||
}
|
||||
|
||||
|
|
@ -397,7 +398,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,
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ define(function(require, exports, module) {
|
|||
|
||||
var console = require('pilot/console');
|
||||
var util = require('pilot/util');
|
||||
var oop = require('pilot/oop').oop;
|
||||
var oop = require('pilot/oop');
|
||||
var EventEmitter = require('pilot/event_emitter').EventEmitter;
|
||||
|
||||
//var keyboard = require('keyboard/keyboard');
|
||||
|
|
@ -480,9 +480,11 @@ var commandParam = {
|
|||
* The event object looks like { command: A }
|
||||
* @constructor
|
||||
*/
|
||||
function Requisition() {
|
||||
function Requisition(env) {
|
||||
this.env = env;
|
||||
this.commandAssignment = new Assignment(commandParam, this);
|
||||
}
|
||||
|
||||
Requisition.prototype = {
|
||||
/**
|
||||
* The command that we are about to execute.
|
||||
|
|
@ -672,8 +674,9 @@ exports.Requisition = Requisition;
|
|||
* if not specified.
|
||||
* @constructor
|
||||
*/
|
||||
function CliRequisition(options) {
|
||||
Requisition.call(this);
|
||||
function CliRequisition(env, options) {
|
||||
Requisition.call(this, env);
|
||||
|
||||
if (options && options.flags) {
|
||||
/**
|
||||
* TODO: We were using a default of keyboard.buildFlags({ });
|
||||
|
|
@ -37,10 +37,9 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
|
||||
var console = require('pilot/console');
|
||||
var Trace = require('pilot/stacktrace').Trace;
|
||||
var oop = require('pilot/oop').oop;
|
||||
var oop = require('pilot/oop');
|
||||
var EventEmitter = require('pilot/event_emitter').EventEmitter;
|
||||
var catalog = require('pilot/catalog');
|
||||
var Status = require('pilot/types').Status;
|
||||
|
|
@ -71,11 +70,8 @@ var commandExtensionSpec = {
|
|||
indexOn: 'name'
|
||||
};
|
||||
|
||||
var env;
|
||||
|
||||
exports.startup = function(data, reason) {
|
||||
// TODO: this is probably all kinds of evil, but we need something working
|
||||
env = data.env;
|
||||
catalog.addExtensionSpec(commandExtensionSpec);
|
||||
};
|
||||
|
||||
|
|
@ -173,8 +169,7 @@ function getCommandNames() {
|
|||
* everything it needs to about the command params
|
||||
* @param command Either a command, or the name of one
|
||||
*/
|
||||
function exec(command, args, typed) {
|
||||
// TODO: Use requisition.toString rather than 'typed'
|
||||
function exec(command, env, args, typed) {
|
||||
if (typeof command === 'string') {
|
||||
command = commands[command];
|
||||
}
|
||||
|
|
@ -66,7 +66,7 @@ if (typeof(window) === 'undefined') {
|
|||
// For each of the console functions, copy them if they exist, stub if not
|
||||
NAMES.forEach(function(name) {
|
||||
if (window.console && window.console[name]) {
|
||||
exports[name] = window.console[name].bind(window.console);
|
||||
exports[name] = Function.prototype.bind.call(window.console[name], window.console);
|
||||
} else {
|
||||
exports[name] = noop;
|
||||
}
|
||||
|
|
@ -37,27 +37,25 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var core = {};
|
||||
var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
|
||||
var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
|
||||
|
||||
core.isWin = (os == "win");
|
||||
core.isMac = (os == "mac");
|
||||
core.isLinux = (os == "linux");
|
||||
core.isIE = ! + "\v1";
|
||||
core.isGecko = window.controllers && window.navigator.product === "Gecko";
|
||||
exports.isWin = (os == "win");
|
||||
exports.isMac = (os == "mac");
|
||||
exports.isLinux = (os == "linux");
|
||||
exports.isIE = ! + "\v1";
|
||||
exports.isGecko = window.controllers && window.navigator.product === "Gecko";
|
||||
exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";
|
||||
|
||||
core.provide = function(namespace) {
|
||||
var parts = namespace.split(".");
|
||||
var obj = window;
|
||||
for (var i=0; i<parts.length; i++) {
|
||||
var part = parts[i];
|
||||
if (!obj[part]) {
|
||||
obj[part] = {};
|
||||
}
|
||||
obj = obj[part];
|
||||
exports.provide = function(namespace) {
|
||||
var parts = namespace.split(".");
|
||||
var obj = window;
|
||||
for (var i=0; i<parts.length; i++) {
|
||||
var part = parts[i];
|
||||
if (!obj[part]) {
|
||||
obj[part] = {};
|
||||
}
|
||||
};
|
||||
|
||||
exports.core = core;
|
||||
obj = obj[part];
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
136
plugins/pilot/dom.js
Normal file
136
plugins/pilot/dom.js
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
/* ***** 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) {
|
||||
|
||||
exports.setText = function(elem, text) {
|
||||
if (elem.innerText !== undefined) {
|
||||
elem.innerText = text;
|
||||
}
|
||||
if (elem.textContent !== undefined) {
|
||||
elem.textContent = text;
|
||||
}
|
||||
};
|
||||
|
||||
exports.hasCssClass = function(el, name) {
|
||||
var classes = el.className.split(/\s+/g);
|
||||
return classes.indexOf(name) !== -1;
|
||||
};
|
||||
|
||||
exports.addCssClass = function(el, name) {
|
||||
if (!exports.hasCssClass(el, name)) {
|
||||
el.className += " " + name;
|
||||
}
|
||||
};
|
||||
|
||||
exports.removeCssClass = function(el, name) {
|
||||
var classes = el.className.split(/\s+/g);
|
||||
while (true) {
|
||||
var index = classes.indexOf(name);
|
||||
if (index == -1) {
|
||||
break;
|
||||
}
|
||||
classes.splice(index, 1);
|
||||
}
|
||||
el.className = classes.join(" ");
|
||||
};
|
||||
|
||||
exports.importCssString = function(cssText, doc){
|
||||
doc = doc || document;
|
||||
|
||||
if (doc.createStyleSheet) {
|
||||
var sheet = doc.createStyleSheet();
|
||||
sheet.cssText = cssText;
|
||||
}
|
||||
else {
|
||||
var style = doc.createElement("style");
|
||||
style.appendChild(doc.createTextNode(cssText));
|
||||
doc.getElementsByTagName("head")[0].appendChild(style);
|
||||
}
|
||||
};
|
||||
|
||||
exports.getInnerWidth = function(element) {
|
||||
return (parseInt(exports.computedStyle(element, "paddingLeft"))
|
||||
+ parseInt(exports.computedStyle(element, "paddingRight")) + element.clientWidth);
|
||||
};
|
||||
|
||||
exports.getInnerHeight = function(element) {
|
||||
return (parseInt(exports.computedStyle(element, "paddingTop"))
|
||||
+ parseInt(exports.computedStyle(element, "paddingBottom")) + element.clientHeight);
|
||||
};
|
||||
|
||||
exports.computedStyle = function(element, style) {
|
||||
if (window.getComputedStyle) {
|
||||
return (window.getComputedStyle(element, "") || {})[style] || "";
|
||||
}
|
||||
else {
|
||||
return element.currentStyle[style];
|
||||
}
|
||||
};
|
||||
|
||||
exports.scrollbarWidth = function() {
|
||||
|
||||
var inner = document.createElement('p');
|
||||
inner.style.width = "100%";
|
||||
inner.style.height = "200px";
|
||||
|
||||
var outer = document.createElement("div");
|
||||
var style = outer.style;
|
||||
|
||||
style.position = "absolute";
|
||||
style.left = "-10000px";
|
||||
style.overflow = "hidden";
|
||||
style.width = "200px";
|
||||
style.height = "150px";
|
||||
|
||||
outer.appendChild(inner);
|
||||
document.body.appendChild(outer);
|
||||
var noScrollbar = inner.offsetWidth;
|
||||
|
||||
style.overflow = "scroll";
|
||||
var withScrollbar = inner.offsetWidth;
|
||||
|
||||
if (noScrollbar == withScrollbar) {
|
||||
withScrollbar = outer.clientWidth;
|
||||
}
|
||||
|
||||
document.body.removeChild(outer);
|
||||
|
||||
return noScrollbar-withScrollbar;
|
||||
};
|
||||
|
||||
});
|
||||
239
plugins/pilot/event.js
Normal file
239
plugins/pilot/event.js
Normal file
|
|
@ -0,0 +1,239 @@
|
|||
/* ***** 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 core = require("pilot/core");
|
||||
|
||||
exports.addListener = function(elem, type, callback) {
|
||||
if (elem.addEventListener) {
|
||||
return elem.addEventListener(type, callback, false);
|
||||
}
|
||||
if (elem.attachEvent) {
|
||||
var wrapper = function() {
|
||||
callback(window.event);
|
||||
};
|
||||
callback._wrapper = wrapper;
|
||||
elem.attachEvent("on" + type, wrapper);
|
||||
}
|
||||
};
|
||||
|
||||
exports.removeListener = function(elem, type, callback) {
|
||||
if (elem.removeEventListener) {
|
||||
return elem.removeEventListener(type, callback, false);
|
||||
}
|
||||
if (elem.detachEvent) {
|
||||
elem.detachEvent("on" + type, callback._wrapper || callback);
|
||||
}
|
||||
};
|
||||
|
||||
exports.stopEvent = function(e) {
|
||||
exports.stopPropagation(e);
|
||||
exports.preventDefault(e);
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.stopPropagation = function(e) {
|
||||
if (e.stopPropagation)
|
||||
e.stopPropagation();
|
||||
else
|
||||
e.cancelBubble = true;
|
||||
};
|
||||
|
||||
exports.preventDefault = function(e) {
|
||||
if (e.preventDefault)
|
||||
e.preventDefault();
|
||||
else
|
||||
e.returnValue = false;
|
||||
};
|
||||
|
||||
exports.getDocumentX = function(e) {
|
||||
if (e.clientX) {
|
||||
var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
|
||||
return e.clientX + scrollLeft;
|
||||
} else {
|
||||
return e.pageX;
|
||||
}
|
||||
};
|
||||
|
||||
exports.getDocumentY = function(e) {
|
||||
if (e.clientY) {
|
||||
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
|
||||
return e.clientY + scrollTop;
|
||||
} else {
|
||||
return e.pageX;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {Number} 0 for left button, 1 for middle button, 2 for right button
|
||||
*/
|
||||
exports.getButton = function(e) {
|
||||
// DOM Event
|
||||
if (e.preventDefault) {
|
||||
return e.button;
|
||||
}
|
||||
// old IE
|
||||
else {
|
||||
return Math.max(e.button - 1, 2);
|
||||
}
|
||||
};
|
||||
|
||||
if (document.documentElement.setCapture) {
|
||||
exports.capture = function(el, eventHandler, releaseCaptureHandler) {
|
||||
function onMouseMove(e) {
|
||||
eventHandler(e);
|
||||
return exports.stopPropagation(e);
|
||||
}
|
||||
|
||||
function onReleaseCapture(e) {
|
||||
eventHandler && eventHandler(e);
|
||||
releaseCaptureHandler && releaseCaptureHandler();
|
||||
|
||||
exports.removeListener(el, "mousemove", eventHandler);
|
||||
exports.removeListener(el, "mouseup", onReleaseCapture);
|
||||
exports.removeListener(el, "losecapture", onReleaseCapture);
|
||||
|
||||
el.releaseCapture();
|
||||
}
|
||||
|
||||
exports.addListener(el, "mousemove", eventHandler);
|
||||
exports.addListener(el, "mouseup", onReleaseCapture);
|
||||
exports.addListener(el, "losecapture", onReleaseCapture);
|
||||
el.setCapture();
|
||||
};
|
||||
}
|
||||
else {
|
||||
exports.capture = function(el, eventHandler, releaseCaptureHandler) {
|
||||
function onMouseMove(e) {
|
||||
eventHandler(e);
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
function onMouseUp(e) {
|
||||
eventHandler && eventHandler(e);
|
||||
releaseCaptureHandler && releaseCaptureHandler();
|
||||
|
||||
el.removeEventListener("mousemove", onMouseMove, true);
|
||||
el.removeEventListener("mouseup", onMouseUp, true);
|
||||
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
el.addEventListener("mousemove", onMouseMove, true);
|
||||
el.addEventListener("mouseup", onMouseUp, true);
|
||||
};
|
||||
}
|
||||
|
||||
exports.addMouseWheelListener = function(el, callback) {
|
||||
var listener = function(e) {
|
||||
if (e.wheelDelta !== undefined) {
|
||||
if (e.wheelDeltaX !== undefined) {
|
||||
e.wheelX = -e.wheelDeltaX / 8;
|
||||
e.wheelY = -e.wheelDeltaY / 8;
|
||||
} else {
|
||||
e.wheelX = 0;
|
||||
e.wheelY = -e.wheelDelta / 8;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
|
||||
e.wheelX = (e.detail || 0) * 5;
|
||||
e.wheelY = 0;
|
||||
} else {
|
||||
e.wheelX = 0;
|
||||
e.wheelY = (e.detail || 0) * 5;
|
||||
}
|
||||
}
|
||||
callback(e);
|
||||
};
|
||||
exports.addListener(el, "DOMMouseScroll", listener);
|
||||
exports.addListener(el, "mousewheel", listener);
|
||||
};
|
||||
|
||||
exports.addMultiMouseDownListener = function(el, button, count, timeout, callback) {
|
||||
var clicks = 0;
|
||||
var startX, startY;
|
||||
|
||||
var listener = function(e) {
|
||||
clicks += 1;
|
||||
if (clicks == 1) {
|
||||
startX = e.clientX;
|
||||
startY = e.clientY;
|
||||
|
||||
setTimeout(function() {
|
||||
clicks = 0;
|
||||
}, timeout || 600);
|
||||
}
|
||||
|
||||
if (exports.getButton(e) != button
|
||||
|| Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5)
|
||||
clicks = 0;
|
||||
|
||||
if (clicks == count) {
|
||||
clicks = 0;
|
||||
callback(e);
|
||||
}
|
||||
return exports.preventDefault(e);
|
||||
};
|
||||
|
||||
exports.addListener(el, "mousedown", listener);
|
||||
core.isIE && exports.addListener(el, "dblclick", listener);
|
||||
};
|
||||
|
||||
exports.addKeyListener = function(el, callback) {
|
||||
var lastDown = null;
|
||||
|
||||
exports.addListener(el, "keydown", function(e) {
|
||||
lastDown = e.keyIdentifier || e.keyCode;
|
||||
return callback(e);
|
||||
});
|
||||
|
||||
// repeated keys are fired as keypress and not keydown events
|
||||
if (core.isMac && (core.isGecko || core.isOpera)) {
|
||||
exports.addListener(el, "keypress", function(e) {
|
||||
var keyId = e.keyIdentifier || e.keyCode;
|
||||
if (lastDown !== keyId) {
|
||||
return callback(e);
|
||||
} else {
|
||||
lastDown = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
|
|
@ -37,8 +37,6 @@
|
|||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var lang = require('pilot/lang').lang;
|
||||
|
||||
var EventEmitter = {};
|
||||
|
||||
EventEmitter._dispatchEvent = function(eventName, e) {
|
||||
|
|
@ -63,7 +61,7 @@ EventEmitter.addEventListener = function(eventName, callback) {
|
|||
if (!listeners) {
|
||||
var listeners = this._eventRegistry[eventName] = [];
|
||||
}
|
||||
if (lang.arrayIndexOf(listeners, callback) == -1) {
|
||||
if (listeners.indexOf(callback) == -1) {
|
||||
listeners.push(callback);
|
||||
}
|
||||
};
|
||||
|
|
@ -75,7 +73,7 @@ EventEmitter.removeEventListener = function(eventName, callback) {
|
|||
if (!listeners) {
|
||||
return;
|
||||
}
|
||||
var index = lang.arrayIndexOf(listeners, callback);
|
||||
var index = listeners.indexOf(callback);
|
||||
if (index !== -1) {
|
||||
listeners.splice(index, 1);
|
||||
}
|
||||
164
plugins/pilot/fixoldbrowsers.js
Normal file
164
plugins/pilot/fixoldbrowsers.js
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
/* ***** 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 Mozilla Skywriter.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Kevin Dangoor (kdangoor@mozilla.com)
|
||||
*
|
||||
* 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) {
|
||||
|
||||
/**
|
||||
* Array detector.
|
||||
* Firefox 3.5 and Safari 4 have this already. Chrome 4 however ...
|
||||
* Note to Dojo - your isArray is still broken: instanceof doesn't work with
|
||||
* Arrays taken from a different frame/window.
|
||||
*/
|
||||
if (!Array.isArray) {
|
||||
Array.isArray = function(data) {
|
||||
return data && Object.prototype.toString.call(data) === "[object Array]";
|
||||
};
|
||||
}
|
||||
|
||||
// from MDC
|
||||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
|
||||
if (!Array.prototype.indexOf)
|
||||
{
|
||||
Array.prototype.indexOf = function(searchElement /*, fromIndex */)
|
||||
{
|
||||
if (this === void 0 || this === null)
|
||||
throw new TypeError();
|
||||
|
||||
var t = Object(this);
|
||||
var len = t.length >>> 0;
|
||||
if (len === 0)
|
||||
return -1;
|
||||
|
||||
var n = 0;
|
||||
if (arguments.length > 0) {
|
||||
n = Number(arguments[1]);
|
||||
if (n !== n)
|
||||
n = 0;
|
||||
else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0))
|
||||
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
||||
}
|
||||
|
||||
if (n >= len)
|
||||
return -1;
|
||||
|
||||
var k = n >= 0
|
||||
? n
|
||||
: Math.max(len - Math.abs(n), 0);
|
||||
|
||||
for (; k < len; k++) {
|
||||
if (k in t && t[k] === searchElement)
|
||||
return k;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
|
||||
// from MDC
|
||||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach
|
||||
if (!Array.prototype.forEach) {
|
||||
Array.prototype.forEach = function(fun /*, thisp */) {
|
||||
if (this === void 0 || this === null)
|
||||
throw new TypeError();
|
||||
|
||||
var t = Object(this);
|
||||
var len = t.length >>> 0;
|
||||
if (typeof fun !== "function")
|
||||
throw new TypeError();
|
||||
|
||||
var thisp = arguments[1];
|
||||
for (var i = 0; i < len; i++) {
|
||||
if (i in t)
|
||||
fun.call(thisp, t[i], i, t);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the list of keys on an object.
|
||||
*/
|
||||
if (!Object.keys) {
|
||||
Object.keys = function(obj) {
|
||||
var k, ret = [];
|
||||
for (k in obj) {
|
||||
if (obj.hasOwnProperty(k)) {
|
||||
ret.push(k);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
|
||||
if (!Function.prototype.bind) {
|
||||
// from MDC
|
||||
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
|
||||
Function.prototype.bind = function (obj) {
|
||||
var slice = [].slice;
|
||||
var args = slice.call(arguments, 1);
|
||||
var self = this;
|
||||
var nop = function () {};
|
||||
|
||||
// optimize common case
|
||||
if (arguments.length == 1) {
|
||||
var bound = function() {
|
||||
return self.apply(this instanceof nop ? this : obj, arguments);
|
||||
};
|
||||
}
|
||||
else {
|
||||
var bound = function () {
|
||||
return self.apply(
|
||||
this instanceof nop ? this : ( obj || {} ),
|
||||
args.concat( slice.call(arguments) )
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
nop.prototype = self.prototype;
|
||||
bound.prototype = new nop();
|
||||
|
||||
// From Narwhal
|
||||
bound.name = this.name;
|
||||
bound.displayName = this.displayName;
|
||||
bound.length = this.length;
|
||||
bound.unbound = self;
|
||||
|
||||
return bound;
|
||||
};
|
||||
}
|
||||
|
||||
exports.globalsLoaded = true;
|
||||
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue