Merge branch 'master' of github.com:ajaxorg/ace

This commit is contained in:
Fabian Jakobs 2011-02-08 09:04:19 +01:00
commit 44c1196e08
30 changed files with 488 additions and 176 deletions

View file

@ -1,3 +1,9 @@
2011.02.xx, Version 0.1.4
* Fix packaged version of the Eclipse mode
* Loading of workers is more robust
* Fix "click selection"
2011.02.04, Version 0.1.4 2011.02.04, Version 0.1.4
* Add C/C++ mode contributed by Gastón Kleiman * Add C/C++ mode contributed by Gastón Kleiman

View file

@ -130,7 +130,7 @@ copy({
copy.source.commonjs({ copy.source.commonjs({
project: project, project: project,
require: [ 'cockpit/index' ] require: [ 'cockpit/index' ]
}), })
], ],
filter: [ copy.filter.moduleDefines ], filter: [ copy.filter.moduleDefines ],
dest: cockpit dest: cockpit
@ -175,7 +175,7 @@ project.assmeAllFilesLoaded();
copy.source.commonjs({ copy.source.commonjs({
project: project, project: project,
require: [ 'ace/mode/' + mode ] require: [ 'ace/mode/' + mode ]
}), })
], ],
filter: [ copy.filter.moduleDefines, copy.filter.uglifyjs ], filter: [ copy.filter.moduleDefines, copy.filter.uglifyjs ],
dest: "build/src/mode-" + mode + ".js" dest: "build/src/mode-" + mode + ".js"
@ -200,9 +200,9 @@ copy({
'pilot/oop', 'pilot/oop',
'ace/mode/javascript_worker' 'ace/mode/javascript_worker'
] ]
}), })
], ],
filter: [ copy.filter.moduleDefines, copy.filter.uglifyjs ], filter: [ copy.filter.moduleDefines],
dest: jsWorker dest: jsWorker
}); });
copy({ copy({
@ -210,6 +210,7 @@ copy({
aceHome + "/lib/ace/worker/worker.js", aceHome + "/lib/ace/worker/worker.js",
jsWorker jsWorker
], ],
filter: [ copy.filter.uglifyjs ],
dest: "build/src/worker-javascript.js" dest: "build/src/worker-javascript.js"
}); });
@ -220,7 +221,7 @@ copy({
root: aceHome + '/lib', root: aceHome + '/lib',
include: "ace/theme/eclipse.js" include: "ace/theme/eclipse.js"
}], }],
filter: [ copy.filter.moduleDefines, copy.filter.uglifyjs ], filter: [ copy.filter.moduleDefines ],
dest: eclipseTheme dest: eclipseTheme
}); });
copy({ copy({
@ -228,11 +229,12 @@ copy({
root: aceHome + '/lib', root: aceHome + '/lib',
include: "ace/theme/eclipse.css" include: "ace/theme/eclipse.css"
}], }],
filter: [ copy.filter.addDefines, copy.filter.uglifyjs ], filter: [ copy.filter.addDefines ],
dest: eclipseTheme dest: eclipseTheme
}); });
copy({ copy({
source: eclipseTheme, source: eclipseTheme,
filter: [ copy.filter.uglifyjs ],
dest: 'build/src/theme-eclipse.js' dest: 'build/src/theme-eclipse.js'
}); });
@ -258,7 +260,7 @@ copy({
copy.source.commonjs({ copy.source.commonjs({
project: project, project: project,
require: [ 'ace/keyboard/keybinding/' + keybinding ] require: [ 'ace/keyboard/keybinding/' + keybinding ]
}), })
], ],
filter: [ copy.filter.moduleDefines, copy.filter.uglifyjs ], filter: [ copy.filter.moduleDefines, copy.filter.uglifyjs ],
dest: "build/src/keybinding-" + keybinding + ".js" dest: "build/src/keybinding-" + keybinding + ".js"
@ -275,6 +277,10 @@ copy({
source: aceHome + "/Readme.md", source: aceHome + "/Readme.md",
dest: 'build/Readme.md' dest: 'build/Readme.md'
}); });
copy({
source: aceHome + "/ChangeLog.txt",
dest: 'build/ChangeLog.txt'
});
// copy complex demo // copy complex demo
//copy({ //copy({

19
build/ChangeLog.md Normal file
View file

