From 921bbe894968877f3f6c050aec13298e646ce21a Mon Sep 17 00:00:00 2001 From: Colin Gourlay Date: Thu, 9 Dec 2010 06:34:56 +0800 Subject: [PATCH 01/44] Added Python syntax support --- lib/ace/mode/Python.js | 87 ++++++++++++++++ lib/ace/mode/PythonHighlightRules.js | 147 +++++++++++++++++++++++++++ 2 files changed, 234 insertions(+) create mode 100644 lib/ace/mode/Python.js create mode 100644 lib/ace/mode/PythonHighlightRules.js diff --git a/lib/ace/mode/Python.js b/lib/ace/mode/Python.js new file mode 100644 index 00000000..a5df5c02 --- /dev/null +++ b/lib/ace/mode/Python.js @@ -0,0 +1,87 @@ +/** + * Ajax.org Code Editor (ACE) + * + * @copyright 2010, Ajax.org Services B.V. + * @license LGPLv3 + * @author Fabian Jakobs + */ +require.def("ace/mode/Python", + [ + "ace/lib/oop", + "ace/mode/Text", + "ace/Tokenizer", + "ace/mode/PythonHighlightRules", + "ace/mode/MatchingBraceOutdent", + "ace/Range" + ], function(oop, TextMode, Tokenizer, PythonHighlightRules, MatchingBraceOutdent, Range) { + +var Python = function() { + this.$tokenizer = new Tokenizer(new PythonHighlightRules().getRules()); + this.$outdent = new MatchingBraceOutdent(); +}; +oop.inherits(Python, TextMode); + +(function() { + + this.toggleCommentLines = function(state, doc, range) { + var outdent = true; + var outentedRows = []; + var re = /^(\s*)#/; + + for (var i=range.start.row; i<= range.end.row; i++) { + if (!re.test(doc.getLine(i))) { + outdent = false; + break; + } + } + + if (outdent) { + var deleteRange = new Range(0, 0, 0, 0); + for (var i=range.start.row; i<= range.end.row; i++) + { + var line = doc.getLine(i).replace(re, "$1"); + deleteRange.start.row = i; + deleteRange.end.row = i; + deleteRange.end.column = line.length + 2; + doc.replace(deleteRange, line); + } + return -2; + } + else { + return doc.indentRows(range, "#"); + } + }; + + this.getNextLineIndent = function(state, line, tab) { + var indent = this.$getIndent(line); + + var tokenizedLine = this.$tokenizer.getLineTokens(line, state); + var tokens = tokenizedLine.tokens; + var endState = tokenizedLine.state; + + if (tokens.length && tokens[tokens.length-1].type == "comment") { + return indent; + } + + if (state == "start") { + var match = line.match(/^.*[\{\(\[\:]\s*$/); + if (match) { + indent += tab; + } + } + + return indent; + }; + + this.checkOutdent = function(state, line, input) { + return this.$outdent.checkOutdent(line, input); + }; + + this.autoOutdent = function(state, doc, row) { + return this.$outdent.autoOutdent(doc, row); + }; + +}).call(Python.prototype); + +return Python; +}); diff --git a/lib/ace/mode/PythonHighlightRules.js b/lib/ace/mode/PythonHighlightRules.js new file mode 100644 index 00000000..aa5797cb --- /dev/null +++ b/lib/ace/mode/PythonHighlightRules.js @@ -0,0 +1,147 @@ +/** + * Ajax.org Code Editor (ACE) + * + * @copyright 2010, Ajax.org Services B.V. + * @license LGPLv3 + * @author Fabian Jakobs + * + * TODO: python delimiters + */ +require.def("ace/mode/PythonHighlightRules", + [ + "ace/lib/oop", + "ace/lib/lang", + "ace/mode/TextHighlightRules" + ], function(oop, lang, 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); + +return PythonHighlightRules; +}); \ No newline at end of file From d566212191baa230507d9884d6a51ce4a7fd5134 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 9 Dec 2010 10:36:43 +0100 Subject: [PATCH 02/44] use lower case file names step #1 --- lib/ace/mode/Python.js | 87 ------------- lib/ace/mode/_python.js | 116 ++++++++++++++++++ ...ightRules.js => python_highlight_rules.js} | 53 ++++++-- 3 files changed, 157 insertions(+), 99 deletions(-) delete mode 100644 lib/ace/mode/Python.js create mode 100644 lib/ace/mode/_python.js rename lib/ace/mode/{PythonHighlightRules.js => python_highlight_rules.js} (71%) diff --git a/lib/ace/mode/Python.js b/lib/ace/mode/Python.js deleted file mode 100644 index a5df5c02..00000000 --- a/lib/ace/mode/Python.js +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Ajax.org Code Editor (ACE) - * - * @copyright 2010, Ajax.org Services B.V. - * @license LGPLv3 - * @author Fabian Jakobs - */ -require.def("ace/mode/Python", - [ - "ace/lib/oop", - "ace/mode/Text", - "ace/Tokenizer", - "ace/mode/PythonHighlightRules", - "ace/mode/MatchingBraceOutdent", - "ace/Range" - ], function(oop, TextMode, Tokenizer, PythonHighlightRules, MatchingBraceOutdent, Range) { - -var Python = function() { - this.$tokenizer = new Tokenizer(new PythonHighlightRules().getRules()); - this.$outdent = new MatchingBraceOutdent(); -}; -oop.inherits(Python, TextMode); - -(function() { - - this.toggleCommentLines = function(state, doc, range) { - var outdent = true; - var outentedRows = []; - var re = /^(\s*)#/; - - for (var i=range.start.row; i<= range.end.row; i++) { - if (!re.test(doc.getLine(i))) { - outdent = false; - break; - } - } - - if (outdent) { - var deleteRange = new Range(0, 0, 0, 0); - for (var i=range.start.row; i<= range.end.row; i++) - { - var line = doc.getLine(i).replace(re, "$1"); - deleteRange.start.row = i; - deleteRange.end.row = i; - deleteRange.end.column = line.length + 2; - doc.replace(deleteRange, line); - } - return -2; - } - else { - return doc.indentRows(range, "#"); - } - }; - - this.getNextLineIndent = function(state, line, tab) { - var indent = this.$getIndent(line); - - var tokenizedLine = this.$tokenizer.getLineTokens(line, state); - var tokens = tokenizedLine.tokens; - var endState = tokenizedLine.state; - - if (tokens.length && tokens[tokens.length-1].type == "comment") { - return indent; - } - - if (state == "start") { - var match = line.match(/^.*[\{\(\[\:]\s*$/); - if (match) { - indent += tab; - } - } - - return indent; - }; - - this.checkOutdent = function(state, line, input) { - return this.$outdent.checkOutdent(line, input); - }; - - this.autoOutdent = function(state, doc, row) { - return this.$outdent.autoOutdent(doc, row); - }; - -}).call(Python.prototype); - -return Python; -}); diff --git a/lib/ace/mode/_python.js b/lib/ace/mode/_python.js new file mode 100644 index 00000000..d1e9a6bd --- /dev/null +++ b/lib/ace/mode/_python.js @@ -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 +* +* Alternatively, the contents of this file may be used under the terms of +* either the GNU General Public License Version 2 or later (the "GPL"), or +* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +* in which case the provisions of the GPL or the LGPL are applicable instead +* of those above. If you wish to allow use of your version of this file only +* under the terms of either the GPL or the LGPL, and not to allow others to +* use your version of this file under the terms of the MPL, indicate your +* decision by deleting the provisions above and replace them with the notice +* and other provisions required by the GPL or the LGPL. If you do not delete +* the provisions above, a recipient may use your version of this file under +* the terms of any one of the MPL, the GPL or the LGPL. +* +* ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { + +var oop = require("../lib/oop"); +var TextMode = require("./text"); +var Tokenizer = require("../tokenizer"); +var PythonHighlightRules = require("./python_highlight_rules"); +var MatchingBraceOutdent = require("./matching_brace_outdent"); +var Range = require("../range"); + +var Python = function() { + this.$tokenizer = new Tokenizer(new PythonHighlightRules().getRules()); + this.$outdent = new MatchingBraceOutdent(); +}; +oop.inherits(Python, TextMode); + +(function() { + + this.toggleCommentLines = function(state, doc, range) { + var outdent = true; + var outentedRows = []; + var re = /^(\s*)#/; + + for (var i=range.start.row; i<= range.end.row; i++) { + if (!re.test(doc.getLine(i))) { + outdent = false; + break; + } + } + + if (outdent) { + var deleteRange = new Range(0, 0, 0, 0); + for (var i=range.start.row; i<= range.end.row; i++) + { + var line = doc.getLine(i).replace(re, "$1"); + deleteRange.start.row = i; + deleteRange.end.row = i; + deleteRange.end.column = line.length + 2; + doc.replace(deleteRange, line); + } + return -2; + } + else { + return doc.indentRows(range, "#"); + } + }; + + this.getNextLineIndent = function(state, line, tab) { + var indent = this.$getIndent(line); + + var tokenizedLine = this.$tokenizer.getLineTokens(line, state); + var tokens = tokenizedLine.tokens; + var endState = tokenizedLine.state; + + if (tokens.length && tokens[tokens.length-1].type == "comment") { + return indent; + } + + if (state == "start") { + var match = line.match(/^.*[\{\(\[\:]\s*$/); + if (match) { + indent += tab; + } + } + + return indent; + }; + + this.checkOutdent = function(state, line, input) { + return this.$outdent.checkOutdent(line, input); + }; + + this.autoOutdent = function(state, doc, row) { + return this.$outdent.autoOutdent(doc, row); + }; + +}).call(Python.prototype); + +return Python; +}); diff --git a/lib/ace/mode/PythonHighlightRules.js b/lib/ace/mode/python_highlight_rules.js similarity index 71% rename from lib/ace/mode/PythonHighlightRules.js rename to lib/ace/mode/python_highlight_rules.js index aa5797cb..57053e8c 100644 --- a/lib/ace/mode/PythonHighlightRules.js +++ b/lib/ace/mode/python_highlight_rules.js @@ -1,19 +1,48 @@ -/** - * Ajax.org Code Editor (ACE) +/* ***** 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 + * + * 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 ***** * - * @copyright 2010, Ajax.org Services B.V. - * @license LGPLv3 - * @author Fabian Jakobs - * * TODO: python delimiters */ -require.def("ace/mode/PythonHighlightRules", - [ - "ace/lib/oop", - "ace/lib/lang", - "ace/mode/TextHighlightRules" - ], function(oop, lang, TextHighlightRules) { +define(function(require, exports, module) { + +var oop = require("../lib/oop"); +var lang = require("../lib/lang"); +var TextHighlightRules = require("./text_highlight_rules"); PythonHighlightRules = function() { From 14593ac1549c1b16ccb7d8129fc20f6b2bf43bc5 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 9 Dec 2010 10:37:13 +0100 Subject: [PATCH 03/44] use lower case file names step #2 --- lib/ace/mode/{_python.js => python.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/ace/mode/{_python.js => python.js} (100%) diff --git a/lib/ace/mode/_python.js b/lib/ace/mode/python.js similarity index 100% rename from lib/ace/mode/_python.js rename to lib/ace/mode/python.js From 2f36e65d43266648fc3aef8b25074758ea1db6aa Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 9 Dec 2010 10:59:57 +0100 Subject: [PATCH 04/44] update editor demo to add python mode --- demo/editor-build.html | 34 ++++++++++++++++++++++++++++++++-- demo/editor.html | 32 +++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/demo/editor-build.html b/demo/editor-build.html index 7f791814..8ebcdf9e 100644 --- a/demo/editor-build.html +++ b/demo/editor-build.html @@ -62,6 +62,7 @@ + @@ -72,6 +73,7 @@ + @@ -132,10 +134,30 @@ + + + + + + +

Juhu Kinners

diff --git a/lib/ace/mode/python.js b/lib/ace/mode/python.js index d1e9a6bd..1e7c9796 100644 --- a/lib/ace/mode/python.js +++ b/lib/ace/mode/python.js @@ -37,12 +37,12 @@ define(function(require, exports, module) { -var oop = require("../lib/oop"); -var TextMode = require("./text"); -var Tokenizer = require("../tokenizer"); -var PythonHighlightRules = require("./python_highlight_rules"); -var MatchingBraceOutdent = require("./matching_brace_outdent"); -var Range = require("../range"); +var oop = require("pilot/oop").oop; +var TextMode = require("./text").Text; +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 Python = function() { this.$tokenizer = new Tokenizer(new PythonHighlightRules().getRules()); @@ -112,5 +112,5 @@ oop.inherits(Python, TextMode); }).call(Python.prototype); -return Python; +exports.Python = Python; }); diff --git a/lib/ace/mode/python_highlight_rules.js b/lib/ace/mode/python_highlight_rules.js index 57053e8c..0a48fcd3 100644 --- a/lib/ace/mode/python_highlight_rules.js +++ b/lib/ace/mode/python_highlight_rules.js @@ -40,9 +40,9 @@ define(function(require, exports, module) { -var oop = require("../lib/oop"); -var lang = require("../lib/lang"); -var TextHighlightRules = require("./text_highlight_rules"); +var oop = require("pilot/oop").oop; +var lang = require("pilot/lang").lang; +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; PythonHighlightRules = function() { @@ -172,5 +172,5 @@ PythonHighlightRules = function() { oop.inherits(PythonHighlightRules, TextHighlightRules); -return PythonHighlightRules; +exports.PythonHighlightRules = PythonHighlightRules; }); \ No newline at end of file diff --git a/support/requirejs b/support/requirejs index 0095dc02..819c4e7b 160000 --- a/support/requirejs +++ b/support/requirejs @@ -1 +1 @@ -Subproject commit 0095dc028d0e6f3d40587071fa67622930aa880e +Subproject commit 819c4e7b9b1e6e5f99696b5c9f2805891a9e7cfd From 5224b0cf97b22f03c115ab48cffada84ea2a2327 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Fri, 10 Dec 2010 17:26:14 +0100 Subject: [PATCH 10/44] add python file to the demo --- editor.html | 41 ++++++++++++++++++++++------------------- lib/ace/scrollbar.js | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/editor.html b/editor.html index cb2919cb..81ceef48 100644 --- a/editor.html +++ b/editor.html @@ -87,6 +87,7 @@ + @@ -97,6 +98,7 @@ + @@ -136,8 +138,7 @@ font-family: Monaco, "Courier New", monospace; font-size: 12px; cursor: text; -} - +} + - +# If no arguments were given, print a helpful message +if len(sys.argv)==1: + print 'Usage: celsius temp1 temp2 ...' + sys.exit(0) - - -

Juhu Kinners

- - - +# 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)) + - + \ No newline at end of file diff --git a/lib/ace/scrollbar.js b/lib/ace/scrollbar.js index 8ff25a14..67411c15 100644 --- a/lib/ace/scrollbar.js +++ b/lib/ace/scrollbar.js @@ -62,7 +62,7 @@ var ScrollBar = function(parent) { oop.implement(this, EventEmitter); this.onScroll = function() { - this.$dispatchEvent("scroll", {data: this.element.scrollTop}); + this._dispatchEvent("scroll", {data: this.element.scrollTop}); }; this.getWidth = function() { From cbb621514583cf84fb82d383699466c54c03d210 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Fri, 10 Dec 2010 18:07:06 +0100 Subject: [PATCH 11/44] rename all language mode classes to 'Mode'. --- demo/demo_startup.js | 12 ++++++------ lib/ace/document.js | 2 +- lib/ace/mode/css.js | 10 +++++----- lib/ace/mode/html.js | 14 +++++++------- lib/ace/mode/javascript.js | 10 +++++----- lib/ace/mode/python.js | 10 +++++----- lib/ace/mode/text.js | 6 +++--- lib/ace/mode/xml.js | 10 +++++----- lib/ace/test/mode/css_test.js | 15 +++++---------- lib/ace/test/mode/css_tokenizer_test.js | 9 +++------ lib/ace/test/mode/html_test.js | 15 +++++---------- lib/ace/test/mode/html_tokenizer_test.js | 9 +++------ lib/ace/test/mode/javascript_test.js | 18 ++++++------------ lib/ace/test/mode/javascript_tokenizer_test.js | 9 +++------ lib/ace/test/mode/text_test.js | 15 +++++---------- lib/ace/test/mode/xml_test.js | 18 ++++++------------ lib/ace/test/mode/xml_tokenizer_test.js | 9 +++------ lib/ace/test/text_edit_test.js | 8 ++++---- 18 files changed, 80 insertions(+), 119 deletions(-) diff --git a/demo/demo_startup.js b/demo/demo_startup.js index 139850e8..99823cc9 100644 --- a/demo/demo_startup.js +++ b/demo/demo_startup.js @@ -46,12 +46,12 @@ exports.launch = function(env) { 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 PythonMode = require("ace/mode/python").Python; - 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 = {}; diff --git a/lib/ace/document.js b/lib/ace/document.js index 671244f2..a705b682 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -41,7 +41,7 @@ var oop = require("pilot/oop").oop; var lang = require("pilot/lang").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) { diff --git a/lib/ace/mode/css.js b/lib/ace/mode/css.js index 4c6bd198..7f69fdf1 100644 --- a/lib/ace/mode/css.js +++ b/lib/ace/mode/css.js @@ -38,16 +38,16 @@ define(function(require, exports, module) { var oop = require("pilot/oop").oop; -var TextMode = require("ace/mode/text").Text; +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; }); diff --git a/lib/ace/mode/html.js b/lib/ace/mode/html.js index f6587676..25746d8e 100644 --- a/lib/ace/mode/html.js +++ b/lib/ace/mode/html.js @@ -38,19 +38,19 @@ 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 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() { @@ -95,7 +95,7 @@ oop.inherits(Html, TextMode); return defaultHandler ? defaultHandler() : undefined; }; -}).call(Html.prototype); +}).call(Mode.prototype); -exports.Html = Html; +exports.Mode = Mode; }); diff --git a/lib/ace/mode/javascript.js b/lib/ace/mode/javascript.js index e8bc67a6..66d6c317 100644 --- a/lib/ace/mode/javascript.js +++ b/lib/ace/mode/javascript.js @@ -38,17 +38,17 @@ define(function(require, exports, module) { var oop = require("pilot/oop").oop; -var TextMode = require("ace/mode/text").Text; +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() { @@ -121,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; }); diff --git a/lib/ace/mode/python.js b/lib/ace/mode/python.js index 1e7c9796..4111b877 100644 --- a/lib/ace/mode/python.js +++ b/lib/ace/mode/python.js @@ -38,17 +38,17 @@ define(function(require, exports, module) { var oop = require("pilot/oop").oop; -var TextMode = require("./text").Text; +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 Python = function() { +var Mode = function() { this.$tokenizer = new Tokenizer(new PythonHighlightRules().getRules()); this.$outdent = new MatchingBraceOutdent(); }; -oop.inherits(Python, TextMode); +oop.inherits(Mode, TextMode); (function() { @@ -110,7 +110,7 @@ oop.inherits(Python, TextMode); return this.$outdent.autoOutdent(doc, row); }; -}).call(Python.prototype); +}).call(Mode.prototype); -exports.Python = Python; +exports.Mode = Mode; }); diff --git a/lib/ace/mode/text.js b/lib/ace/mode/text.js index 1a73194f..0e18d038 100644 --- a/lib/ace/mode/text.js +++ b/lib/ace/mode/text.js @@ -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()); }; @@ -74,7 +74,7 @@ var Text = function() { return ""; }; -}).call(Text.prototype); +}).call(Mode.prototype); -exports.Text = Text; +exports.Mode = Mode; }); diff --git a/lib/ace/mode/xml.js b/lib/ace/mode/xml.js index 0a83adb1..e51bd7f8 100644 --- a/lib/ace/mode/xml.js +++ b/lib/ace/mode/xml.js @@ -38,15 +38,15 @@ define(function(require, exports, module) { var oop = require("pilot/oop").oop; -var TextMode = require("ace/mode/text").Text; +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; }); diff --git a/lib/ace/test/mode/css_test.js b/lib/ace/test/mode/css_test.js index 3fc588ea..27b5e55a 100644 --- a/lib/ace/test/mode/css_test.js +++ b/lib/ace/test/mode/css_test.js @@ -35,17 +35,12 @@ * * ***** END LICENSE BLOCK ***** */ -require.def([ - "ace/Document", - "ace/Range", - "ace/mode/Css" - ], function( - Document, - Range, - cssMod - ) { +define(function(require, exports, module) { + +var Document = require("ace/document").Document; +var Range = require("ace/range").Range; +var Css = require("ace/mode/css").Mode; -var CssMode = cssMod.Css; var CssTest = new TestCase("mode.CssTest", { setUp : function() { diff --git a/lib/ace/test/mode/css_tokenizer_test.js b/lib/ace/test/mode/css_tokenizer_test.js index 7baedfab..858770ba 100644 --- a/lib/ace/test/mode/css_tokenizer_test.js +++ b/lib/ace/test/mode/css_tokenizer_test.js @@ -35,13 +35,10 @@ * * ***** END LICENSE BLOCK ***** */ -require.def([ - "ace/mode/Css" - ], function( - cssMod - ) { +define(function(require, exports, module) { + +var Css = require("ace/mode/css").Mode; -var CssMode = cssMod.Css; var CssTest = new TestCase("mode.CssTest", { setUp : function() { diff --git a/lib/ace/test/mode/html_test.js b/lib/ace/test/mode/html_test.js index ae80f579..1e631b55 100644 --- a/lib/ace/test/mode/html_test.js +++ b/lib/ace/test/mode/html_test.js @@ -35,17 +35,12 @@ * * ***** END LICENSE BLOCK ***** */ -require.def([ - "ace/Document", - "ace/Range", - "ace/mode/Html" - ], function( - Document, - Range, - htmlMod - ) { +define(function(require, exports, module) { + +var Document = require("ace/document").Document; +var Range = require("ace/range").Range; +var Html = require("ace/mode/html").Mode; -var HtmlMode = htmlMod.Html; var HtmlTest = new TestCase("mode.HtmlTest", { setUp : function() { diff --git a/lib/ace/test/mode/html_tokenizer_test.js b/lib/ace/test/mode/html_tokenizer_test.js index b95bbe4e..6c89dc81 100644 --- a/lib/ace/test/mode/html_tokenizer_test.js +++ b/lib/ace/test/mode/html_tokenizer_test.js @@ -35,13 +35,10 @@ * * ***** END LICENSE BLOCK ***** */ -require.def([ - "ace/mode/Html" - ], function( - htmlMod - ) { +define(function(require, exports, module) { + +var Html = require("ace/mode/html").Mode; -var HtmlMode = htmlMod.Html; var HtmlTest = new TestCase("mode.HtmlTest", { setUp : function() { diff --git a/lib/ace/test/mode/javascript_test.js b/lib/ace/test/mode/javascript_test.js index 2374edde..52de56d1 100644 --- a/lib/ace/test/mode/javascript_test.js +++ b/lib/ace/test/mode/javascript_test.js @@ -35,19 +35,13 @@ * * ***** END LICENSE BLOCK ***** */ -require.def([ - "ace/Document", - "ace/Range", - "ace/Tokenizer", - "ace/mode/JavaScript" - ], function( - Document, - Range, - Tokenizer, - jsMod - ) { +define(function(require, exports, module) { + +var Document = require("ace/document").Document; +var Range = require("ace/range").Range; +var Tokenizer = require("ace/tokenizer").Tokenizer; +var JavaScript = require("ace/mode/javascript").Mode; -var JavaScriptMode = jsMod.JavaScript; var JavaScriptTest = new TestCase("mode.JavaScriptTest", { setUp : function() { diff --git a/lib/ace/test/mode/javascript_tokenizer_test.js b/lib/ace/test/mode/javascript_tokenizer_test.js index a80bcdd5..518d58e4 100644 --- a/lib/ace/test/mode/javascript_tokenizer_test.js +++ b/lib/ace/test/mode/javascript_tokenizer_test.js @@ -35,13 +35,10 @@ * * ***** END LICENSE BLOCK ***** */ -require.def([ - "ace/mode/JavaScript" - ], function( - jsMod - ) { +define(function(require, exports, module) { + +var JavaScript = require("ace/mode/javascript").Mode; -var JavaScriptMode = jsMod.JavaScript; var JavaScriptTokenizerTest = new TestCase("mode.JavaScriptTokenizerTest", { setUp : function() { diff --git a/lib/ace/test/mode/text_test.js b/lib/ace/test/mode/text_test.js index 9ca3880f..ef41e7b3 100644 --- a/lib/ace/test/mode/text_test.js +++ b/lib/ace/test/mode/text_test.js @@ -35,17 +35,12 @@ * * ***** END LICENSE BLOCK ***** */ -require.def([ - "ace/Document", - "ace/Range", - "ace/mode/Text" - ], function( - Document, - Range, - textMod - ) { +define(function(require, exports, module) { + +var Document = require("ace/document").Document; +var Range = require("ace/range").Range; +var Text = require("ace/mode/text").Mode; -var TextMode = textMod.Text; var TextTest = new TestCase("mode.TextTest", { setUp : function() { diff --git a/lib/ace/test/mode/xml_test.js b/lib/ace/test/mode/xml_test.js index f94f4a13..8f2962c6 100644 --- a/lib/ace/test/mode/xml_test.js +++ b/lib/ace/test/mode/xml_test.js @@ -35,19 +35,13 @@ * * ***** END LICENSE BLOCK ***** */ -require.def([ - "ace/Document", - "ace/Range", - "ace/Tokenizer", - "ace/mode/Xml" - ], function( - Document, - Range, - Tokenizer, - xmlMod - ) { +define(function(require, exports, module) { + +var Document = require("ace/document").Document; +var Range = require("ace/range").Range; +var Tokenizer = require("ace/tokenizer").Tokenizer; +var Xml = require("ace/mode/xml").Mode; -var XmlMode = xmlMod.Xml; var XmlTest = new TestCase("mode.XmlTest", { setUp : function() { diff --git a/lib/ace/test/mode/xml_tokenizer_test.js b/lib/ace/test/mode/xml_tokenizer_test.js index ada2ea38..cb03b4f5 100644 --- a/lib/ace/test/mode/xml_tokenizer_test.js +++ b/lib/ace/test/mode/xml_tokenizer_test.js @@ -35,13 +35,10 @@ * * ***** END LICENSE BLOCK ***** */ -require.def([ - "ace/mode/Xml" - ], function( - xmlMod - ) { +define(function(require, exports, module) { + +var Xml = require("ace/mode/xml").Mode; -var XmlMode = xmlMod.Xml; var XmlTest = new TestCase("mode.XmlTest", { setUp : function() { diff --git a/lib/ace/test/text_edit_test.js b/lib/ace/test/text_edit_test.js index c8d40c7b..fbc39d2b 100644 --- a/lib/ace/test/text_edit_test.js +++ b/lib/ace/test/text_edit_test.js @@ -48,7 +48,7 @@ global.location = browser.location; var Document = require("../document"), Editor = require("../editor"), - JavaScriptMode = require("../mode/javascript").JavaScript, + JavaScriptMode = require("../mode/javascript").Mode, MockRenderer = require("./mockrenderer"), assert = require("./assertions"); @@ -112,7 +112,7 @@ 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); @@ -131,7 +131,7 @@ var Test = { assert.position(range.end, 2, 7); }, - "__test: outdent block" : function() { + "test: outdent block" : function() { var doc = new Document([" a12345", " b12345", " c12345"].join("\n")); var editor = new Editor(new MockRenderer(), doc); @@ -248,7 +248,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); From f370a6f7fa90550ed17a63a165b2b6f78c43e52a Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Mon, 13 Dec 2010 10:39:25 +0100 Subject: [PATCH 12/44] remove lib directory from plugins otherwise the modules cannot be loaded with nodejs --- demo/boot.js | 3 +- plugins/cockpit/{lib => }/cli.js | 0 plugins/cockpit/{lib => }/index.js | 0 plugins/cockpit/{lib => }/test/assert.js | 0 plugins/cockpit/{lib => }/test/testCli.js | 0 plugins/cockpit/{lib => }/test/testNothing.js | 0 plugins/cockpit/{lib => }/ui/plain.css | 0 plugins/cockpit/{lib => }/ui/plain.js | 0 plugins/pilot/{lib => }/canon.js | 0 plugins/pilot/{lib => }/catalog.js | 0 plugins/pilot/{lib => }/commands/settings.js | 0 plugins/pilot/{lib => }/console.js | 0 plugins/pilot/{lib => }/core.js | 0 plugins/pilot/{lib => }/dom.js | 0 plugins/pilot/{lib => }/event.js | 0 plugins/pilot/{lib => }/event_emitter.js | 0 plugins/pilot/fixoldbrowsers.js | 145 +++++++++++++++++ plugins/pilot/{lib => }/index.js | 1 - plugins/pilot/{lib => }/keyboard/index.js | 0 plugins/pilot/{lib => }/keyboard/keyutil.js | 0 .../{lib => }/keyboard/tests/testKeyboard.js | 0 plugins/pilot/{lib => }/lang.js | 0 plugins/pilot/lib/fixoldbrowsers.js | 147 ------------------ plugins/pilot/{lib => }/oop.js | 0 plugins/pilot/{lib => }/plugin_manager.js | 0 plugins/pilot/{lib => }/promise.js | 0 plugins/pilot/{lib => }/proxy.js | 0 plugins/pilot/{lib => }/rangeutils.js | 0 plugins/pilot/{lib => }/settings.js | 0 plugins/pilot/{lib => }/settings/canon.js | 0 plugins/pilot/{lib => }/stacktrace.js | 0 .../pilot/{lib => }/tests/testRangeutils.js | 0 plugins/pilot/{lib => }/types.js | 0 plugins/pilot/{lib => }/types/basic.js | 0 plugins/pilot/{lib => }/types/command.js | 0 plugins/pilot/{lib => }/types/settings.js | 0 plugins/pilot/{lib => }/util.js | 0 37 files changed, 147 insertions(+), 149 deletions(-) rename plugins/cockpit/{lib => }/cli.js (100%) rename plugins/cockpit/{lib => }/index.js (100%) rename plugins/cockpit/{lib => }/test/assert.js (100%) rename plugins/cockpit/{lib => }/test/testCli.js (100%) rename plugins/cockpit/{lib => }/test/testNothing.js (100%) rename plugins/cockpit/{lib => }/ui/plain.css (100%) rename plugins/cockpit/{lib => }/ui/plain.js (100%) rename plugins/pilot/{lib => }/canon.js (100%) rename plugins/pilot/{lib => }/catalog.js (100%) rename plugins/pilot/{lib => }/commands/settings.js (100%) rename plugins/pilot/{lib => }/console.js (100%) rename plugins/pilot/{lib => }/core.js (100%) rename plugins/pilot/{lib => }/dom.js (100%) rename plugins/pilot/{lib => }/event.js (100%) rename plugins/pilot/{lib => }/event_emitter.js (100%) create mode 100644 plugins/pilot/fixoldbrowsers.js rename plugins/pilot/{lib => }/index.js (99%) rename plugins/pilot/{lib => }/keyboard/index.js (100%) rename plugins/pilot/{lib => }/keyboard/keyutil.js (100%) rename plugins/pilot/{lib => }/keyboard/tests/testKeyboard.js (100%) rename plugins/pilot/{lib => }/lang.js (100%) delete mode 100644 plugins/pilot/lib/fixoldbrowsers.js rename plugins/pilot/{lib => }/oop.js (100%) rename plugins/pilot/{lib => }/plugin_manager.js (100%) rename plugins/pilot/{lib => }/promise.js (100%) rename plugins/pilot/{lib => }/proxy.js (100%) rename plugins/pilot/{lib => }/rangeutils.js (100%) rename plugins/pilot/{lib => }/settings.js (100%) rename plugins/pilot/{lib => }/settings/canon.js (100%) rename plugins/pilot/{lib => }/stacktrace.js (100%) rename plugins/pilot/{lib => }/tests/testRangeutils.js (100%) rename plugins/pilot/{lib => }/types.js (100%) rename plugins/pilot/{lib => }/types/basic.js (100%) rename plugins/pilot/{lib => }/types/command.js (100%) rename plugins/pilot/{lib => }/types/settings.js (100%) rename plugins/pilot/{lib => }/util.js (100%) diff --git a/demo/boot.js b/demo/boot.js index 8cb3e6e3..95b704b9 100644 --- a/demo/boot.js +++ b/demo/boot.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]); } diff --git a/plugins/cockpit/lib/cli.js b/plugins/cockpit/cli.js similarity index 100% rename from plugins/cockpit/lib/cli.js rename to plugins/cockpit/cli.js diff --git a/plugins/cockpit/lib/index.js b/plugins/cockpit/index.js similarity index 100% rename from plugins/cockpit/lib/index.js rename to plugins/cockpit/index.js diff --git a/plugins/cockpit/lib/test/assert.js b/plugins/cockpit/test/assert.js similarity index 100% rename from plugins/cockpit/lib/test/assert.js rename to plugins/cockpit/test/assert.js diff --git a/plugins/cockpit/lib/test/testCli.js b/plugins/cockpit/test/testCli.js similarity index 100% rename from plugins/cockpit/lib/test/testCli.js rename to plugins/cockpit/test/testCli.js diff --git a/plugins/cockpit/lib/test/testNothing.js b/plugins/cockpit/test/testNothing.js similarity index 100% rename from plugins/cockpit/lib/test/testNothing.js rename to plugins/cockpit/test/testNothing.js diff --git a/plugins/cockpit/lib/ui/plain.css b/plugins/cockpit/ui/plain.css similarity index 100% rename from plugins/cockpit/lib/ui/plain.css rename to plugins/cockpit/ui/plain.css diff --git a/plugins/cockpit/lib/ui/plain.js b/plugins/cockpit/ui/plain.js similarity index 100% rename from plugins/cockpit/lib/ui/plain.js rename to plugins/cockpit/ui/plain.js diff --git a/plugins/pilot/lib/canon.js b/plugins/pilot/canon.js similarity index 100% rename from plugins/pilot/lib/canon.js rename to plugins/pilot/canon.js diff --git a/plugins/pilot/lib/catalog.js b/plugins/pilot/catalog.js similarity index 100% rename from plugins/pilot/lib/catalog.js rename to plugins/pilot/catalog.js diff --git a/plugins/pilot/lib/commands/settings.js b/plugins/pilot/commands/settings.js similarity index 100% rename from plugins/pilot/lib/commands/settings.js rename to plugins/pilot/commands/settings.js diff --git a/plugins/pilot/lib/console.js b/plugins/pilot/console.js similarity index 100% rename from plugins/pilot/lib/console.js rename to plugins/pilot/console.js diff --git a/plugins/pilot/lib/core.js b/plugins/pilot/core.js similarity index 100% rename from plugins/pilot/lib/core.js rename to plugins/pilot/core.js diff --git a/plugins/pilot/lib/dom.js b/plugins/pilot/dom.js similarity index 100% rename from plugins/pilot/lib/dom.js rename to plugins/pilot/dom.js diff --git a/plugins/pilot/lib/event.js b/plugins/pilot/event.js similarity index 100% rename from plugins/pilot/lib/event.js rename to plugins/pilot/event.js diff --git a/plugins/pilot/lib/event_emitter.js b/plugins/pilot/event_emitter.js similarity index 100% rename from plugins/pilot/lib/event_emitter.js rename to plugins/pilot/event_emitter.js diff --git a/plugins/pilot/fixoldbrowsers.js b/plugins/pilot/fixoldbrowsers.js new file mode 100644 index 00000000..1f7f1033 --- /dev/null +++ b/plugins/pilot/fixoldbrowsers.js @@ -0,0 +1,145 @@ +/* ***** 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) { + +// Narwhal's shim for ES5 defineProperty +// ES5 15.2.3.6 +if (!Object.defineProperty) { + Object.defineProperty = function(object, property, descriptor) { + var has = Object.prototype.hasOwnProperty; + if (typeof descriptor == "object" && object.__defineGetter__) { + if (has.call(descriptor, "value")) { + if (!object.__lookupGetter__(property) && !object.__lookupSetter__(property)) { + // data property defined and no pre-existing accessors + object[property] = descriptor.value; + } + if (has.call(descriptor, "get") || has.call(descriptor, "set")) { + // descriptor has a value property but accessor already exists + throw new TypeError("Object doesn't support this action"); + } + } + // fail silently if "writable", "enumerable", or "configurable" + // are requested but not supported + /* + // alternate approach: + if ( // can't implement these features; allow false but not true + !(has.call(descriptor, "writable") ? descriptor.writable : true) || + !(has.call(descriptor, "enumerable") ? descriptor.enumerable : true) || + !(has.call(descriptor, "configurable") ? descriptor.configurable : true) + ) + throw new RangeError( + "This implementation of Object.defineProperty does not " + + "support configurable, enumerable, or writable." + ); + */ + else if (typeof descriptor.get == "function") { + object.__defineGetter__(property, descriptor.get); + } + if (typeof descriptor.set == "function") { + object.__defineSetter__(property, descriptor.set); + } + } + return object; + }; +} + +// ES5 15.2.3.7 +if (!Object.defineProperties) { + Object.defineProperties = function(object, properties) { + for (var property in properties) { + if (Object.prototype.hasOwnProperty.call(properties, property)) { + Object.defineProperty(object, property, properties[property]); + } + } + return object; + }; +} + + + +/** + * 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]"; + }; +} + +/** + * 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 Narwhal + Function.prototype.bind = function () { + var args = Array.prototype.slice.call(arguments); + var self = this; + var bound = function () { + return self.call.apply( + self, + args.concat( + Array.prototype.slice.call(arguments) + ) + ); + }; + bound.name = this.name; + bound.displayName = this.displayName; + bound.length = this.length; + bound.unbound = self; + return bound; + }; +} + +exports.globalsLoaded = true; + +}); \ No newline at end of file diff --git a/plugins/pilot/lib/index.js b/plugins/pilot/index.js similarity index 99% rename from plugins/pilot/lib/index.js rename to plugins/pilot/index.js index 73262d42..157d4f1c 100644 --- a/plugins/pilot/lib/index.js +++ b/plugins/pilot/index.js @@ -50,7 +50,6 @@ packages.unshift("require", "exports", "module"); define(packages, function(require, exports, module) { -console.log(packages); exports.startup = function(data, reason) { deps.forEach(function(dep) { console.log("test startup for " + dep); diff --git a/plugins/pilot/lib/keyboard/index.js b/plugins/pilot/keyboard/index.js similarity index 100% rename from plugins/pilot/lib/keyboard/index.js rename to plugins/pilot/keyboard/index.js diff --git a/plugins/pilot/lib/keyboard/keyutil.js b/plugins/pilot/keyboard/keyutil.js similarity index 100% rename from plugins/pilot/lib/keyboard/keyutil.js rename to plugins/pilot/keyboard/keyutil.js diff --git a/plugins/pilot/lib/keyboard/tests/testKeyboard.js b/plugins/pilot/keyboard/tests/testKeyboard.js similarity index 100% rename from plugins/pilot/lib/keyboard/tests/testKeyboard.js rename to plugins/pilot/keyboard/tests/testKeyboard.js diff --git a/plugins/pilot/lib/lang.js b/plugins/pilot/lang.js similarity index 100% rename from plugins/pilot/lib/lang.js rename to plugins/pilot/lang.js diff --git a/plugins/pilot/lib/fixoldbrowsers.js b/plugins/pilot/lib/fixoldbrowsers.js deleted file mode 100644 index 995afb8a..00000000 --- a/plugins/pilot/lib/fixoldbrowsers.js +++ /dev/null @@ -1,147 +0,0 @@ -/* ***** 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) { - -exports.startup = function(data, reason) { - // Narwhal's shim for ES5 defineProperty - // ES5 15.2.3.6 - if (!Object.defineProperty) { - Object.defineProperty = function(object, property, descriptor) { - var has = Object.prototype.hasOwnProperty; - if (typeof descriptor == "object" && object.__defineGetter__) { - if (has.call(descriptor, "value")) { - if (!object.__lookupGetter__(property) && !object.__lookupSetter__(property)) { - // data property defined and no pre-existing accessors - object[property] = descriptor.value; - } - if (has.call(descriptor, "get") || has.call(descriptor, "set")) { - // descriptor has a value property but accessor already exists - throw new TypeError("Object doesn't support this action"); - } - } - // fail silently if "writable", "enumerable", or "configurable" - // are requested but not supported - /* - // alternate approach: - if ( // can't implement these features; allow false but not true - !(has.call(descriptor, "writable") ? descriptor.writable : true) || - !(has.call(descriptor, "enumerable") ? descriptor.enumerable : true) || - !(has.call(descriptor, "configurable") ? descriptor.configurable : true) - ) - throw new RangeError( - "This implementation of Object.defineProperty does not " + - "support configurable, enumerable, or writable." - ); - */ - else if (typeof descriptor.get == "function") { - object.__defineGetter__(property, descriptor.get); - } - if (typeof descriptor.set == "function") { - object.__defineSetter__(property, descriptor.set); - } - } - return object; - }; - } - - // ES5 15.2.3.7 - if (!Object.defineProperties) { - Object.defineProperties = function(object, properties) { - for (var property in properties) { - if (Object.prototype.hasOwnProperty.call(properties, property)) { - Object.defineProperty(object, property, properties[property]); - } - } - return object; - }; - } - - - - /** - * 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]"; - }; - } - - /** - * 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 Narwhal - Function.prototype.bind = function () { - var args = Array.prototype.slice.call(arguments); - var self = this; - var bound = function () { - return self.call.apply( - self, - args.concat( - Array.prototype.slice.call(arguments) - ) - ); - }; - bound.name = this.name; - bound.displayName = this.displayName; - bound.length = this.length; - bound.unbound = self; - return bound; - }; - } - - exports.globalsLoaded = true; -}; - -}); \ No newline at end of file diff --git a/plugins/pilot/lib/oop.js b/plugins/pilot/oop.js similarity index 100% rename from plugins/pilot/lib/oop.js rename to plugins/pilot/oop.js diff --git a/plugins/pilot/lib/plugin_manager.js b/plugins/pilot/plugin_manager.js similarity index 100% rename from plugins/pilot/lib/plugin_manager.js rename to plugins/pilot/plugin_manager.js diff --git a/plugins/pilot/lib/promise.js b/plugins/pilot/promise.js similarity index 100% rename from plugins/pilot/lib/promise.js rename to plugins/pilot/promise.js diff --git a/plugins/pilot/lib/proxy.js b/plugins/pilot/proxy.js similarity index 100% rename from plugins/pilot/lib/proxy.js rename to plugins/pilot/proxy.js diff --git a/plugins/pilot/lib/rangeutils.js b/plugins/pilot/rangeutils.js similarity index 100% rename from plugins/pilot/lib/rangeutils.js rename to plugins/pilot/rangeutils.js diff --git a/plugins/pilot/lib/settings.js b/plugins/pilot/settings.js similarity index 100% rename from plugins/pilot/lib/settings.js rename to plugins/pilot/settings.js diff --git a/plugins/pilot/lib/settings/canon.js b/plugins/pilot/settings/canon.js similarity index 100% rename from plugins/pilot/lib/settings/canon.js rename to plugins/pilot/settings/canon.js diff --git a/plugins/pilot/lib/stacktrace.js b/plugins/pilot/stacktrace.js similarity index 100% rename from plugins/pilot/lib/stacktrace.js rename to plugins/pilot/stacktrace.js diff --git a/plugins/pilot/lib/tests/testRangeutils.js b/plugins/pilot/tests/testRangeutils.js similarity index 100% rename from plugins/pilot/lib/tests/testRangeutils.js rename to plugins/pilot/tests/testRangeutils.js diff --git a/plugins/pilot/lib/types.js b/plugins/pilot/types.js similarity index 100% rename from plugins/pilot/lib/types.js rename to plugins/pilot/types.js diff --git a/plugins/pilot/lib/types/basic.js b/plugins/pilot/types/basic.js similarity index 100% rename from plugins/pilot/lib/types/basic.js rename to plugins/pilot/types/basic.js diff --git a/plugins/pilot/lib/types/command.js b/plugins/pilot/types/command.js similarity index 100% rename from plugins/pilot/lib/types/command.js rename to plugins/pilot/types/command.js diff --git a/plugins/pilot/lib/types/settings.js b/plugins/pilot/types/settings.js similarity index 100% rename from plugins/pilot/lib/types/settings.js rename to plugins/pilot/types/settings.js diff --git a/plugins/pilot/lib/util.js b/plugins/pilot/util.js similarity index 100% rename from plugins/pilot/lib/util.js rename to plugins/pilot/util.js From 46ac14ab6299c0aa4d82f83e01a6ce5ab6b82743 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Mon, 13 Dec 2010 10:40:48 +0100 Subject: [PATCH 13/44] make sure the browser fix is always loaded --- demo/boot.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/demo/boot.js b/demo/boot.js index 95b704b9..1e63002a 100644 --- a/demo/boot.js +++ b/demo/boot.js @@ -110,15 +110,11 @@ var setupPlugins = function(config, callback) { } } } -console.log(JSON.stringify({ - packagePaths: pluginPackageInfo, - paths: paths - })); require({ 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; From 5e0695b58813592b57ecb91eb3a5e79986226116 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Tue, 14 Dec 2010 11:36:21 +0100 Subject: [PATCH 14/44] pass in the env to canon.execute to allow multiple editors --- lib/ace/keybinding.js | 2 +- plugins/cockpit/cli.js | 8 ++++++-- plugins/pilot/canon.js | 6 +----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/ace/keybinding.js b/lib/ace/keybinding.js index 31df2ee3..d9ecd4a1 100644 --- a/lib/ace/keybinding.js +++ b/lib/ace/keybinding.js @@ -56,7 +56,7 @@ var KeyBinding = function(element, editor, config) { 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); } diff --git a/plugins/cockpit/cli.js b/plugins/cockpit/cli.js index 027ba9f8..85382cb9 100644 --- a/plugins/cockpit/cli.js +++ b/plugins/cockpit/cli.js @@ -244,8 +244,10 @@ exports.Assignment = Assignment; * class * @constructor */ -function Requisition() { +function Requisition(env) { + this.env = env; } + Requisition.prototype = { /** * The command that we are about to execute. @@ -377,7 +379,9 @@ exports.Requisition = Requisition; * if not specified. * @constructor */ -function CliRequisition(options) { +function CliRequisition(env, options) { + Requisition.call(this, env); + if (options && options.flags) { /** * TODO: We were using a default of keyboard.buildFlags({ }); diff --git a/plugins/pilot/canon.js b/plugins/pilot/canon.js index aa308f49..5bf4e79a 100644 --- a/plugins/pilot/canon.js +++ b/plugins/pilot/canon.js @@ -37,7 +37,6 @@ define(function(require, exports, module) { - var console = require('pilot/console'); var Trace = require('pilot/stacktrace').Trace; var oop = require('pilot/oop').oop; @@ -70,11 +69,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); }; @@ -160,7 +156,7 @@ exports.getCommandNames = function() { * everything it needs to about the command params * @param command Either a command, or the name of one */ -exports.exec = function(command, args) { +exports.exec = function(command, env, args) { if (typeof command === 'string') { command = commands[command]; } From 8b15b3c0a72a65c541b1559d27b8195f9155efd0 Mon Sep 17 00:00:00 2001 From: Eddy Bruel Date: Tue, 14 Dec 2010 11:47:52 +0100 Subject: [PATCH 15/44] Added paths.js and requireJS-node.js --- support/paths.js | 5 +++ support/requireJS-node.js | 79 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 support/paths.js create mode 100644 support/requireJS-node.js diff --git a/support/paths.js b/support/paths.js new file mode 100644 index 00000000..4244a500 --- /dev/null +++ b/support/paths.js @@ -0,0 +1,5 @@ +require("./requireJS-node"); +require.paths.unshift(__dirname + "/async/lib"); +require.paths.unshift(__dirname + "/node-htmlparser/lib"); +require.paths.unshift(__dirname + "/jsdom/lib"); +require.paths.unshift(__dirname); diff --git a/support/requireJS-node.js b/support/requireJS-node.js new file mode 100644 index 00000000..0e5e5a37 --- /dev/null +++ b/support/requireJS-node.js @@ -0,0 +1,79 @@ +var path = require("path"); +var currentModule, defaultCompile = module.constructor.prototype._compile; +//console.log(module.id); + +module.constructor.prototype._compile = function(content, filename){ + currentModule = this; + try{ + return defaultCompile.call(this, content, filename); + } + finally { + currentModule = null; + } +}; + +var requireModule = module; + +global.define = function (id, injects, factory) { + if (currentModule == null) { + throw new Error("define() may only be called during module factory instantiation"); + } + + var module = currentModule; + + var req = function(relativeId) { + if (relativeId.charAt(0) === '.') { + var rootPath = path.dirname(path.dirname(requireModule.filename)) + "/", + absolutePath = path.dirname(module.filename) + "/" + relativeId; + + relativeId = "../" + absolutePath.match(new RegExp(rootPath + "(.*)"))[1]; + } + + return require(relativeId); + }; + if (!factory) { + // two or less arguments + factory = injects; + if (factory) { + // two args + if (typeof id === "string") { + if (id !== module.id) { + throw new Error("Can not assign module to a different id than the current file"); + } + // default injects + injects = []; + } + else{ + // anonymous, deps included + injects = id; + } + } + else { + // only one arg, just the factory + factory = id; + injects = []; + } + } + injects.unshift("require", "exports", "module"); + + id = module.id; + if (typeof factory !== "function"){ + // we can just provide a plain object + return module.exports = factory; + } + var returned = factory.apply(module.exports, injects.map(function (injection) { + switch (injection) { + // check for CommonJS injection variables + case "require": return req; + case "exports": return module.exports; + case "module": return module; + default: + // a module dependency + return req(injection); + } + })); + if(returned){ + // since AMD encapsulates a function/callback, it can allow the factory to return the exports. + module.exports = returned; + } +}; From 6ad890e71e1cc5a528ea2de22e5e9eb9c742573f Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Tue, 14 Dec 2010 14:17:52 +0100 Subject: [PATCH 16/44] fix moving lines up --- lib/ace/document.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ace/document.js b/lib/ace/document.js index a705b682..74b5f8df 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -664,7 +664,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], lastRow, this.lines[lastRow].length)); this.$insertLines(firstRow - 1, removed); this.fireChangeEvent(firstRow - 1, lastRow); From d6ccdce00894af7fdb42a6ad6511e5809a57f007 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Tue, 14 Dec 2010 14:18:09 +0100 Subject: [PATCH 17/44] minor fix --- plugins/pilot/lang.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pilot/lang.js b/plugins/pilot/lang.js index f99d7a04..f4538dbf 100644 --- a/plugins/pilot/lang.js +++ b/plugins/pilot/lang.js @@ -111,7 +111,7 @@ define(function(require, exports, module) { }, call: function() { - lang.cancel(); + this.cancel(); fcn(); }, From f07745839c759f53fac523cc9ebc72ace87aa026 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Tue, 14 Dec 2010 15:09:24 +0100 Subject: [PATCH 18/44] fix all tests to run with node.js --- lib/ace/document.js | 4 +- lib/ace/test/all.js | 23 ++++---- lib/ace/test/change_document_test.js | 18 ++----- lib/ace/test/document_test.js | 57 ++------------------ lib/ace/test/event_emitter_test.js | 12 ++--- lib/ace/test/mockdom.js | 8 +++ lib/ace/test/mockrenderer.js | 3 ++ lib/ace/test/navigation_test.js | 15 ++---- lib/ace/test/range_test.js | 2 +- lib/ace/test/search_test.js | 4 +- lib/ace/test/selection_test.js | 2 +- lib/ace/test/text_edit_test.js | 73 ++++++++++++++++++------- lib/ace/test/virtual_renderer_test.js | 7 +-- support/paths.js | 2 + support/requireJS-node.js | 76 +++++++++++++++++++++++++-- 15 files changed, 181 insertions(+), 125 deletions(-) create mode 100644 lib/ace/test/mockdom.js diff --git a/lib/ace/document.js b/lib/ace/document.js index 74b5f8df..357520cb 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -47,7 +47,7 @@ var Range = require("ace/range").Range; var Document = function(text, mode) { this.modified = true; - this.lines = [""]; + this.lines = []; this.selection = new Selection(this); this.$breakpoints = []; @@ -623,7 +623,7 @@ var Document = function(text, mode) { }; this.indentRows = function(range, indentString) { - indentString.replace("\t", this.getTabString()); + indentString = indentString.replace("\t", this.getTabString()); for (var row=range.start.row; row<=range.end.row; row++) { this.$insert({row: row, column:0}, indentString); } diff --git a/lib/ace/test/all.js b/lib/ace/test/all.js index 297c69a4..7ed48c4a 100644 --- a/lib/ace/test/all.js +++ b/lib/ace/test/all.js @@ -35,14 +35,17 @@ * * ***** 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") +).exec(); diff --git a/lib/ace/test/change_document_test.js b/lib/ace/test/change_document_test.js index 90ca741f..24561d9b 100644 --- a/lib/ace/test/change_document_test.js +++ b/lib/ace/test/change_document_test.js @@ -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"); diff --git a/lib/ace/test/document_test.js b/lib/ace/test/document_test.js index 6ae725da..fd5995da 100644 --- a/lib/ace/test/document_test.js +++ b/lib/ace/test/document_test.js @@ -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"); @@ -83,9 +83,7 @@ var Test = { "test: move lines down" : function() { var doc = new Document(["1", "2", "3", "4"]); - 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")); doc.moveLinesDown(1, 2); @@ -98,12 +96,10 @@ var Test = { assert.equal(doc.toString(), ["3", "4", "2", "1"].join("\n")); }, - "__test: move lines up" : function() { + "test: move lines up" : function() { var doc = new Document(["1", "2", "3", "4"]); - 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")); doc.moveLinesUp(1, 2); @@ -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); diff --git a/lib/ace/test/event_emitter_test.js b/lib/ace/test/event_emitter_test.js index 8b6b6a26..f28a345a 100644 --- a/lib/ace/test/event_emitter_test.js +++ b/lib/ace/test/event_emitter_test.js @@ -37,17 +37,17 @@ require("../../../support/paths"); -var oop = require("../lib/oop"); - MEventEmitter = require("../event_emitter"), +var oop = require("pilot/oop").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); } }; diff --git a/lib/ace/test/mockdom.js b/lib/ace/test/mockdom.js new file mode 100644 index 00000000..1c9b8476 --- /dev/null +++ b/lib/ace/test/mockdom.js @@ -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; \ No newline at end of file diff --git a/lib/ace/test/mockrenderer.js b/lib/ace/test/mockrenderer.js index 6a3f51a1..61739218 100644 --- a/lib/ace/test/mockrenderer.js +++ b/lib/ace/test/mockrenderer.js @@ -116,6 +116,9 @@ MockRenderer.prototype.setBreakpoints = function() { MockRenderer.prototype.updateFull = function() { }; +MockRenderer.prototype.updateText = function() { +}; + MockRenderer.prototype.showCursor = function() { }; diff --git a/lib/ace/test/navigation_test.js b/lib/ace/test/navigation_test.js index 63e519e8..907650a5 100644 --- a/lib/ace/test/navigation_test.js +++ b/lib/ace/test/navigation_test.js @@ -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) { diff --git a/lib/ace/test/range_test.js b/lib/ace/test/range_test.js index 3aa1cc72..a590889a 100644 --- a/lib/ace/test/range_test.js +++ b/lib/ace/test/range_test.js @@ -37,7 +37,7 @@ require("../../../support/paths"); -var Range = require("../range"), +var Range = require("../range").Range, assert = require("./assertions"); var Test = { diff --git a/lib/ace/test/search_test.js b/lib/ace/test/search_test.js index ba9b6e10..d86d59e0 100644 --- a/lib/ace/test/search_test.js +++ b/lib/ace/test/search_test.js @@ -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 = { diff --git a/lib/ace/test/selection_test.js b/lib/ace/test/selection_test.js index 407fd3bf..571117dd 100644 --- a/lib/ace/test/selection_test.js +++ b/lib/ace/test/selection_test.js @@ -37,7 +37,7 @@ require("../../../support/paths"); -var Document = require("../document"), +var Document = require("../document").Document, assert = require("./assertions"); var Test = { diff --git a/lib/ace/test/text_edit_test.js b/lib/ace/test/text_edit_test.js index fbc39d2b..ea9b77a9 100644 --- a/lib/ace/test/text_edit_test.js +++ b/lib/ace/test/text_edit_test.js @@ -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"), +var Document = require("../document").Document, + Editor = require("../editor").Editor, JavaScriptMode = require("../mode/javascript").Mode, + UndoManager = require("../undomanager").UndoManager, MockRenderer = require("./mockrenderer"), assert = require("./assertions"); @@ -119,7 +112,7 @@ var Test = { editor.moveCursorTo(1, 3); editor.getSelection().selectDown(); - editor.blockIndent(" "); + editor.indent(); assert.equal(["a12345", " b12345", " c12345"].join("\n"), doc.toString()); @@ -135,26 +128,25 @@ var Test = { var doc = new Document([" a12345", " b12345", " c12345"].join("\n")); var editor = new Editor(new MockRenderer(), doc); - editor.moveCursorTo(0, 3); + 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() { @@ -340,6 +332,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); } }; diff --git a/lib/ace/test/virtual_renderer_test.js b/lib/ace/test/virtual_renderer_test.js index 776d8bab..088dcb28 100644 --- a/lib/ace/test/virtual_renderer_test.js +++ b/lib/ace/test/virtual_renderer_test.js @@ -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() { diff --git a/support/paths.js b/support/paths.js index 4244a500..1be92a90 100644 --- a/support/paths.js +++ b/support/paths.js @@ -1,4 +1,6 @@ require("./requireJS-node"); +require.paths.unshift(__dirname + "/../lib"); +require.paths.unshift(__dirname + "/../plugins"); require.paths.unshift(__dirname + "/async/lib"); require.paths.unshift(__dirname + "/node-htmlparser/lib"); require.paths.unshift(__dirname + "/jsdom/lib"); diff --git a/support/requireJS-node.js b/support/requireJS-node.js index 0e5e5a37..debb0124 100644 --- a/support/requireJS-node.js +++ b/support/requireJS-node.js @@ -1,6 +1,6 @@ var path = require("path"); +var fs = require("fs"); var currentModule, defaultCompile = module.constructor.prototype._compile; -//console.log(module.id); module.constructor.prototype._compile = function(content, filename){ currentModule = this; @@ -21,15 +21,29 @@ global.define = function (id, injects, factory) { var module = currentModule; - var req = function(relativeId) { + var req = function(relativeId, callback) { + if (Array.isArray(relativeId)) { + // async require + return callback.apply(this, relativeId.map(req)) + } + + var chunks = relativeId.split("!"); + if (chunks.length >= 2) { + var prefix = chunks[0]; + relativeId = chunks.slice(1).join("!") + } + if (relativeId.charAt(0) === '.') { var rootPath = path.dirname(path.dirname(requireModule.filename)) + "/", absolutePath = path.dirname(module.filename) + "/" + relativeId; relativeId = "../" + absolutePath.match(new RegExp(rootPath + "(.*)"))[1]; } - - return require(relativeId); + + if (prefix == "text") { + return fs.readFileSync(findModulePath(relativeId)) + } else + return require(relativeId); }; if (!factory) { // two or less arguments @@ -77,3 +91,57 @@ global.define = function (id, injects, factory) { module.exports = returned; } }; + +// slighly modified version of +// https://github.com/ry/node/blob/1dad95a3a960c645ffec28f9ec023dad6a17c0d4/src/node.js#L159 +// +// given a module name, and a list of paths to test, returns the first +// matching file in the following precedence. +// +// require("a.") +// -> a. +// +// require("a") +// -> a +// -> a. +// -> a/index. +function findModulePath(request) { + var fs = require('fs'), + exts = ["js"], + paths = ['.'].concat(require.paths) + + paths = request.charAt(0) === '/' ? [''] : paths; + + // check if the file exists and is not a directory + var tryFile = function(requestPath) { + try { + var stats = fs.statSync(requestPath); + if (stats && !stats.isDirectory()) { + return requestPath; + } + } catch (e) {} + return false; + }; + + // given a path check a the file exists with any of the set extensions + var tryExtensions = function(p, extension) { + for (var i = 0, EL = exts.length; i < EL; i++) { + f = tryFile(p + exts[i]); + if (f) { return f; } + } + return false; + }; + + // For each path + for (var i = 0, PL = paths.length; i < PL; i++) { + var p = paths[i], + // try to join the request to the path + f = tryFile(path.join(p, request)) || + // try it with each of the extensions + tryExtensions(path.join(p, request)) || + // try it with each of the extensions at "index" + tryExtensions(path.join(p, request, 'index')); + if (f) { return f; } + } + return false; +} \ No newline at end of file From c5f63c7112842e2faeb0ff7ff3d1d7489b7b9916 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 11:04:14 +0100 Subject: [PATCH 19/44] put functions from old "ace/lib" modules directly on "exports" --- demo/demo_startup.js | 2 +- lib/ace/background_tokenizer.js | 2 +- lib/ace/document.js | 4 +- lib/ace/editor.js | 6 +- lib/ace/keybinding.js | 4 +- lib/ace/layer/cursor.js | 2 +- lib/ace/layer/text.js | 4 +- lib/ace/mode/css.js | 2 +- lib/ace/mode/css_highlight_rules.js | 4 +- lib/ace/mode/doc_comment_highlight_rules.js | 2 +- lib/ace/mode/html.js | 2 +- lib/ace/mode/html_highlight_rules.js | 2 +- lib/ace/mode/javascript.js | 2 +- lib/ace/mode/javascript_highlight_rules.js | 4 +- lib/ace/mode/python.js | 2 +- lib/ace/mode/python_highlight_rules.js | 4 +- lib/ace/mode/xml.js | 2 +- lib/ace/mode/xml_highlight_rules.js | 2 +- lib/ace/renderloop.js | 2 +- lib/ace/scrollbar.js | 8 +- lib/ace/search.js | 4 +- lib/ace/selection.js | 4 +- lib/ace/test/event_emitter_test.js | 2 +- lib/ace/textinput.js | 2 +- lib/ace/theme/clouds.js | 2 +- lib/ace/theme/clouds_mignight.js | 2 +- lib/ace/theme/cobalt.js | 2 +- lib/ace/theme/dawn.js | 2 +- lib/ace/theme/eclipse.js | 2 +- lib/ace/theme/idle_fingers.js | 2 +- lib/ace/theme/kr_theme.js | 2 +- lib/ace/theme/mono_industrial.js | 2 +- lib/ace/theme/monokai.js | 2 +- lib/ace/theme/textmate.js | 2 +- lib/ace/theme/twilight.js | 2 +- lib/ace/virtual_renderer.js | 8 +- plugins/cockpit/cli.js | 2 +- plugins/cockpit/ui/plain.js | 2 +- plugins/pilot/canon.js | 2 +- plugins/pilot/core.js | 35 +- plugins/pilot/dom.js | 163 ++++----- plugins/pilot/event.js | 383 ++++++++++---------- plugins/pilot/event_emitter.js | 2 +- plugins/pilot/lang.js | 144 ++++---- plugins/pilot/oop.js | 33 +- plugins/pilot/settings.js | 2 +- 46 files changed, 428 insertions(+), 444 deletions(-) diff --git a/demo/demo_startup.js b/demo/demo_startup.js index 99823cc9..1e71e8b3 100644 --- a/demo/demo_startup.js +++ b/demo/demo_startup.js @@ -41,7 +41,7 @@ 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"); diff --git a/lib/ace/background_tokenizer.js b/lib/ace/background_tokenizer.js index 811eeb8d..a95da503 100644 --- a/lib/ace/background_tokenizer.js +++ b/lib/ace/background_tokenizer.js @@ -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) { diff --git a/lib/ace/document.js b/lib/ace/document.js index 357520cb..6b792a5b 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -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 Selection = require("ace/selection").Selection; var TextMode = require("ace/mode/text").Mode; diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 63c99563..2ccdf0fc 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -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; diff --git a/lib/ace/keybinding.js b/lib/ace/keybinding.js index d9ecd4a1..a57c71cc 100644 --- a/lib/ace/keybinding.js +++ b/lib/ace/keybinding.js @@ -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"); diff --git a/lib/ace/layer/cursor.js b/lib/ace/layer/cursor.js index 57ffc7f7..7d1b7fa6 100644 --- a/lib/ace/layer/cursor.js +++ b/lib/ace/layer/cursor.js @@ -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"); diff --git a/lib/ace/layer/text.js b/lib/ace/layer/text.js index 9ba67f43..724b5f36 100644 --- a/lib/ace/layer/text.js +++ b/lib/ace/layer/text.js @@ -37,8 +37,8 @@ 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 EventEmitter = require("pilot/event_emitter").EventEmitter; var Text = function(parentEl) { diff --git a/lib/ace/mode/css.js b/lib/ace/mode/css.js index 7f69fdf1..21a1df85 100644 --- a/lib/ace/mode/css.js +++ b/lib/ace/mode/css.js @@ -37,7 +37,7 @@ define(function(require, exports, module) { -var oop = require("pilot/oop").oop; +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; diff --git a/lib/ace/mode/css_highlight_rules.js b/lib/ace/mode/css_highlight_rules.js index a4445f41..f448f87f 100644 --- a/lib/ace/mode/css_highlight_rules.js +++ b/lib/ace/mode/css_highlight_rules.js @@ -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() { diff --git a/lib/ace/mode/doc_comment_highlight_rules.js b/lib/ace/mode/doc_comment_highlight_rules.js index 48812aed..d88a9d2d 100644 --- a/lib/ace/mode/doc_comment_highlight_rules.js +++ b/lib/ace/mode/doc_comment_highlight_rules.js @@ -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() { diff --git a/lib/ace/mode/html.js b/lib/ace/mode/html.js index 25746d8e..a6ecc6c8 100644 --- a/lib/ace/mode/html.js +++ b/lib/ace/mode/html.js @@ -37,7 +37,7 @@ define(function(require, exports, module) { -var oop = require("pilot/oop").oop; +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; diff --git a/lib/ace/mode/html_highlight_rules.js b/lib/ace/mode/html_highlight_rules.js index be441552..6193cb91 100644 --- a/lib/ace/mode/html_highlight_rules.js +++ b/lib/ace/mode/html_highlight_rules.js @@ -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; diff --git a/lib/ace/mode/javascript.js b/lib/ace/mode/javascript.js index 66d6c317..1e4eb24b 100644 --- a/lib/ace/mode/javascript.js +++ b/lib/ace/mode/javascript.js @@ -37,7 +37,7 @@ define(function(require, exports, module) { -var oop = require("pilot/oop").oop; +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; diff --git a/lib/ace/mode/javascript_highlight_rules.js b/lib/ace/mode/javascript_highlight_rules.js index 0cbad802..3dd063f2 100644 --- a/lib/ace/mode/javascript_highlight_rules.js +++ b/lib/ace/mode/javascript_highlight_rules.js @@ -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; diff --git a/lib/ace/mode/python.js b/lib/ace/mode/python.js index 4111b877..7687e553 100644 --- a/lib/ace/mode/python.js +++ b/lib/ace/mode/python.js @@ -37,7 +37,7 @@ define(function(require, exports, module) { -var oop = require("pilot/oop").oop; +var oop = require("pilot/oop"); var TextMode = require("./text").Mode; var Tokenizer = require("../tokenizer").Tokenizer; var PythonHighlightRules = require("./python_highlight_rules").PythonHighlightRules; diff --git a/lib/ace/mode/python_highlight_rules.js b/lib/ace/mode/python_highlight_rules.js index 0a48fcd3..5190178b 100644 --- a/lib/ace/mode/python_highlight_rules.js +++ b/lib/ace/mode/python_highlight_rules.js @@ -40,8 +40,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("./text_highlight_rules").TextHighlightRules; PythonHighlightRules = function() { diff --git a/lib/ace/mode/xml.js b/lib/ace/mode/xml.js index e51bd7f8..5208709d 100644 --- a/lib/ace/mode/xml.js +++ b/lib/ace/mode/xml.js @@ -37,7 +37,7 @@ define(function(require, exports, module) { -var oop = require("pilot/oop").oop; +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; diff --git a/lib/ace/mode/xml_highlight_rules.js b/lib/ace/mode/xml_highlight_rules.js index b1c6e874..7e758c63 100644 --- a/lib/ace/mode/xml_highlight_rules.js +++ b/lib/ace/mode/xml_highlight_rules.js @@ -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() { diff --git a/lib/ace/renderloop.js b/lib/ace/renderloop.js index 20fa21fb..afe2b8b0 100644 --- a/lib/ace/renderloop.js +++ b/lib/ace/renderloop.js @@ -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; diff --git a/lib/ace/scrollbar.js b/lib/ace/scrollbar.js index 67411c15..e74dbf76 100644 --- a/lib/ace/scrollbar.js +++ b/lib/ace/scrollbar.js @@ -37,10 +37,10 @@ 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 lang = require("pilot/lang"); +var dom = require("pilot/dom"); +var event = require("pilot/event"); var EventEmitter = require("pilot/event_emitter").EventEmitter; var ScrollBar = function(parent) { diff --git a/lib/ace/search.js b/lib/ace/search.js index 3ea5eba0..43f399de 100644 --- a/lib/ace/search.js +++ b/lib/ace/search.js @@ -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() { diff --git a/lib/ace/selection.js b/lib/ace/selection.js index 3b551667..236d546e 100644 --- a/lib/ace/selection.js +++ b/lib/ace/selection.js @@ -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; diff --git a/lib/ace/test/event_emitter_test.js b/lib/ace/test/event_emitter_test.js index f28a345a..c414e0b3 100644 --- a/lib/ace/test/event_emitter_test.js +++ b/lib/ace/test/event_emitter_test.js @@ -37,7 +37,7 @@ require("../../../support/paths"); -var oop = require("pilot/oop").oop; +var oop = require("pilot/oop"); EventEmitter = require("pilot/event_emitter").EventEmitter, assert = require("./assertions"); diff --git a/lib/ace/textinput.js b/lib/ace/textinput.js index d4abdc96..076f7875 100644 --- a/lib/ace/textinput.js +++ b/lib/ace/textinput.js @@ -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) { diff --git a/lib/ace/theme/clouds.js b/lib/ace/theme/clouds.js index 6f1fa494..0211aeff 100644 --- a/lib/ace/theme/clouds.js +++ b/lib/ace/theme/clouds.js @@ -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);\ diff --git a/lib/ace/theme/clouds_mignight.js b/lib/ace/theme/clouds_mignight.js index d73350f2..16011ba9 100644 --- a/lib/ace/theme/clouds_mignight.js +++ b/lib/ace/theme/clouds_mignight.js @@ -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);\ diff --git a/lib/ace/theme/cobalt.js b/lib/ace/theme/cobalt.js index 5ae45ca1..409b1e80 100644 --- a/lib/ace/theme/cobalt.js +++ b/lib/ace/theme/cobalt.js @@ -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);\ diff --git a/lib/ace/theme/dawn.js b/lib/ace/theme/dawn.js index 02a46140..7c6a9525 100644 --- a/lib/ace/theme/dawn.js +++ b/lib/ace/theme/dawn.js @@ -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);\ diff --git a/lib/ace/theme/eclipse.js b/lib/ace/theme/eclipse.js index 9545a5eb..1d0b062d 100644 --- a/lib/ace/theme/eclipse.js +++ b/lib/ace/theme/eclipse.js @@ -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 diff --git a/lib/ace/theme/idle_fingers.js b/lib/ace/theme/idle_fingers.js index c0e3733a..3e7fd8ce 100644 --- a/lib/ace/theme/idle_fingers.js +++ b/lib/ace/theme/idle_fingers.js @@ -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);\ diff --git a/lib/ace/theme/kr_theme.js b/lib/ace/theme/kr_theme.js index 164232d7..2a2f6b82 100644 --- a/lib/ace/theme/kr_theme.js +++ b/lib/ace/theme/kr_theme.js @@ -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);\ diff --git a/lib/ace/theme/mono_industrial.js b/lib/ace/theme/mono_industrial.js index 20a0efbb..72eebb12 100644 --- a/lib/ace/theme/mono_industrial.js +++ b/lib/ace/theme/mono_industrial.js @@ -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);\ diff --git a/lib/ace/theme/monokai.js b/lib/ace/theme/monokai.js index 3e116bc6..ce579cbb 100644 --- a/lib/ace/theme/monokai.js +++ b/lib/ace/theme/monokai.js @@ -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);\ diff --git a/lib/ace/theme/textmate.js b/lib/ace/theme/textmate.js index 19d65d27..3311b1e3 100644 --- a/lib/ace/theme/textmate.js +++ b/lib/ace/theme/textmate.js @@ -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 diff --git a/lib/ace/theme/twilight.js b/lib/ace/theme/twilight.js index dba0f7a4..ea5f0eca 100644 --- a/lib/ace/theme/twilight.js +++ b/lib/ace/theme/twilight.js @@ -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);\ diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 08155d9c..bc289dc7 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -37,10 +37,10 @@ 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 lang = require("pilot/lang"); +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; diff --git a/plugins/cockpit/cli.js b/plugins/cockpit/cli.js index 85382cb9..e8764c88 100644 --- a/plugins/cockpit/cli.js +++ b/plugins/cockpit/cli.js @@ -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'); diff --git a/plugins/cockpit/ui/plain.js b/plugins/cockpit/ui/plain.js index 445a7864..618f3943 100644 --- a/plugins/cockpit/ui/plain.js +++ b/plugins/cockpit/ui/plain.js @@ -38,7 +38,7 @@ define(function(require, exports, module) { var editorCss = require("text!cockpit/ui/plain.css"); -var dom = require("pilot/dom").dom; +var dom = require("pilot/dom"); dom.importCssString(editorCss); var CliRequisition = require('cockpit/cli').CliRequisition; diff --git a/plugins/pilot/canon.js b/plugins/pilot/canon.js index 5bf4e79a..ce987290 100644 --- a/plugins/pilot/canon.js +++ b/plugins/pilot/canon.js @@ -39,7 +39,7 @@ 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; diff --git a/plugins/pilot/core.js b/plugins/pilot/core.js index 29aacf9e..e0332633 100644 --- a/plugins/pilot/core.js +++ b/plugins/pilot/core.js @@ -37,27 +37,24 @@ 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"; - core.provide = function(namespace) { - var parts = namespace.split("."); - var obj = window; - for (var i=0; i 5 || Math.abs(e.clientY - startY) > 5) - clicks = 0; - - if (clicks == count) { - clicks = 0; - callback(e); - } - return event.preventDefault(e); - }; - - event.addListener(el, "mousedown", listener); - core.isIE && event.addListener(el, "dblclick", listener); - }; - - event.addKeyListener = function(el, callback) { - var lastDown = null; - - event.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) { - event.addListener(el, "keypress", function(e) { - var keyId = e.keyIdentifier || e.keyCode; - if (lastDown !== keyId) { - return callback(e); - } else { - lastDown = null; - } - }); +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(); + + exports.removeEventListener("mousemove", onMouseMove, true); + exports.removeEventListener("mouseup", onMouseUp, true); + + e.stopPropagation(); + } + + exports.addEventListener("mousemove", onMouseMove, true); + exports.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.event = event; + 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) { + exports.addListener(el, "keypress", function(e) { + var keyId = e.keyIdentifier || e.keyCode; + if (lastDown !== keyId) { + return callback(e); + } else { + lastDown = null; + } + }); + } +}; }); diff --git a/plugins/pilot/event_emitter.js b/plugins/pilot/event_emitter.js index c7ddf1cd..cff5b379 100644 --- a/plugins/pilot/event_emitter.js +++ b/plugins/pilot/event_emitter.js @@ -37,7 +37,7 @@ define(function(require, exports, module) { -var lang = require('pilot/lang').lang; +var lang = require('pilot/lang'); var EventEmitter = {}; diff --git a/plugins/pilot/lang.js b/plugins/pilot/lang.js index f4538dbf..49ba8763 100644 --- a/plugins/pilot/lang.js +++ b/plugins/pilot/lang.js @@ -37,90 +37,86 @@ define(function(require, exports, module) { +exports.stringReverse = function(string) { + return string.split("").reverse().join(""); +}; - var lang = {}; +exports.stringRepeat = function (string, count) { + return new Array(count + 1).join(string); +}; - lang.stringReverse = function(string) { - return string.split("").reverse().join(""); +if (Array.prototype.indexOf) { + exports.arrayIndexOf = function(array, searchElement) { + return array.indexOf(searchElement); }; - - lang.stringRepeat = function (string, count) { - return new Array(count + 1).join(string); - }; - - if (Array.prototype.indexOf) { - lang.arrayIndexOf = function(array, searchElement) { - return array.indexOf(searchElement); - }; - } - else { - lang.arrayIndexOf = function(array, searchElement) { - for (var i=0; i Date: Wed, 15 Dec 2010 11:10:31 +0100 Subject: [PATCH 20/44] remove defineProperty shim --- plugins/pilot/fixoldbrowsers.js | 55 --------------------------------- 1 file changed, 55 deletions(-) diff --git a/plugins/pilot/fixoldbrowsers.js b/plugins/pilot/fixoldbrowsers.js index 1f7f1033..2dcb835b 100644 --- a/plugins/pilot/fixoldbrowsers.js +++ b/plugins/pilot/fixoldbrowsers.js @@ -37,61 +37,6 @@ define(function(require, exports, module) { -// Narwhal's shim for ES5 defineProperty -// ES5 15.2.3.6 -if (!Object.defineProperty) { - Object.defineProperty = function(object, property, descriptor) { - var has = Object.prototype.hasOwnProperty; - if (typeof descriptor == "object" && object.__defineGetter__) { - if (has.call(descriptor, "value")) { - if (!object.__lookupGetter__(property) && !object.__lookupSetter__(property)) { - // data property defined and no pre-existing accessors - object[property] = descriptor.value; - } - if (has.call(descriptor, "get") || has.call(descriptor, "set")) { - // descriptor has a value property but accessor already exists - throw new TypeError("Object doesn't support this action"); - } - } - // fail silently if "writable", "enumerable", or "configurable" - // are requested but not supported - /* - // alternate approach: - if ( // can't implement these features; allow false but not true - !(has.call(descriptor, "writable") ? descriptor.writable : true) || - !(has.call(descriptor, "enumerable") ? descriptor.enumerable : true) || - !(has.call(descriptor, "configurable") ? descriptor.configurable : true) - ) - throw new RangeError( - "This implementation of Object.defineProperty does not " + - "support configurable, enumerable, or writable." - ); - */ - else if (typeof descriptor.get == "function") { - object.__defineGetter__(property, descriptor.get); - } - if (typeof descriptor.set == "function") { - object.__defineSetter__(property, descriptor.set); - } - } - return object; - }; -} - -// ES5 15.2.3.7 -if (!Object.defineProperties) { - Object.defineProperties = function(object, properties) { - for (var property in properties) { - if (Object.prototype.hasOwnProperty.call(properties, property)) { - Object.defineProperty(object, property, properties[property]); - } - } - return object; - }; -} - - - /** * Array detector. * Firefox 3.5 and Safari 4 have this already. Chrome 4 however ... From a0d4f85b9e2038a1975a6d9fa72648661029797e Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 11:41:59 +0100 Subject: [PATCH 21/44] use ES5 Array.isArray instead of lang.isArray --- lib/ace/document.js | 2 +- plugins/pilot/lang.js | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/ace/document.js b/lib/ace/document.js index 6b792a5b..bd4454dc 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -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); diff --git a/plugins/pilot/lang.js b/plugins/pilot/lang.js index 49ba8763..2641837b 100644 --- a/plugins/pilot/lang.js +++ b/plugins/pilot/lang.js @@ -61,10 +61,6 @@ else { }; } -exports.isArray = function(value) { - return Object.prototype.toString.call(value) == "[object Array]"; -}; - exports.copyObject = function(obj) { var copy = {}; for (var key in obj) { From 69095379c345c2421d13ae00821e7b546015e0df Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 11:43:02 +0100 Subject: [PATCH 22/44] use ES5 bind() instead of lang.bind() --- lib/ace/editor.js | 22 +++++++++---------- lib/ace/scrollbar.js | 3 +-- lib/ace/virtual_renderer.js | 9 ++++---- plugins/pilot/fixoldbrowsers.js | 38 +++++++++++++++++++++++---------- plugins/pilot/lang.js | 6 ------ 5 files changed, 43 insertions(+), 35 deletions(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 2ccdf0fc..0471196a 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -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 { diff --git a/lib/ace/scrollbar.js b/lib/ace/scrollbar.js index e74dbf76..1a0315da 100644 --- a/lib/ace/scrollbar.js +++ b/lib/ace/scrollbar.js @@ -38,7 +38,6 @@ define(function(require, exports, module) { var oop = require("pilot/oop"); -var lang = require("pilot/lang"); var dom = require("pilot/dom"); var event = require("pilot/event"); var EventEmitter = require("pilot/event_emitter").EventEmitter; @@ -55,7 +54,7 @@ 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() { diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index bc289dc7..fab0da15 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -38,7 +38,6 @@ define(function(require, exports, module) { var oop = require("pilot/oop"); -var lang = require("pilot/lang"); var dom = require("pilot/dom"); var event = require("pilot/event"); var GutterLayer = require("ace/layer/gutter").Gutter; @@ -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(); diff --git a/plugins/pilot/fixoldbrowsers.js b/plugins/pilot/fixoldbrowsers.js index 2dcb835b..ee40f18e 100644 --- a/plugins/pilot/fixoldbrowsers.js +++ b/plugins/pilot/fixoldbrowsers.js @@ -65,22 +65,38 @@ if (!Object.keys) { } if (!Function.prototype.bind) { - // From Narwhal - Function.prototype.bind = function () { - var args = Array.prototype.slice.call(arguments); + // from MDC + // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind + Function.prototype.bind = function () { + var slice = [].slice; + var args = slice.call(arguments, 1); var self = this; - var bound = function () { - return self.call.apply( - self, - args.concat( - Array.prototype.slice.call(arguments) - ) - ); - }; + var nop = function () {}; + + // optimize common case + if (arguments.length == 1) { + var bound = return function() { + return fcn.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; }; } diff --git a/plugins/pilot/lang.js b/plugins/pilot/lang.js index 2641837b..9cd98c6a 100644 --- a/plugins/pilot/lang.js +++ b/plugins/pilot/lang.js @@ -82,12 +82,6 @@ exports.escapeRegExp = function(str) { return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1'); }; -exports.bind = function(fcn, context) { - return function() { - return fcn.apply(context, arguments); - }; -}; - exports.deferredCall = function(fcn) { var timer = null; From 19eecaaefce49a75e6ed57208cdf2242c3f73e35 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 11:59:05 +0100 Subject: [PATCH 23/44] replace lang.arrayIndexOf with ES5 indexOf() --- plugins/pilot/dom.js | 6 ++---- plugins/pilot/event_emitter.js | 6 ++---- plugins/pilot/fixoldbrowsers.js | 38 +++++++++++++++++++++++++++++++++ plugins/pilot/lang.js | 16 -------------- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/plugins/pilot/dom.js b/plugins/pilot/dom.js index ccd8c124..99d51636 100644 --- a/plugins/pilot/dom.js +++ b/plugins/pilot/dom.js @@ -37,8 +37,6 @@ define(function(require, exports, module) { -var lang = require("pilot/lang"); - exports.setText = function(elem, text) { if (elem.innerText !== undefined) { elem.innerText = text; @@ -50,7 +48,7 @@ exports.setText = function(elem, text) { exports.hasCssClass = function(el, name) { var classes = el.className.split(/\s+/g); - return lang.arrayIndexOf(classes, name) !== -1; + return classes.indexOf(name) !== -1; }; exports.addCssClass = function(el, name) { @@ -62,7 +60,7 @@ exports.addCssClass = function(el, name) { exports.removeCssClass = function(el, name) { var classes = el.className.split(/\s+/g); while (true) { - var index = lang.arrayIndexOf(classes, name); + var index = classes.indexOf(name); if (index == -1) { break; } diff --git a/plugins/pilot/event_emitter.js b/plugins/pilot/event_emitter.js index cff5b379..7a31f6ba 100644 --- a/plugins/pilot/event_emitter.js +++ b/plugins/pilot/event_emitter.js @@ -37,8 +37,6 @@ define(function(require, exports, module) { -var lang = require('pilot/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); } diff --git a/plugins/pilot/fixoldbrowsers.js b/plugins/pilot/fixoldbrowsers.js index ee40f18e..5e230ba5 100644 --- a/plugins/pilot/fixoldbrowsers.js +++ b/plugins/pilot/fixoldbrowsers.js @@ -49,6 +49,44 @@ if (!Array.isArray) { }; } +// 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; + }; +} + /** * Retrieves the list of keys on an object. */ diff --git a/plugins/pilot/lang.js b/plugins/pilot/lang.js index 9cd98c6a..5170a261 100644 --- a/plugins/pilot/lang.js +++ b/plugins/pilot/lang.js @@ -45,22 +45,6 @@ exports.stringRepeat = function (string, count) { return new Array(count + 1).join(string); }; -if (Array.prototype.indexOf) { - exports.arrayIndexOf = function(array, searchElement) { - return array.indexOf(searchElement); - }; -} -else { - exports.arrayIndexOf = function(array, searchElement) { - for (var i=0; i Date: Wed, 15 Dec 2010 12:35:17 +0100 Subject: [PATCH 24/44] we need more precision when measuring the character width fixes https://github.com/ajaxorg/editor/issues/issue/8 --- lib/ace/layer/text.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ace/layer/text.js b/lib/ace/layer/text.js index 724b5f36..c8f60391 100644 --- a/lib/ace/layer/text.js +++ b/lib/ace/layer/text.js @@ -79,7 +79,7 @@ var Text = function(parentEl) { self.$characterSize = size; self._dispatchEvent("changeCharaterSize", {data: size}); } - }, 500); + }, 1000); }; this.$fontStyles = { @@ -108,12 +108,12 @@ var Text = function(parentEl) { // 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"); + measureNode.innerHTML = new Array(10000).join("Xy"); document.body.insertBefore(measureNode, document.body.firstChild); var size = { height: measureNode.offsetHeight, - width: measureNode.offsetWidth / 2000 + width: measureNode.offsetWidth / 20000 }; document.body.removeChild(measureNode); From 32058c52060ee5c56835d228d6846c1f12eb25ad Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 12:35:36 +0100 Subject: [PATCH 25/44] fix syntax error --- plugins/pilot/fixoldbrowsers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pilot/fixoldbrowsers.js b/plugins/pilot/fixoldbrowsers.js index 5e230ba5..b3026a71 100644 --- a/plugins/pilot/fixoldbrowsers.js +++ b/plugins/pilot/fixoldbrowsers.js @@ -113,7 +113,7 @@ if (!Function.prototype.bind) { // optimize common case if (arguments.length == 1) { - var bound = return function() { + var bound = function() { return fcn.apply(this instanceof nop ? this : obj, arguments); }; } From caec77b63f63625d457819e5e3afb823a811ae0c Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 12:36:13 +0100 Subject: [PATCH 26/44] remove function, which uses getters and setters --- plugins/pilot/util.js | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/plugins/pilot/util.js b/plugins/pilot/util.js index e0cd4bb3..7fed5068 100644 --- a/plugins/pilot/util.js +++ b/plugins/pilot/util.js @@ -586,33 +586,6 @@ exports.clone = function(object, deep) { return object; }; - -/** - * Helper method for extending one object with another - * Copies all properties from source to target. Returns the extended target - * object. - * Taken from John Resig, http://ejohn.org/blog/javascript-getters-and-setters/. - */ -exports.mixin = function(a, b) { - for (var i in b) { - var g = b.__lookupGetter__(i); - var s = b.__lookupSetter__(i); - - if (g || s) { - if (g) { - a.__defineGetter__(i, g); - } - if (s) { - a.__defineSetter__(i, s); - } - } else { - a[i] = b[i]; - } - } - - return a; -}; - /** * Basically taken from Sproutcore. * Replaces the count items from idx with objects. From 46552265e5abf2450f5bd8985b9b9c21fde2aa36 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 12:37:47 +0100 Subject: [PATCH 27/44] fix url to the demo page --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 9b74242d..542a1579 100644 --- a/index.html +++ b/index.html @@ -62,7 +62,7 @@

Demo

-Check out the demo. +Check out the demo.

Contact

Fabian Jakobs (fabian.jakobs@web.de)

From 65407f8ef8203c47d1345f4bdde595a4a6d2fc9f Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 14:12:04 +0100 Subject: [PATCH 28/44] fix css and move scripts to the bottom to improve load time and to avoid having to wait for document.onload --- editor.html | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/editor.html b/editor.html index 81ceef48..1f8679d8 100644 --- a/editor.html +++ b/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; } - - - -
@@ -179,5 +156,29 @@ for i in sys.argv[1:]: + + + + + + \ No newline at end of file From 634e9ac890a1f31aa7fdd36ea69a30e0f2c5de69 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 14:13:44 +0100 Subject: [PATCH 29/44] optimize text size measurement code and fix ugly off by one error --- lib/ace/layer/text.js | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/lib/ace/layer/text.js b/lib/ace/layer/text.js index c8f60391..7af4c7aa 100644 --- a/lib/ace/layer/text.js +++ b/lib/ace/layer/text.js @@ -39,6 +39,7 @@ define(function(require, exports, module) { 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) { @@ -79,7 +80,7 @@ var Text = function(parentEl) { self.$characterSize = size; self._dispatchEvent("changeCharaterSize", {data: size}); } - }, 1000); + }, 500); }; this.$fontStyles = { @@ -91,32 +92,37 @@ 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"; + 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! + var n = 1000; + measureNode.innerHTML = lang.stringRepeat("Xy", n); + document.body.insertBefore(measureNode, document.body.firstChild); + } + var style = this.$measureNode; 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(10000).join("Xy"); - document.body.insertBefore(measureNode, document.body.firstChild); - var size = { - height: measureNode.offsetHeight, - width: measureNode.offsetWidth / 20000 + height: this.$measureNode.offsetHeight, + width: this.$measureNode.offsetWidth / (n * 2) }; - document.body.removeChild(measureNode); return size; }; From 7bb4950a1c497287f99c7658ea755fd03f932aa3 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 14:14:15 +0100 Subject: [PATCH 30/44] fix lib functions --- plugins/pilot/event.js | 8 ++++---- plugins/pilot/fixoldbrowsers.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/pilot/event.js b/plugins/pilot/event.js index 0e2d003e..6b360007 100644 --- a/plugins/pilot/event.js +++ b/plugins/pilot/event.js @@ -148,14 +148,14 @@ else { eventHandler && eventHandler(e); releaseCaptureHandler && releaseCaptureHandler(); - exports.removeEventListener("mousemove", onMouseMove, true); - exports.removeEventListener("mouseup", onMouseUp, true); + el.removeEventListener("mousemove", onMouseMove, true); + el.removeEventListener("mouseup", onMouseUp, true); e.stopPropagation(); } - exports.addEventListener("mousemove", onMouseMove, true); - exports.addEventListener("mouseup", onMouseUp, true); + el.addEventListener("mousemove", onMouseMove, true); + el.addEventListener("mouseup", onMouseUp, true); }; } diff --git a/plugins/pilot/fixoldbrowsers.js b/plugins/pilot/fixoldbrowsers.js index b3026a71..5387187f 100644 --- a/plugins/pilot/fixoldbrowsers.js +++ b/plugins/pilot/fixoldbrowsers.js @@ -105,7 +105,7 @@ if (!Object.keys) { if (!Function.prototype.bind) { // from MDC // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind - Function.prototype.bind = function () { + Function.prototype.bind = function (obj) { var slice = [].slice; var args = slice.call(arguments, 1); var self = this; @@ -114,7 +114,7 @@ if (!Function.prototype.bind) { // optimize common case if (arguments.length == 1) { var bound = function() { - return fcn.apply(this instanceof nop ? this : obj, arguments); + return self.apply(this instanceof nop ? this : obj, arguments); }; } else { From 5383a297c2820e32a0eb7b3a89076c40b32ceb4d Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 14:14:41 +0100 Subject: [PATCH 31/44] comment out console.log statements as the log module is not yet loaded at these points --- plugins/cockpit/ui/plain.js | 4 ++-- plugins/pilot/index.js | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/cockpit/ui/plain.js b/plugins/cockpit/ui/plain.js index 618f3943..677f7f86 100644 --- a/plugins/cockpit/ui/plain.js +++ b/plugins/cockpit/ui/plain.js @@ -48,7 +48,7 @@ exports.startup = function(data, reason) { // TODO: we should have a better way to specify command lines??? this.input = document.getElementById('cockpit'); if (!this.input) { - console.log('No element with an id of cockpit. Bailing on plain cli'); + // console.log('No element with an id of cockpit. Bailing on plain cli'); return; } @@ -87,7 +87,7 @@ exports.startup = function(data, reason) { end: this.input.selectionEnd } }); - console.log(JSON.stringify(cli.getHints())); + //console.log(JSON.stringify(cli.getHints())); } // return handled; diff --git a/plugins/pilot/index.js b/plugins/pilot/index.js index 157d4f1c..f576b29c 100644 --- a/plugins/pilot/index.js +++ b/plugins/pilot/index.js @@ -52,7 +52,6 @@ define(packages, function(require, exports, module) { exports.startup = function(data, reason) { deps.forEach(function(dep) { - console.log("test startup for " + dep); var module = require(dep); if (typeof module.startup === "function") { module.startup(data, reason); From a2d271677f91ccc638f3cdad6bd275664dda11e8 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 15:40:53 +0100 Subject: [PATCH 32/44] some Opera key handling fixes (not perfect yet) --- lib/ace/keybinding.js | 10 ++++++++-- plugins/pilot/core.js | 1 + plugins/pilot/event.js | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/ace/keybinding.js b/lib/ace/keybinding.js index a57c71cc..fecf2463 100644 --- a/lib/ace/keybinding.js +++ b/lib/ace/keybinding.js @@ -49,8 +49,14 @@ 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 diff --git a/plugins/pilot/core.js b/plugins/pilot/core.js index e0332633..40991657 100644 --- a/plugins/pilot/core.js +++ b/plugins/pilot/core.js @@ -44,6 +44,7 @@ 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]"; exports.provide = function(namespace) { var parts = namespace.split("."); diff --git a/plugins/pilot/event.js b/plugins/pilot/event.js index 6b360007..2beaff41 100644 --- a/plugins/pilot/event.js +++ b/plugins/pilot/event.js @@ -224,7 +224,7 @@ exports.addKeyListener = function(el, callback) { }); // repeated keys are fired as keypress and not keydown events - if (core.isMac && core.isGecko) { + if (core.isMac && (core.isGecko || core.isOpera)) { exports.addListener(el, "keypress", function(e) { var keyId = e.keyIdentifier || e.keyCode; if (lastDown !== keyId) { From 633293ee5ef09bce1878c5473ea024f2cd35110d Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 15:41:08 +0100 Subject: [PATCH 33/44] fix character size measurement --- lib/ace/layer/text.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/ace/layer/text.js b/lib/ace/layer/text.js index 7af4c7aa..98ff7bfc 100644 --- a/lib/ace/layer/text.js +++ b/lib/ace/layer/text.js @@ -92,6 +92,7 @@ var Text = function(parentEl) { }, this.$measureSizes = function() { + var n = 1000; if (!this.$measureNode) { var measureNode = this.$measureNode = document.createElement("div"); var style = measureNode.style; @@ -107,12 +108,11 @@ var Text = function(parentEl) { // 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! - var n = 1000; measureNode.innerHTML = lang.stringRepeat("Xy", n); document.body.insertBefore(measureNode, document.body.firstChild); } - var style = this.$measureNode; + var style = this.$measureNode.style; for (var prop in this.$fontStyles) { var value = dom.computedStyle(this.element, prop); style[prop] = value; @@ -122,7 +122,6 @@ var Text = function(parentEl) { height: this.$measureNode.offsetHeight, width: this.$measureNode.offsetWidth / (n * 2) }; - return size; }; From e97f9dbbb78857ba1b0c8e52fa6772a767637f0d Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 16:19:09 +0100 Subject: [PATCH 34/44] removed redundant "undefined" --- lib/ace/mode/javascript_highlight_rules.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ace/mode/javascript_highlight_rules.js b/lib/ace/mode/javascript_highlight_rules.js index 3dd063f2..38fe7100 100644 --- a/lib/ace/mode/javascript_highlight_rules.js +++ b/lib/ace/mode/javascript_highlight_rules.js @@ -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") From ac923b5813b45984d80dee293383d0375e829b99 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 17:32:06 +0100 Subject: [PATCH 35/44] IE fixes --- plugins/cockpit/ui/plain.js | 3 ++- plugins/pilot/console.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/cockpit/ui/plain.js b/plugins/cockpit/ui/plain.js index 677f7f86..ab2266ca 100644 --- a/plugins/cockpit/ui/plain.js +++ b/plugins/cockpit/ui/plain.js @@ -39,6 +39,7 @@ define(function(require, exports, module) { var editorCss = require("text!cockpit/ui/plain.css"); var dom = require("pilot/dom"); +var event = require("pilot/event"); dom.importCssString(editorCss); var CliRequisition = require('cockpit/cli').CliRequisition; @@ -69,7 +70,7 @@ exports.startup = function(data, reason) { }.bind(this)); */ - this.input.addEventListener('keyup', function(ev) { + event.addListener(this.input, 'keyup', function(ev) { /* var handled = keyboardManager.processKeyEvent(ev, this, { isCommandLine: true, isKeyUp: true diff --git a/plugins/pilot/console.js b/plugins/pilot/console.js index b1fe5190..c386f855 100644 --- a/plugins/pilot/console.js +++ b/plugins/pilot/console.js @@ -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; } From b817889ad8787e4c9801514d6400982645d96224 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 17:33:32 +0100 Subject: [PATCH 36/44] add JS implementation for forEach --- plugins/pilot/fixoldbrowsers.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/plugins/pilot/fixoldbrowsers.js b/plugins/pilot/fixoldbrowsers.js index 5387187f..04929418 100644 --- a/plugins/pilot/fixoldbrowsers.js +++ b/plugins/pilot/fixoldbrowsers.js @@ -87,6 +87,26 @@ if (!Array.prototype.indexOf) }; } +// 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. */ @@ -102,7 +122,7 @@ if (!Object.keys) { }; } -if (!Function.prototype.bind) { +if (!Function.prototype.bind) { // from MDC // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind Function.prototype.bind = function (obj) { From 062c39643293bbbf85374e382ec4f9358ebd93df Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 17:34:24 +0100 Subject: [PATCH 37/44] IE rendering fix --- lib/ace/virtual_renderer.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index fab0da15..03c3322e 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -184,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) { @@ -195,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; } } @@ -210,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) { @@ -372,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); } From bfa4748b1b6dc1e15c2e4be3d61d57cd3666f868 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 18:40:46 +0100 Subject: [PATCH 38/44] add collapse lines in range --- lib/ace/editor.js | 11 +++-------- lib/ace/range.js | 7 +++++++ lib/ace/test/range_test.js | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 0471196a..c8647636 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -715,16 +715,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 }; }; diff --git a/lib/ace/range.js b/lib/ace/range.js index a818617a..ae49f04e 100644 --- a/lib/ace/range.js +++ b/lib/ace/range.js @@ -137,6 +137,13 @@ var Range = function(startRow, startColumn, endRow, endColumn) { this.clone = function() { return Range.fromPoints(this.start, this.end); }; + + this.collapseLines = 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( diff --git a/lib/ace/test/range_test.js b/lib/ace/test/range_test.js index a590889a..471c6857 100644 --- a/lib/ace/test/range_test.js +++ b/lib/ace/test/range_test.js @@ -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); } }; From aa594119b7c33a5614276dac291a96ec5fb7efa1 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 19:16:44 +0100 Subject: [PATCH 39/44] toggleCommentLines and indentRows now take row numbers instead of ranges as arguments --- lib/ace/document.js | 6 +++--- lib/ace/editor.js | 16 ++++++-------- lib/ace/mode/html.js | 2 +- lib/ace/mode/javascript.js | 8 +++---- lib/ace/mode/python.js | 8 +++---- lib/ace/mode/text.js | 2 +- lib/ace/range.js | 2 +- lib/ace/test/mode/css_test.js | 4 +--- lib/ace/test/mode/html_test.js | 2 +- lib/ace/test/mode/javascript_test.js | 21 ++++++++++-------- lib/ace/test/mode/text_test.js | 4 +--- lib/ace/test/mode/xml_test.js | 4 +--- lib/ace/test/text_edit_test.js | 32 ++++++++++++++++++++++++---- 13 files changed, 64 insertions(+), 47 deletions(-) diff --git a/lib/ace/document.js b/lib/ace/document.js index bd4454dc..291ad4c3 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -622,12 +622,12 @@ var Document = function(text, mode) { return end; }; - this.indentRows = function(range, indentString) { + this.indentRows = function(startRow, endRow, indentString) { indentString = indentString.replace("\t", this.getTabString()); - for (var row=range.start.row; row<=range.end.row; row++) { + 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; }; diff --git a/lib/ace/editor.js b/lib/ace/editor.js index c8647636..7c18514c 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -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 { @@ -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); }); }; diff --git a/lib/ace/mode/html.js b/lib/ace/mode/html.js index a6ecc6c8..3d8f07f5 100644 --- a/lib/ace/mode/html.js +++ b/lib/ace/mode/html.js @@ -54,7 +54,7 @@ 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; }); diff --git a/lib/ace/mode/javascript.js b/lib/ace/mode/javascript.js index 1e4eb24b..1f5f4c2c 100644 --- a/lib/ace/mode/javascript.js +++ b/lib/ace/mode/javascript.js @@ -52,12 +52,12 @@ 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(Mode, 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(Mode, TextMode); return -2; } else { - return doc.indentRows(range, "//"); + return doc.indentRows(startRow, endRow, "//"); } }; diff --git a/lib/ace/mode/python.js b/lib/ace/mode/python.js index 7687e553..d60c08b0 100644 --- a/lib/ace/mode/python.js +++ b/lib/ace/mode/python.js @@ -52,12 +52,12 @@ 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(Mode, 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(Mode, TextMode); return -2; } else { - return doc.indentRows(range, "#"); + return doc.indentRows(startRow, endRow, "#"); } }; diff --git a/lib/ace/mode/text.js b/lib/ace/mode/text.js index 0e18d038..361dd572 100644 --- a/lib/ace/mode/text.js +++ b/lib/ace/mode/text.js @@ -50,7 +50,7 @@ var Mode = function() { return this.$tokenizer; }; - this.toggleCommentLines = function(state, doc, range) { + this.toggleCommentLines = function(state, doc, startRow, endRow) { return 0; }; diff --git a/lib/ace/range.js b/lib/ace/range.js index ae49f04e..65775cb0 100644 --- a/lib/ace/range.js +++ b/lib/ace/range.js @@ -138,7 +138,7 @@ var Range = function(startRow, startColumn, endRow, endColumn) { return Range.fromPoints(this.start, this.end); }; - this.collapseLines = function() { + 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 diff --git a/lib/ace/test/mode/css_test.js b/lib/ace/test/mode/css_test.js index 27b5e55a..cbcefb21 100644 --- a/lib/ace/test/mode/css_test.js +++ b/lib/ace/test/mode/css_test.js @@ -38,7 +38,6 @@ define(function(require, exports, module) { var Document = require("ace/document").Document; -var Range = require("ace/range").Range; var Css = require("ace/mode/css").Mode; var CssTest = new TestCase("mode.CssTest", { @@ -50,8 +49,7 @@ 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); + var comment = this.mode.toggleCommentLines("start", doc, 0, 1); assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString()); }, diff --git a/lib/ace/test/mode/html_test.js b/lib/ace/test/mode/html_test.js index 1e631b55..d37e47e8 100644 --- a/lib/ace/test/mode/html_test.js +++ b/lib/ace/test/mode/html_test.js @@ -51,7 +51,7 @@ 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); + var comment = this.mode.toggleCommentLines("start", doc, 0, 1); assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString()); }, diff --git a/lib/ace/test/mode/javascript_test.js b/lib/ace/test/mode/javascript_test.js index 52de56d1..ed65caaf 100644 --- a/lib/ace/test/mode/javascript_test.js +++ b/lib/ace/test/mode/javascript_test.js @@ -38,7 +38,6 @@ define(function(require, exports, module) { var Document = require("ace/document").Document; -var Range = require("ace/range").Range; var Tokenizer = require("ace/tokenizer").Tokenizer; var JavaScript = require("ace/mode/javascript").Mode; @@ -60,32 +59,36 @@ var JavaScriptTest = new TestCase("mode.JavaScriptTest", { "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); + var comment = this.mode.toggleCommentLines("start", doc, 0, 1); assertEquals(["// 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); + var comment = this.mode.toggleCommentLines("start", doc, 0, 1); assertEquals([" 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); + assertEquals([" 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); + var comment = this.mode.toggleCommentLines("start", doc, 0, 2); assertEquals(["//// 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); + var comment = this.mode.toggleCommentLines("start", doc, 0, 1); assertEquals(["cde", " fg"].join("\n"), doc.toString()); }, diff --git a/lib/ace/test/mode/text_test.js b/lib/ace/test/mode/text_test.js index ef41e7b3..5f39311e 100644 --- a/lib/ace/test/mode/text_test.js +++ b/lib/ace/test/mode/text_test.js @@ -38,7 +38,6 @@ define(function(require, exports, module) { var Document = require("ace/document").Document; -var Range = require("ace/range").Range; var Text = require("ace/mode/text").Mode; var TextTest = new TestCase("mode.TextTest", { @@ -50,8 +49,7 @@ 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); + var comment = this.mode.toggleCommentLines("start", doc, 0, 1); assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString()); }, diff --git a/lib/ace/test/mode/xml_test.js b/lib/ace/test/mode/xml_test.js index 8f2962c6..bf3578da 100644 --- a/lib/ace/test/mode/xml_test.js +++ b/lib/ace/test/mode/xml_test.js @@ -38,7 +38,6 @@ define(function(require, exports, module) { var Document = require("ace/document").Document; -var Range = require("ace/range").Range; var Tokenizer = require("ace/tokenizer").Tokenizer; var Xml = require("ace/mode/xml").Mode; @@ -60,8 +59,7 @@ var XmlTest = new TestCase("mode.XmlTest", { "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); + var comment = this.mode.toggleCommentLines("start", doc, 0, 1); assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString()); }, diff --git a/lib/ace/test/text_edit_test.js b/lib/ace/test/text_edit_test.js index ea9b77a9..61658cca 100644 --- a/lib/ace/test/text_edit_test.js +++ b/lib/ace/test/text_edit_test.js @@ -114,8 +114,7 @@ var Test = { 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); @@ -124,13 +123,24 @@ var Test = { assert.position(range.end, 2, 7); }, + "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, 5); editor.getSelection().selectDown(); - editor.getSelection().selectDown(); + editor.getSelection().selectDown(); editor.blockOutdent(); assert.equal(doc.toString(), [" a12345", "b12345", " c12345"].join("\n")); @@ -166,7 +176,6 @@ var Test = { editor.moveCursorTo(0, 2); editor.getSelection().selectDown(); - editor.toggleCommentLines(); assert.equal(["// abc", "//cde"].join("\n"), doc.toString()); @@ -190,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 From 79872cac5ddd1da329bb996bf8858a4ed51d60ce Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 19:17:45 +0100 Subject: [PATCH 40/44] collapse line selection for outdented rows --- lib/ace/document.js | 13 +++++++------ lib/ace/editor.js | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/ace/document.js b/lib/ace/document.js index 291ad4c3..32ae57a9 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -632,10 +632,11 @@ var Document = function(text, mode) { }; 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) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 7c18514c..a442c38f 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -629,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(); From ba7168156b8d8fc0d5ea9d3b124d8876f1ed76ac Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 19:28:30 +0100 Subject: [PATCH 41/44] fix move lines up + unit test --- lib/ace/document.js | 2 +- lib/ace/test/document_test.js | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/ace/document.js b/lib/ace/document.js index 32ae57a9..3dbb438e 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -665,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-1, this.lines[firstRow-1], lastRow, this.lines[lastRow].length)); + 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); diff --git a/lib/ace/test/document_test.js b/lib/ace/test/document_test.js index fd5995da..9b24c404 100644 --- a/lib/ace/test/document_test.js +++ b/lib/ace/test/document_test.js @@ -81,35 +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"]); doc.moveLinesDown(0, 1); - 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"]); + var doc = new Document(["a1", "a2", "a3", "a4"]); doc.moveLinesUp(2, 3); - 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() { From 123da20bd59e871f7cda5828b4781e0e7b5de476 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 20:00:46 +0100 Subject: [PATCH 42/44] no capture groups in tokenizer regexps --- lib/ace/mode/javascript_highlight_rules.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ace/mode/javascript_highlight_rules.js b/lib/ace/mode/javascript_highlight_rules.js index 38fe7100..6d6afa2b 100644 --- a/lib/ace/mode/javascript_highlight_rules.js +++ b/lib/ace/mode/javascript_highlight_rules.js @@ -119,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+" From 36595bd9d6602606e106e0004b695672ecc631ef Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 20:01:09 +0100 Subject: [PATCH 43/44] convert missing unit tests --- lib/ace/test/all.js | 11 ++- lib/ace/test/mode/css_test.js | 31 ++++---- lib/ace/test/mode/css_tokenizer_test.js | 35 +++++----- lib/ace/test/mode/html_test.js | 25 ++++--- lib/ace/test/mode/html_tokenizer_test.js | 39 ++++++----- lib/ace/test/mode/javascript_test.js | 70 ++++++++++--------- .../test/mode/javascript_tokenizer_test.js | 55 ++++++++------- lib/ace/test/mode/text_test.js | 21 +++--- lib/ace/test/mode/xml_test.js | 29 ++++---- lib/ace/test/mode/xml_tokenizer_test.js | 28 ++++---- 10 files changed, 191 insertions(+), 153 deletions(-) diff --git a/lib/ace/test/all.js b/lib/ace/test/all.js index 7ed48c4a..88c03478 100644 --- a/lib/ace/test/all.js +++ b/lib/ace/test/all.js @@ -47,5 +47,14 @@ async.concat( require("./range_test"), require("./search_test"), require("./selection_test"), - require("./text_edit_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(); diff --git a/lib/ace/test/mode/css_test.js b/lib/ace/test/mode/css_test.js index cbcefb21..7251fb1c 100644 --- a/lib/ace/test/mode/css_test.js +++ b/lib/ace/test/mode/css_test.js @@ -35,13 +35,13 @@ * * ***** END LICENSE BLOCK ***** */ -define(function(require, exports, module) { - +require("../../../../support/paths"); + var Document = require("ace/document").Document; -var Css = require("ace/mode/css").Mode; - -var CssTest = new TestCase("mode.CssTest", { +var CssMode = require("ace/mode/css").Mode; +var assert = require("../assertions"); +var Test = { setUp : function() { this.mode = new CssMode(); }, @@ -50,24 +50,27 @@ var CssTest = new TestCase("mode.CssTest", { var doc = new Document([" abc", "cde", "fg"].join("\n")); var comment = this.mode.toggleCommentLines("start", doc, 0, 1); - assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString()); + 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() \ No newline at end of file diff --git a/lib/ace/test/mode/css_tokenizer_test.js b/lib/ace/test/mode/css_tokenizer_test.js index 858770ba..84f63f6f 100644 --- a/lib/ace/test/mode/css_tokenizer_test.js +++ b/lib/ace/test/mode/css_tokenizer_test.js @@ -35,12 +35,12 @@ * * ***** END LICENSE BLOCK ***** */ -define(function(require, exports, module) { +require("../../../../support/paths"); -var Css = require("ace/mode/css").Mode; - -var CssTest = new TestCase("mode.CssTest", { +var CssMode = require("ace/mode/css").Mode; +var assert = require("../assertions"); +var Test = { setUp : function() { this.tokenizer = new CssMode().getTokenizer(); }, @@ -49,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); } -}); +}; -}); \ No newline at end of file +module.exports = require("async/test").testcase(Test); + +if (module === require.main) + module.exports.exec() \ No newline at end of file diff --git a/lib/ace/test/mode/html_test.js b/lib/ace/test/mode/html_test.js index d37e47e8..9e28d32f 100644 --- a/lib/ace/test/mode/html_test.js +++ b/lib/ace/test/mode/html_test.js @@ -35,15 +35,15 @@ * * ***** END LICENSE BLOCK ***** */ -define(function(require, exports, module) { +require("../../../../support/paths"); var Document = require("ace/document").Document; var Range = require("ace/range").Range; -var Html = require("ace/mode/html").Mode; +var HtmlMode = require("ace/mode/html").Mode; +var assert = require("../assertions"); -var HtmlTest = new TestCase("mode.HtmlTest", { - - setUp : function() { +var Test = { + setUp : function() { this.mode = new HtmlMode(); }, @@ -52,14 +52,17 @@ var HtmlTest = new TestCase("mode.HtmlTest", { var range = new Range(0, 3, 1, 1); var comment = this.mode.toggleCommentLines("start", doc, 0, 1); - assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString()); + 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")); } -}); +}; -}); \ No newline at end of file +module.exports = require("async/test").testcase(Test); + +if (module === require.main) + module.exports.exec() \ No newline at end of file diff --git a/lib/ace/test/mode/html_tokenizer_test.js b/lib/ace/test/mode/html_tokenizer_test.js index 6c89dc81..da82074b 100644 --- a/lib/ace/test/mode/html_tokenizer_test.js +++ b/lib/ace/test/mode/html_tokenizer_test.js @@ -35,12 +35,12 @@ * * ***** END LICENSE BLOCK ***** */ -define(function(require, exports, module) { +require("../../../../support/paths"); -var Html = require("ace/mode/html").Mode; - -var HtmlTest = new TestCase("mode.HtmlTest", { +var HtmlMode = require("ace/mode/html").Mode; +var assert = require("../assertions"); +var Test = { setUp : function() { this.tokenizer = new HtmlMode().getTokenizer(); }, @@ -50,19 +50,22 @@ var HtmlTest = new TestCase("mode.HtmlTest", { var line = "'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); } -}); +}; -}); \ No newline at end of file +module.exports = require("async/test").testcase(Test); + +if (module === require.main) + module.exports.exec() \ No newline at end of file diff --git a/lib/ace/test/mode/javascript_test.js b/lib/ace/test/mode/javascript_test.js index ed65caaf..20a75d14 100644 --- a/lib/ace/test/mode/javascript_test.js +++ b/lib/ace/test/mode/javascript_test.js @@ -35,39 +35,39 @@ * * ***** END LICENSE BLOCK ***** */ -define(function(require, exports, module) { +require("../../../../support/paths"); var Document = require("ace/document").Document; var Tokenizer = require("ace/tokenizer").Tokenizer; -var JavaScript = require("ace/mode/javascript").Mode; +var JavaScriptMode = require("ace/mode/javascript").Mode; +var assert = require("../assertions"); -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 comment = this.mode.toggleCommentLines("start", doc, 0, 1); - assertEquals(["// abc", "//cde", "fg"].join("\n"), doc.toString()); + 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 comment = this.mode.toggleCommentLines("start", doc, 0, 1); - assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString()); + assert.equal([" abc", "cde", "fg"].join("\n"), doc.toString()); }, "test: toggle comment lines twice should return the original text" : function() { @@ -75,74 +75,76 @@ var JavaScriptTest = new TestCase("mode.JavaScriptTest", { this.mode.toggleCommentLines("start", doc, 0, 2); this.mode.toggleCommentLines("start", doc, 0, 2); - assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString()); + 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 comment = this.mode.toggleCommentLines("start", doc, 0, 2); - assertEquals(["//// abc", "////cde", "//fg"].join("\n"), doc.toString()); + 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 comment = this.mode.toggleCommentLines("start", doc, 0, 1); - assertEquals(["cde", " fg"].join("\n"), doc.toString()); + 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); -}); \ No newline at end of file +if (module === require.main) + module.exports.exec() \ No newline at end of file diff --git a/lib/ace/test/mode/javascript_tokenizer_test.js b/lib/ace/test/mode/javascript_tokenizer_test.js index 518d58e4..e292574b 100644 --- a/lib/ace/test/mode/javascript_tokenizer_test.js +++ b/lib/ace/test/mode/javascript_tokenizer_test.js @@ -35,12 +35,12 @@ * * ***** END LICENSE BLOCK ***** */ -define(function(require, exports, module) { - -var JavaScript = require("ace/mode/javascript").Mode; - -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(); }, @@ -50,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() { @@ -61,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() { @@ -74,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() { @@ -85,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); } -}); +}; -}); \ No newline at end of file +module.exports = require("async/test").testcase(Test); + +if (module === require.main) + module.exports.exec() \ No newline at end of file diff --git a/lib/ace/test/mode/text_test.js b/lib/ace/test/mode/text_test.js index 5f39311e..79dc35aa 100644 --- a/lib/ace/test/mode/text_test.js +++ b/lib/ace/test/mode/text_test.js @@ -35,13 +35,13 @@ * * ***** END LICENSE BLOCK ***** */ -define(function(require, exports, module) { - +require("../../../../support/paths"); + var Document = require("ace/document").Document; -var Text = require("ace/mode/text").Mode; - -var TextTest = new TestCase("mode.TextTest", { +var TextMode = require("ace/mode/text").Mode; +var assert = require("../assertions"); +var Test = { setUp : function() { this.mode = new TextMode(); }, @@ -50,13 +50,16 @@ var TextTest = new TestCase("mode.TextTest", { var doc = new Document([" abc", "cde", "fg"]); var comment = this.mode.toggleCommentLines("start", doc, 0, 1); - assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString()); + 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", " ")); } -}); +}; -}); \ No newline at end of file +module.exports = require("async/test").testcase(Test); + +if (module === require.main) + module.exports.exec() \ No newline at end of file diff --git a/lib/ace/test/mode/xml_test.js b/lib/ace/test/mode/xml_test.js index bf3578da..11ca111a 100644 --- a/lib/ace/test/mode/xml_test.js +++ b/lib/ace/test/mode/xml_test.js @@ -35,14 +35,14 @@ * * ***** END LICENSE BLOCK ***** */ -define(function(require, exports, module) { - +require("../../../../support/paths"); + var Document = require("ace/document").Document; var Tokenizer = require("ace/tokenizer").Tokenizer; -var Xml = require("ace/mode/xml").Mode; - -var XmlTest = new TestCase("mode.XmlTest", { +var XmlMode = require("ace/mode/xml").Mode; +var assert = require("../assertions"); +var Test = { setUp : function() { this.mode = new XmlMode(); }, @@ -50,24 +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("", "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 comment = this.mode.toggleCommentLines("start", doc, 0, 1); - assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString()); + 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")); } -}); +}; -}); \ No newline at end of file +module.exports = require("async/test").testcase(Test); + +if (module === require.main) + module.exports.exec() \ No newline at end of file diff --git a/lib/ace/test/mode/xml_tokenizer_test.js b/lib/ace/test/mode/xml_tokenizer_test.js index cb03b4f5..d1e16bc2 100644 --- a/lib/ace/test/mode/xml_tokenizer_test.js +++ b/lib/ace/test/mode/xml_tokenizer_test.js @@ -35,12 +35,13 @@ * * ***** END LICENSE BLOCK ***** */ -define(function(require, exports, module) { + +require("../../../../support/paths"); -var Xml = require("ace/mode/xml").Mode; - -var XmlTest = new TestCase("mode.XmlTest", { +var XmlMode = require("ace/mode/xml").Mode; +var assert = require("../assertions"); +var Test = { setUp : function() { this.tokenizer = new XmlMode().getTokenizer(); }, @@ -50,13 +51,16 @@ var XmlTest = new TestCase("mode.XmlTest", { var line = "//Juhu 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); } -}); +}; -}); \ No newline at end of file +module.exports = require("async/test").testcase(Test); + +if (module === require.main) + module.exports.exec() \ No newline at end of file From bf71127511eaf03adae70b8ed7a0c60334375219 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 20:01:26 +0100 Subject: [PATCH 44/44] remove references to window (not supported by node) --- lib/ace/tokenizer.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/ace/tokenizer.js b/lib/ace/tokenizer.js index c5cdf964..e67f61f4 100644 --- a/lib/ace/tokenizer.js +++ b/lib/ace/tokenizer.js @@ -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