@ -0,0 +1,19 @@
2011.02.xx, Version 0.1.4
* Fix packaged version of the Eclipse mode
* Loading of workers is more robust
* Fix "click selection"
2011.02.04, Version 0.1.4
* Add C/C++ mode contributed by Gastón Kleiman
* Fix word wrap bug
* Fix exception in key input
2011.02.04, Version 0.1.3
* Let the packaged version play nice with requireJS
* Add Ruby mode contributed by Shlomo Zalman Heigh
* Add Java mode contributed by Tom Tasche
* Fix annotation bug
* Changing a document added a new empty line at the end

19
build/ChangeLog.txt Normal file
View file

@ -0,0 +1,19 @@
2011.02.xx, Version 0.1.4
* Fix packaged version of the Eclipse mode
* Loading of workers is more robust
* Fix "click selection"
2011.02.04, Version 0.1.4
* Add C/C++ mode contributed by Gastón Kleiman
* Fix word wrap bug
* Fix exception in key input
2011.02.04, Version 0.1.3
* Let the packaged version play nice with requireJS
* Add Ruby mode contributed by Shlomo Zalman Heigh
* Add Java mode contributed by Tom Tasche
* Fix annotation bug
* Changing a document added a new empty line at the end

View file

@ -22,7 +22,8 @@
<body> <body>
<pre id="editor">function foo(items) { <pre id="editor">function foo(items) {
for (var i = 0; i &lt; items.length; i++) { var i;
for (i = 0; i &lt; items.length; i++) {
alert("Ace Rocks " + items[i]); alert("Ace Rocks " + items[i]);
} }
}</pre> }</pre>

View file

@ -5777,7 +5777,7 @@ var MouseHandler = function(editor) {
if (self.$clickSelection) { if (self.$clickSelection) {
if (self.$clickSelection.contains(cursor.row, cursor.column)) { if (self.$clickSelection.contains(cursor.row, cursor.column)) {
self.selection.setSelectionRange(self.$clickSelection); editor.selection.setSelectionRange(self.$clickSelection);
} else { } else {
if (self.$clickSelection.compare(cursor.row, cursor.column) == -1) { if (self.$clickSelection.compare(cursor.row, cursor.column) == -1) {
var anchor = self.$clickSelection.end; var anchor = self.$clickSelection.end;

File diff suppressed because one or more lines are too long

1
build/src/mode-c_cpp.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1 +1 @@
define("ace/theme/eclipse",function(a,b,c){var d=a("pilot/dom"),e=a("text!ace/theme/eclipse.css");d.importCssString(e),b.cssClass="ace-eclipse"})define("text!ace/theme/eclipse.css",".ace-eclipse .ace_editor { border: 2px solid rgb(159, 159, 159);}.ace-eclipse .ace_editor.ace_focus { border: 2px solid #327fbd;}.ace-eclipse .ace_gutter { width: 40px; background: rgb(227, 227, 227); border-right: 1px solid rgb(159, 159, 159);\t color: rgb(136, 136, 136);}.ace-eclipse .ace_gutter-layer { right: 10px; text-align: right;}.ace-eclipse .ace_text-layer { cursor: text;}.ace-eclipse .ace_cursor { border-left: 1px solid black;}.ace-eclipse .ace_line .ace_keyword, .ace-eclipse .ace_line .ace_variable { color: rgb(127, 0, 85);}.ace-eclipse .ace_line .ace_constant.ace_buildin { color: rgb(88, 72, 246);}.ace-eclipse .ace_line .ace_constant.ace_library { color: rgb(6, 150, 14);}.ace-eclipse .ace_line .ace_function { color: rgb(60, 76, 114);}.ace-eclipse .ace_line .ace_string { color: rgb(42, 0, 255);}.ace-eclipse .ace_line .ace_comment { color: rgb(63, 127, 95);}.ace-eclipse .ace_line .ace_comment.ace_doc { color: rgb(63, 95, 191);}.ace-eclipse .ace_line .ace_comment.ace_doc.ace_tag { color: rgb(127, 159, 191);}.ace-eclipse .ace_line .ace_constant.ace_numeric {}.ace-eclipse .ace_line .ace_tag {\tcolor: rgb(63, 127, 127);}.ace-eclipse .ace_line .ace_xml_pe { color: rgb(104, 104, 91);}.ace-eclipse .ace_marker-layer .ace_selection { background: rgb(181, 213, 255);}.ace-eclipse .ace_marker-layer .ace_bracket { margin: -1px 0 0 -1px; border: 1px solid rgb(192, 192, 192);}.ace-eclipse .ace_marker-layer .ace_active_line { background: rgb(232, 242, 254);}") define("ace/theme/eclipse",function(a,b,c){var d=a("pilot/dom"),e=a("text!ace/theme/eclipse.css");d.importCssString(e),b.cssClass="ace-eclipse"}),define("text!ace/theme/eclipse.css",".ace-eclipse .ace_editor { border: 2px solid rgb(159, 159, 159);}.ace-eclipse .ace_editor.ace_focus { border: 2px solid #327fbd;}.ace-eclipse .ace_gutter { width: 40px; background: rgb(227, 227, 227); border-right: 1px solid rgb(159, 159, 159);\t color: rgb(136, 136, 136);}.ace-eclipse .ace_gutter-layer { right: 10px; text-align: right;}.ace-eclipse .ace_text-layer { cursor: text;}.ace-eclipse .ace_cursor { border-left: 1px solid black;}.ace-eclipse .ace_line .ace_keyword, .ace-eclipse .ace_line .ace_variable { color: rgb(127, 0, 85);}.ace-eclipse .ace_line .ace_constant.ace_buildin { color: rgb(88, 72, 246);}.ace-eclipse .ace_line .ace_constant.ace_library { color: rgb(6, 150, 14);}.ace-eclipse .ace_line .ace_function { color: rgb(60, 76, 114);}.ace-eclipse .ace_line .ace_string { color: rgb(42, 0, 255);}.ace-eclipse .ace_line .ace_comment { color: rgb(63, 127, 95);}.ace-eclipse .ace_line .ace_comment.ace_doc { color: rgb(63, 95, 191);}.ace-eclipse .ace_line .ace_comment.ace_doc.ace_tag { color: rgb(127, 159, 191);}.ace-eclipse .ace_line .ace_constant.ace_numeric {}.ace-eclipse .ace_line .ace_tag {\tcolor: rgb(63, 127, 127);}.ace-eclipse .ace_line .ace_xml_pe { color: rgb(104, 104, 91);}.ace-eclipse .ace_marker-layer .ace_selection { background: rgb(181, 213, 255);}.ace-eclipse .ace_marker-layer .ace_bracket { margin: -1px 0 0 -1px; border: 1px solid rgb(192, 192, 192);}.ace-eclipse .ace_marker-layer .ace_active_line { background: rgb(232, 242, 254);}")

File diff suppressed because one or more lines are too long

View file

@ -22,7 +22,8 @@
<body> <body>
<pre id="editor">function foo(items) { <pre id="editor">function foo(items) {
for (var i = 0; i &lt; items.length; i++) { var i;
for (i = 0; i &lt; items.length; i++) {
alert("Ace Rocks " + items[i]); alert("Ace Rocks " + items[i]);
} }
}</pre> }</pre>

View file

@ -46,6 +46,7 @@ exports.launch = function(env) {
var Renderer = require("ace/virtual_renderer").VirtualRenderer; var Renderer = require("ace/virtual_renderer").VirtualRenderer;
var theme = require("ace/theme/textmate"); var theme = require("ace/theme/textmate");
var EditSession = require("ace/edit_session").EditSession; var EditSession = require("ace/edit_session").EditSession;
var JavaScriptMode = require("ace/mode/javascript").Mode; var JavaScriptMode = require("ace/mode/javascript").Mode;
var CssMode = require("ace/mode/css").Mode; var CssMode = require("ace/mode/css").Mode;
var HtmlMode = require("ace/mode/html").Mode; var HtmlMode = require("ace/mode/html").Mode;
@ -55,6 +56,7 @@ exports.launch = function(env) {
var JavaMode = require("ace/mode/java").Mode; var JavaMode = require("ace/mode/java").Mode;
var RubyMode = require("ace/mode/ruby").Mode; var RubyMode = require("ace/mode/ruby").Mode;
var CCPPMode = require("ace/mode/c_cpp").Mode; var CCPPMode = require("ace/mode/c_cpp").Mode;
var CoffeeMode = require("ace/mode/coffee").Mode;
var TextMode = require("ace/mode/text").Mode; var TextMode = require("ace/mode/text").Mode;
var UndoManager = require("ace/undomanager").UndoManager; var UndoManager = require("ace/undomanager").UndoManager;
@ -117,6 +119,10 @@ exports.launch = function(env) {
docs.c_cpp.setMode(new CCPPMode()); docs.c_cpp.setMode(new CCPPMode());
docs.c_cpp.setUndoManager(new UndoManager()); docs.c_cpp.setUndoManager(new UndoManager());
docs.coffee = new EditSession(document.getElementById("coffeetext").innerHTML);
docs.coffee.setMode(new CoffeeMode());
docs.coffee.setUndoManager(new UndoManager());
var container = document.getElementById("editor"); var container = document.getElementById("editor");
env.editor = new Editor(new Renderer(container, theme)); env.editor = new Editor(new Renderer(container, theme));
@ -130,7 +136,8 @@ exports.launch = function(env) {
php: new PhpMode(), php: new PhpMode(),
java: new JavaMode(), java: new JavaMode(),
ruby: new RubyMode(), ruby: new RubyMode(),
c_cpp: new CCPPMode() c_cpp: new CCPPMode(),
coffee: new CoffeeMode()
}; };
function getMode() { function getMode() {
@ -172,6 +179,9 @@ exports.launch = function(env) {
else if (mode instanceof CCPPMode) { else if (mode instanceof CCPPMode) {
modeEl.value = "c_cpp"; modeEl.value = "c_cpp";
} }
else if (mode instanceof CoffeeMode) {
modeEl.value = "coffee";
}
else { else {
modeEl.value = "text"; modeEl.value = "text";
} }
@ -303,6 +313,8 @@ exports.launch = function(env) {
mode = "ruby"; mode = "ruby";
} else if (/^.*\.(c|cpp|h|hpp|cxx)$/i.test(file.name)) { } else if (/^.*\.(c|cpp|h|hpp|cxx)$/i.test(file.name)) {
mode = "c_cpp"; mode = "c_cpp";
} else if (/^.*\.coffee$/i.test(file.name)) {
mode = "coffee";
} }
env.editor.onTextInput(reader.result); env.editor.onTextInput(reader.result);

View file

@ -22,6 +22,7 @@
<option value="java">Java Document</option> <option value="java">Java Document</option>
<option value="ruby">Ruby Document</option> <option value="ruby">Ruby Document</option>
<option value="c_cpp">C++ Document</option> <option value="c_cpp">C++ Document</option>
<option value="coffee">CoffeeScript Document</option>
<option value="plain">Text Document</option> <option value="plain">Text Document</option>
</select> </select>
</td> </td>
@ -77,7 +78,8 @@
<option value="php">PHP</option> <option value="php">PHP</option>
<option value="java">Java</option> <option value="java">Java</option>
<option value="ruby">Ruby</option> <option value="ruby">Ruby</option>
<option value="c_cpp">C/C++ Document</option> <option value="c_cpp">C/C++</option>
<option value="coffee">CoffeeScript</option>
</select> </select>
</td> </td>
<td align="right"> <td align="right">
@ -238,6 +240,30 @@ int main ()
cout << a; cout << a;
return 0; return 0;
} }
</script>
<script type="text/editor" id="coffeetext">#!/usr/bin/env coffee
try
throw URIError decodeURI(0xC0ffee * 123456.7e-8 / .9)
catch e
console.log 'qstring' + "qqstring" + '''
qdoc
''' + """
qqdoc
"""
do ->
###
herecomment
###
re = /regex/imgy.test ///
heregex # comment
///imgy
this isnt: `just JavaScript`
undefined
var illegal
</script> </script>
<input id="cockpitInput" type="text"/> <input id="cockpitInput" type="text"/>

View file

@ -46,6 +46,11 @@ var Document = function(text) {
if (Array.isArray(text)) { if (Array.isArray(text)) {
this.insertLines(0, text); this.insertLines(0, text);
}
// There has to be one line at least in the document. If you pass an empty
// string to the insert function, nothing will happen. Workaround.
else if (text.length == 0) {
this.$lines = [""];
} else { } else {
this.insert({row: 0, column:0}, text); this.insert({row: 0, column:0}, text);
} }

View file

@ -646,8 +646,18 @@ var EditSession = function(text, mode) {
this.setUseWrapMode = function(useWrapMode) { this.setUseWrapMode = function(useWrapMode) {
if (useWrapMode != this.$useWrapMode) { if (useWrapMode != this.$useWrapMode) {
this.$useWrapMode = useWrapMode; this.$useWrapMode = useWrapMode;
this.$updateWrapData(0, this.getLength() - 1);
this.$modified = true; this.$modified = true;
// If wrapMode is activaed, the wrapData array has to be initialized.
if (useWrapMode) {
var len = this.getLength();
this.$wrapMode = [];
for (i = 0; i < len; i++) {
this.$wrapData.push([]);
}
this.$updateWrapData(0, len - 1);
}
this._dispatchEvent("changeWrapMode"); this._dispatchEvent("changeWrapMode");
} }
}; };
@ -659,7 +669,9 @@ var EditSession = function(text, mode) {
this.setWrapLimit = function(wrapLimit) { this.setWrapLimit = function(wrapLimit) {
if (wrapLimit != this.$wrapLimit) { if (wrapLimit != this.$wrapLimit) {
this.$wrapLimit = wrapLimit; this.$wrapLimit = wrapLimit;
this.$updateWrapData(0, this.getLength() - 1); if (this.$useWrapMode) {
this.$updateWrapData(0, this.getLength() - 1);
}
this._dispatchEvent("changeWrapMode"); this._dispatchEvent("changeWrapMode");
} }
}; };
@ -673,20 +685,23 @@ var EditSession = function(text, mode) {
return; return;
} }
var len;
var action = e.data.action; var action = e.data.action;
var firstRow = e.data.range.start.row, var firstRow = e.data.range.start.row,
lastRow = e.data.range.end.row; lastRow = e.data.range.end.row;
if (action.indexOf("Lines") != -1) { if (action.indexOf("Lines") != -1) {
if (action == "insertLines") { if (action == "insertLines") {
lastRow = firstRow + e.data.lines.length; lastRow = firstRow + (e.data.lines.length);
} else { } else {
firstRow = lastRow - e.data.lines.length; lastRow = firstRow;
} }
len = e.data.lines.length;
} else {
len = lastRow - firstRow;
} }
if (firstRow != lastRow) { if (len != 0) {
var len = lastRow - firstRow;
if (action.indexOf("remove") != -1) { if (action.indexOf("remove") != -1) {
this.$wrapData.splice(firstRow, len); this.$wrapData.splice(firstRow, len);
lastRow = firstRow; lastRow = firstRow;
@ -697,6 +712,10 @@ var EditSession = function(text, mode) {
} }
} }
if (this.$wrapData.length != this.doc.$lines.length) {
console.error("The length of doc.$lines and $wrapData have to be the same!");
}
this.$updateWrapData(firstRow, lastRow); this.$updateWrapData(firstRow, lastRow);
}; };
@ -706,9 +725,6 @@ var EditSession = function(text, mode) {
var wrapData = this.$wrapData; var wrapData = this.$wrapData;
var wrapLimit = this.$wrapLimit; var wrapLimit = this.$wrapLimit;
// Remove lines that are no longer there.
wrapData.splice(lines.length, wrapData.length - lines.length);
for (var row = firstRow; row <= lastRow; row++) { for (var row = firstRow; row <= lastRow; row++) {
wrapData[row] = wrapData[row] =
this.$computeWrapSplits(lines[row], wrapLimit, tabSize); this.$computeWrapSplits(lines[row], wrapLimit, tabSize);
@ -1055,7 +1071,7 @@ var EditSession = function(text, mode) {
if (docRow > wrapData.length - 1) { if (docRow > wrapData.length - 1) {
return [ return [
this.getScreenLength(), this.getScreenLength(),
wrapData[wrapData.length - 1].length - 1 wrapData.length == 0 ? 0 : (wrapData[wrapData.length - 1].length - 1)
]; ];
} }

88
lib/ace/mode/coffee.js Normal file
View file

@ -0,0 +1,88 @@
/* ***** 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 B.V.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Satoshi Murakami <murky.satyr AT gmail DOT 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) {
var Tokenizer = require("ace/tokenizer").Tokenizer
, Rules = require("ace/mode/coffee_highlight_rules").CoffeeHighlightRules
, Outdent = require("ace/mode/matching_brace_outdent").MatchingBraceOutdent
, Range = require("ace/range").Range
;
require("pilot/oop").inherits(CoffeeMode, require("ace/mode/text").Mode);
function CoffeeMode() {
this.$tokenizer = new Tokenizer(new Rules().getRules());
this.$outdent = new Outdent();
}
var proto = CoffeeMode.prototype
, indenter = /(?:[({[=:]|[-=]>|\b(?:else|switch|try|catch(?:\s*[$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)?|finally))\s*$/
, commentLine = /^(\s*)#/
, hereComment = /^\s*###(?!#)/
, indentation = /^\s*/
;
proto.getNextLineIndent = function(state, line, tab){
var indent = this.$getIndent(line)
, tokens = this.$tokenizer.getLineTokens(line, state).tokens
;
if (!(tokens.length && tokens[tokens.length - 1].type === 'comment') &&
state === 'start' && indenter.test(line))
indent += tab;
return indent;
};
proto.toggleCommentLines = function(state, doc, startRow, endRow){
var out, range = new Range(0, 0, 0, 0);
for (var i = startRow; i <= endRow; ++i) {
var line = doc.getLine(i);
if (hereComment.test(line)) continue;
line = (out = commentLine.test(line))
? line.replace(commentLine, '$1')
: line.replace(indentation, '$&#');
range.end.row = range.start.row = i;
range.end.column = line.length + 1;
doc.replace(range, line);
}
return 1 - out * 2;
};
proto.checkOutdent = function(state, line, input) {
return this.$outdent.checkOutdent(line, input);
};
proto.autoOutdent = function(state, doc, row) {
return this.$outdent.autoOutdent(doc, row);
};
exports.Mode = CoffeeMode;
});

View file

@ -0,0 +1,182 @@
/* ***** 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 B.V.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Satoshi Murakami <murky.satyr AT gmail DOT 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) {
require("pilot/oop").inherits(
CoffeeHighlightRules,
require("ace/mode/text_highlight_rules").TextHighlightRules);
function CoffeeHighlightRules() {
var identifier = "[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*"
, keywordend = "(?![$\\w]|\\s*:)"
, stringfill = {token: "string", regex: ".+"}
;
this.$rules =
{ start:
[ { token: "identifier"
, regex: "(?:@|(?:\\.|::)\\s*)" + identifier
}
, { token: "keyword"
, regex: "(?:t(?:h(?:is|row|en)|ry|ypeof)|s(?:uper|witch)|return|b(?:reak|y)|c(?:ontinue|atch|lass)|i(?:n(?:stanceof)?|s(?:nt)?|f)|e(?:lse|xtends)|f(?:or (?:own)?|inally|unction)|wh(?:ile|en)|n(?:ew|ot?)|d(?:e(?:lete|bugger)|o)|loop|o(?:ff?|[rn])|un(?:less|til)|and|yes)" + keywordend
}
, { token: "constant.language"
, regex: "(?:true|false|null|undefined)" + keywordend
}
, { token: "invalid.illegal"
, regex: "(?:c(?:ase|onst)|default|function|v(?:ar|oid)|with|e(?:num|xport)|i(?:mplements|nterface)|let|p(?:ackage|r(?:ivate|otected)|ublic)|static|yield|__(?:hasProp|extends|slice|bind|indexOf))" + keywordend
}
, { token: "language.support.class"
, regex: "(?:Array|Boolean|Date|Function|Number|Object|R(?:e(?:gExp|ferenceError)|angeError)|S(?:tring|yntaxError)|E(?:rror|valError)|TypeError|URIError)" + keywordend
}
, { token: "language.support.function"
, regex: "(?:Math|JSON|is(?:NaN|Finite)|parse(?:Int|Float)|encodeURI(?:Component)?|decodeURI(?:Component)?)" + keywordend
}
, { token: "identifier"
, regex: identifier
}
, { token: "constant.numeric"
, regex: "(?:0x[\\da-fA-F]+|(?:\\d+(?:\\.\\d+)?|\\.\\d+)(?:[eE][+-]?\\d+)?)"
}
, { token: "string"
, regex: "'''"
, next : "qdoc"
}
, { token: "string"
, regex: '"""'
, next : "qqdoc"
}
, { token: "string"
, regex: "'"
, next : "qstring"
}
, { token: "string"
, regex: '"'
, next : "qqstring"
}
, { token: "string"
, regex: "`"
, next : "js"
}
, { token: "string.regex"
, regex: "///"
, next : "heregex"
}
, { token: "string.regex"
, regex: "/(?!\\s)[^[/\\n\\\\]*(?: (?:\\\\.|\\[[^\\]\\n\\\\]*(?:\\\\.[^\\]\\n\\\\]*)*\\])[^[/\\n\\\\]*)*/[imgy]{0,4}(?!\\w)"
}
, { token: "comment"
, regex: "###(?!#)"
, next : "comment"
}
, { token: "comment"
, regex: "#.*"
}
, { token: "lparen"
, regex: "[({[]"
}
, { token: "rparen"
, regex: "[\\]})]"
}
, { token: "keyword.operator"
, regex: "\\S+"
}
, { token: "text"
, regex: "\\s+"
}
]
, qdoc:
[ { token: "string"
, regex: ".*?'''"
, next : "start"
}
, stringfill
]
, qqdoc:
[ { token: "string"
, regex: '.*?"""'
, next : "start"
}
, stringfill
]
, qstring:
[ { token: "string"
, regex: "[^\\\\']*(?:\\\\.[^\\\\']*)*'"
, next : "start"
}
, stringfill
]
, qqstring:
[ { token: "string"
, regex: '[^\\\\"]*(?:\\\\.[^\\\\"]*)*"'
, next : "start"
}
, stringfill
]
, js:
[ { token: "string"
, regex: "[^\\\\`]*(?:\\\\.[^\\\\`]*)*`"
, next : "start"
}
, stringfill
]
, heregex:
[ { token: "string.regex"
, regex: '.*?///[imgy]{0,4}'
, next : "start"
}
, { token: "comment.regex"
, regex: "\\s+(?:#.*)?"
}
, { token: "string.regex"
, regex: "\\S+"
}
]
, comment:
[ { token: "comment"
, regex: '.*?###'
, next : "start"
}
, { token: "comment"
, regex: ".+"
}
]
};
}
exports.CoffeeHighlightRules = CoffeeHighlightRules;
});

View file

@ -124,7 +124,7 @@ oop.inherits(Mode, TextMode);
this.createWorker = function(session) { this.createWorker = function(session) {
var doc = session.getDocument(); var doc = session.getDocument();
var worker = new WorkerClient("../..", ["ace", "pilot"], "worker-javascript.js", "ace/mode/javascript_worker", "JavaScriptWorker"); var worker = new WorkerClient(["ace", "pilot"], "worker-javascript.js", "ace/mode/javascript_worker", "JavaScriptWorker");
worker.call("setValue", [doc.getValue()]); worker.call("setValue", [doc.getValue()]);
doc.on("change", function(e) { doc.on("change", function(e) {

View file

@ -44,7 +44,6 @@ var Tokenizer = require("ace/tokenizer").Tokenizer;
var RubyHighlightRules = require("ace/mode/ruby_highlight_rules").RubyHighlightRules; var RubyHighlightRules = require("ace/mode/ruby_highlight_rules").RubyHighlightRules;
var MatchingBraceOutdent = require("ace/mode/matching_brace_outdent").MatchingBraceOutdent; var MatchingBraceOutdent = require("ace/mode/matching_brace_outdent").MatchingBraceOutdent;
var Range = require("ace/range").Range; var Range = require("ace/range").Range;
var WorkerClient = require("ace/worker/worker_client").WorkerClient;
var Mode = function() { var Mode = function() {
this.$tokenizer = new Tokenizer(new RubyHighlightRules().getRules()); this.$tokenizer = new Tokenizer(new RubyHighlightRules().getRules());

View file

@ -292,6 +292,11 @@ var Test = {
doc.setValue(doc.getValue()); doc.setValue(doc.getValue());
assert.equal("1\n2", doc.getValue()); assert.equal("1\n2", doc.getValue());
},
"test: empty document has to contain one line": function() {
var doc = new Document("");
assert.equal(doc.$lines.length, 1);
} }
}; };

View file

@ -38,6 +38,7 @@
define(function(require, exports, module) { define(function(require, exports, module) {
var EditSession = require("ace/edit_session").EditSession, var EditSession = require("ace/edit_session").EditSession,
Editor = require("../editor").Editor,
UndoManager = require("ace/undomanager").UndoManager, UndoManager = require("ace/undomanager").UndoManager,
MockRenderer = require("./mockrenderer"), MockRenderer = require("./mockrenderer"),
Range = require("ace/range").Range, Range = require("ace/range").Range,
@ -357,6 +358,32 @@ var Test = {
assert.equal(session.$getDisplayTokens("\t").length, 4); assert.equal(session.$getDisplayTokens("\t").length, 4);
assert.equal(session.$getDisplayTokens("abc").length, 3); assert.equal(session.$getDisplayTokens("abc").length, 3);
assert.equal(session.$getDisplayTokens("abc\t").length, 7); assert.equal(session.$getDisplayTokens("abc\t").length, 7);
},
"test issue 83": function() {
var session = new EditSession("");
var editor = new Editor(new MockRenderer(), session);
var document = session.getDocument();
session.setUseWrapMode(true);
document.insertLines(0, ["a", "b"]);
document.insertLines(2, ["c", "d"]);
document.removeLines(1, 2);
},
"test wrapMode init has to create wrapData array": function() {
var session = new EditSession("foo bar\nfoo bar");
var editor = new Editor(new MockRenderer(), session);
var document = session.getDocument();
session.setUseWrapMode(true);
session.setWrapLimit(3);
// Test if wrapData is there and was computed.
assert.equal(session.$wrapData.length, 2);
assert.equal(session.$wrapData[0].length, 1);
assert.equal(session.$wrapData[1].length, 1);
} }
}; };

View file

@ -19,7 +19,7 @@ var require = function(id) {
var chunks = id.split("/"); var chunks = id.split("/");
chunks[0] = require.tlns[chunks[0]] || chunks[0]; chunks[0] = require.tlns[chunks[0]] || chunks[0];
path = /*require.baseUrl + "/" +*/ chunks.join("/") + ".js"; path = chunks.join("/") + ".js";
require.id = id; require.id = id;
// console.log("require " + path + " " + id) // console.log("require " + path + " " + id)
@ -29,7 +29,6 @@ var require = function(id) {
require.modules = {}; require.modules = {};
require.tlns = {}; require.tlns = {};
require.baseUrl = "";
var define = function(id, factory) { var define = function(id, factory) {
if (!factory) { if (!factory) {
@ -52,8 +51,7 @@ var define = function(id, factory) {
}; };
}; };
function initBaseUrls(baseUrl, topLevelNamespaces) { function initBaseUrls(topLevelNamespaces) {
require.baseUrl = baseUrl;
require.tlns = topLevelNamespaces; require.tlns = topLevelNamespaces;
} }
@ -98,7 +96,7 @@ onmessage = function(e) {
main[msg.command].apply(main, msg.args); main[msg.command].apply(main, msg.args);
} }
else if (msg.init) { else if (msg.init) {
initBaseUrls(msg.base, msg.tlns); initBaseUrls(msg.tlns);
require("pilot/fixoldbrowsers"); require("pilot/fixoldbrowsers");
sender = initSender(); sender = initSender();
var clazz = require(msg.module)[msg.classname]; var clazz = require(msg.module)[msg.classname];

View file

@ -11,12 +11,13 @@ define(function(require, exports, module) {
var oop = require("pilot/oop"); var oop = require("pilot/oop");
var EventEmitter = require("pilot/event_emitter").EventEmitter; var EventEmitter = require("pilot/event_emitter").EventEmitter;
var WorkerClient = function(baseUrl, topLevelNamespaces, packagedJs, module, classname) { var WorkerClient = function(topLevelNamespaces, packagedJs, module, classname) {
this.callbacks = []; this.callbacks = [];
if (require.packaged) { if (require.packaged) {
var worker = this.$worker = new Worker(packagedJs); var base = this.$guessBasePath();
var worker = this.$worker = new Worker(base + packagedJs);
} }
else { else {
var workerUrl = require.nameToUrl("ace/worker/worker", null, "_"); var workerUrl = require.nameToUrl("ace/worker/worker", null, "_");
@ -25,14 +26,13 @@ var WorkerClient = function(baseUrl, topLevelNamespaces, packagedJs, module, cla
var tlns = {}; var tlns = {};
for (var i=0; i<topLevelNamespaces.length; i++) { for (var i=0; i<topLevelNamespaces.length; i++) {
var ns = topLevelNamespaces[i]; var ns = topLevelNamespaces[i];
tlns[ns] = require.nameToUrl(ns, null, "_").replace(/.js$/, "").replace(require.config.baseUrl, ""); tlns[ns] = require.nameToUrl(ns, null, "_").replace(/.js$/, "");
} }
} }
this.$worker.postMessage({ this.$worker.postMessage({
init : true, init : true,
tlns: tlns, tlns: tlns,
base: baseUrl,
module: module, module: module,
classname: classname classname: classname
}); });
@ -71,6 +71,16 @@ var WorkerClient = function(baseUrl, topLevelNamespaces, packagedJs, module, cla
oop.implement(this, EventEmitter); oop.implement(this, EventEmitter);
this.$guessBasePath = function() {
var scripts = document.getElementsByTagName("script");
for (var i=0; i<scripts.length; i++) {
var m = scripts[i].src.match(/^(.*\/)ace\.js$/);
if (m)
return m[1];
}
return "";
};
this.terminate = function() { this.terminate = function() {
this._dispatchEvent("terminate", {}); this._dispatchEvent("terminate", {});
this.$worker.terminate(); this.$worker.terminate();