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

This commit is contained in:
baboso 2014-07-08 15:22:40 -04:00
commit 5ebcf9298b
56 changed files with 2476 additions and 1092 deletions

View file

@ -1,3 +1,13 @@
2014.07.01 Version 1.1.4
* New Features
- Highlight matching tags (Adam Jimenez)
- Improved jump to matching command (Adam Jimenez)
* new language modes
- AppleScript (Yaogang Lian)
- Vala
2014.03.08 Version 1.1.3 2014.03.08 Version 1.1.3
* New Features * New Features

View file

@ -13,7 +13,6 @@ pre_build:
build: pre_build build: pre_build
./Makefile.dryice.js normal ./Makefile.dryice.js normal
./Makefile.dryice.js demo ./Makefile.dryice.js demo
./Makefile.dryice.js bm
# Minimal build: call Makefile.dryice.js only if our sources changed # Minimal build: call Makefile.dryice.js only if our sources changed
basic: build/src/ace.js basic: build/src/ace.js

File diff suppressed because it is too large Load diff

2
build

@ -1 +1 @@
Subproject commit fc9d2cae9fe8e6e95e74c86a31d21caadd8f9f39 Subproject commit b85b38c1e33e161826f4dd7774ef73aac55e0d14

View file

@ -20,7 +20,7 @@ function foo() {
var bar = true; var bar = true;
}</textarea><br> }</textarea><br>
SourceUrl: <br> SourceUrl: <br>
<input id="srcURL" style="width:300px" value="http://ajaxorg.github.com/ace-builds/textarea/src/"></input><br> <input id="srcURL" style="width:300px" value="http://ajaxorg.github.com/ace-builds/src-noconflict"></input><br>
<button id="buBuild">Build Link</button> <br> <a href="#"></a> <button id="buBuild">Build Link</button> <br> <a href="#"></a>
<a href="https://github.com/ajaxorg/ace/"> <a href="https://github.com/ajaxorg/ace/">
<div class="fork_on_github" ></div> <div class="fork_on_github" ></div>
@ -49,63 +49,60 @@ function foo() {
<script> <script>
function inject(callback) { function inject(options, callback) {
var baseUrl = "src/"; var baseUrl = options.baseUrl || "../../src-noconflict";
var load = window.__ace_loader__ = function(path, module, callback) { var load = function(path, callback) {
var head = document.getElementsByTagName('head')[0]; var head = document.getElementsByTagName('head')[0];
var s = document.createElement('script'); var s = document.createElement('script');
s.src = baseUrl + path; s.src = baseUrl + "/" + path;
head.appendChild(s); head.appendChild(s);
s.onload = function() { s.onload = s.onreadystatechange = function(_, isAbort) {
window.__ace_shadowed__.require([module], callback); if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") {
s = s.onload = s.onreadystatechange = null;
if (!isAbort)
callback();
}
}; };
}; };
load('ace-bookmarklet.js', "ace/ext/textarea", function() { load("ace.js", function() {
var ace = window.__ace_shadowed__; ace.config.loadModule("ace/ext/textarea", function() {
var event = ace.require("ace/lib/event");
ace.options.mode = "javascript";
var Event = ace.require("ace/lib/event");
var areas = document.getElementsByTagName("textarea"); var areas = document.getElementsByTagName("textarea");
for (var i = 0; i < areas.length; i++) { for (var i = 0; i < areas.length; i++) {
Event.addListener(areas[i], "click", function(e) { event.addListener(areas[i], "click", function(e) {
if (e.detail == 3) { if (e.detail == 3) {
ace.transformTextarea(e.target, load); ace.transformTextarea(e.target, options.ace);
} }
}); });
} }
callback && callback(); callback && callback();
}); });
});
} }
// Call the inject function to load the ace files. // Call the inject function to load the ace files.
var textAce; var textAce;
inject(function () { inject({}, function () {
// Transform the textarea on the page into an ace editor. // Transform the textarea on the page into an ace editor.
var ace = window.__ace_shadowed__;
var t = document.querySelector("textarea"); var t = document.querySelector("textarea");
textAce = ace.transformTextarea(t, window.__ace_loader__); textAce = ace.require("ace/ext/textarea").transformTextarea(t);
setTimeout(function(){textAce.setDisplaySettings(true)}); setTimeout(function(){textAce.setDisplaySettings(true)});
}); });
document.getElementById("buBuild").onclick = function() { document.getElementById("buBuild").onclick = function() {
var injectSrc = inject.toString().split("\n").join(""); var injectSrc = inject.toString().split("\n").join("");
injectSrc = injectSrc.replace('baseUrl = "src/"', 'baseUrl="' + document.getElementById("srcURL").value + '"');
var aceOptions = textAce.getOptions();
var opt = [];
for (var option in aceOptions) {
opt.push(option + ":'" + aceOptions[option] + "'");
}
injectSrc = injectSrc.replace('ace.options.mode = "javascript"', 'ace.options = { ' + opt.join(",") + ' }');
injectSrc = injectSrc.replace(/\s+/g, " "); injectSrc = injectSrc.replace(/\s+/g, " ");
var options = textAce.getOptions();
options.baseUrl = document.getElementById("srcURL").value;
var a = document.querySelector("a"); var a = document.querySelector("a");
a.href = "javascript:(" + injectSrc + ")()"; a.href = "javascript:(" + injectSrc + ")(" + JSON.stringify(options) + ")";
a.innerHTML = "Ace Bookmarklet Link"; a.innerHTML = "Ace Bookmarklet Link";
} }

View file

@ -26,8 +26,12 @@
<div class="scrollmargin"></div> <div class="scrollmargin"></div>
<pre id="editor"></pre> <pre id="editor"></pre>
<script src="../build/src/ace.js"></script> <script src="kitchen-sink/require.js"></script>
<script> <script>
// setup paths
require.config({paths: { "ace" : "../lib/ace"}});
// load ace and extensions
require(["ace/ace"], function(ace) {
var editor1 = ace.edit("editor1"); var editor1 = ace.edit("editor1");
editor1.setTheme("ace/theme/tomorrow_night_eighties"); editor1.setTheme("ace/theme/tomorrow_night_eighties");
@ -47,7 +51,7 @@ editor.setTheme("ace/theme/tomorrow");
editor.session.setMode("ace/mode/html"); editor.session.setMode("ace/mode/html");
editor.setAutoScrollEditorIntoView(true); editor.setAutoScrollEditorIntoView(true);
editor.setOption("maxLines", 100); editor.setOption("maxLines", 100);
});
</script> </script>
<script src="./show_own_source.js"></script> <script src="./show_own_source.js"></script>

View file

@ -592,7 +592,7 @@ env.editSnippets = function() {
require("ace/ext/language_tools"); require("ace/ext/language_tools");
env.editor.setOptions({ env.editor.setOptions({
enableBasicAutocompletion: true, enableBasicAutocompletion: true,
enableLiveAutocompletion: true, enableLiveAutocompletion: false,
enableSnippets: true enableSnippets: true
}); });

11
demo/kitchen-sink/docs/.gitignore vendored Normal file
View file

@ -0,0 +1,11 @@
# A sample .gitignore file.
.buildlog
.DS_Store
.svn
# Negated patterns:
!foo.bar
# Also ignore user settings...
/.settings

View file

@ -0,0 +1,21 @@
using Gtk;
int main (string[] args) {
Gtk.init (ref args);
var foo = new MyFoo<string[](), MyBar<string, int>>();
var window = new Window();
window.title = "Hello, World!";
window.border_width = 10;
window.window_position = WindowPosition.CENTER;
window.set_default_size(350, 70);
window.destroy.connect(Gtk.main_quit);
var label = new Label("Hello, World!");
window.add(label);
window.show_all();
Gtk.main();
return 0;
}

View file

@ -29,14 +29,20 @@
}</pre> }</pre>
<script src="../demo/kitchen-sink/require.js"></script> <script src="../demo/kitchen-sink/require.js"></script>
<script src="../build/src/ace.js" charset="utf-8"></script>
<script> <script>
require.config({paths: {ace: "../build/src"}})
define('testace', ['ace/ace'],
function(ace, langtools) {
console.log("This is the testace module");
var editor = ace.edit("editor"); var editor = ace.edit("editor");
editor.setTheme("ace/theme/twilight"); editor.setTheme("ace/theme/twilight");
editor.session.setMode("ace/mode/javascript"); editor.session.setMode("ace/mode/javascript");
require(["ace/requirejs/text!src/ace"], function(e){ require(["ace/requirejs/text!src/ace"], function(e){
editor.setValue(e); editor.setValue(e);
}) })
}
);
require(['testace'])
</script> </script>
</body> </body>

View file

@ -11,16 +11,10 @@
commit %commit% commit %commit%
--> -->
<!--DEVEL-->
<link rel="stylesheet" href="demo/kitchen-sink/styles.css" type="text/css" media="screen" charset="utf-8"> <link rel="stylesheet" href="demo/kitchen-sink/styles.css" type="text/css" media="screen" charset="utf-8">
<script async="true" src="https://use.edgefonts.net/source-code-pro.js"></script> <script async="true" src="https://use.edgefonts.net/source-code-pro.js"></script>
<!--DEVEL-->
<link href="./doc/site/images/favicon.ico" rel="icon" type="image/x-icon"> <link href="./doc/site/images/favicon.ico" rel="icon" type="image/x-icon">
<!--PACKAGE
<link rel="stylesheet" href="kitchen-sink/styles.css" type="text/css" media="screen" charset="utf-8">
<script async="true" src="https://use.edgefonts.net/source-code-pro.js"></script>
PACKAGE-->
</head> </head>
<body> <body>
<div id="optionsPanel" style="position:absolute;height:100%;width:260px"> <div id="optionsPanel" style="position:absolute;height:100%;width:260px">
@ -287,7 +281,7 @@
<script src="src/ace.js" data-ace-base="src" type="text/javascript" charset="utf-8"></script> <script src="src/ace.js" data-ace-base="src" type="text/javascript" charset="utf-8"></script>
<script src="src/keybinding-vim.js"></script> <script src="src/keybinding-vim.js"></script>
<script src="src/keybinding-emacs.js"></script> <script src="src/keybinding-emacs.js"></script>
<script src="kitchen-sink/demo.js"></script> <script src="demo/kitchen-sink/demo.js"></script>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
require("kitchen-sink/demo"); require("kitchen-sink/demo");
</script> </script>

View file

@ -101,12 +101,12 @@ var Autocomplete = function() {
this.changeTimer.cancel(); this.changeTimer.cancel();
if (this.popup && this.popup.isOpen) { if (this.popup && this.popup.isOpen) {
this.gatherCompletionsId = this.gatherCompletionsId + 1; this.gatherCompletionsId += 1;
this.popup.hide();
} }
if (this.popup) if (this.base)
this.popup.hide(); this.base.detach();
this.activated = false; this.activated = false;
this.completions = this.base = null; this.completions = this.base = null;
}; };
@ -205,8 +205,7 @@ var Autocomplete = function() {
var line = session.getLine(pos.row); var line = session.getLine(pos.row);
var prefix = util.retrievePrecedingIdentifier(line, pos.column); var prefix = util.retrievePrecedingIdentifier(line, pos.column);
this.base = editor.getCursorPosition(); this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length);
this.base.column -= prefix.length;
var matches = []; var matches = [];
var total = editor.completers.length; var total = editor.completers.length;
@ -306,13 +305,7 @@ var Autocomplete = function() {
}; };
this.cancelContextMenu = function() { this.cancelContextMenu = function() {
var stop = function(e) { this.editor.$mouseHandler.cancelContextMenu();
this.editor.off("nativecontextmenu", stop);
if (e && e.domEvent)
event.stopEvent(e.domEvent);
}.bind(this);
setTimeout(stop, 10);
this.editor.on("nativecontextmenu", stop);
}; };
}).call(Autocomplete.prototype); }).call(Autocomplete.prototype);

View file

@ -67,6 +67,7 @@ var AcePopup = function(parentNode) {
popup.renderer.setStyle("ace_autocomplete"); popup.renderer.setStyle("ace_autocomplete");
popup.setOption("displayIndentGuides", false); popup.setOption("displayIndentGuides", false);
popup.setOption("dragDelay", 150);
var noop = function(){}; var noop = function(){};
@ -178,7 +179,7 @@ var AcePopup = function(parentNode) {
if (typeof data == "string") if (typeof data == "string")
data = {value: data}; data = {value: data};
if (!data.caption) if (!data.caption)
data.caption = data.value; data.caption = data.value || data.name;
var last = -1; var last = -1;
var flag, c; var flag, c;

View file

@ -68,7 +68,7 @@ define(function(require, exports, module) {
var wordList = Object.keys(wordScore); var wordList = Object.keys(wordScore);
callback(null, wordList.map(function(word) { callback(null, wordList.map(function(word) {
return { return {
name: word, caption: word,
value: word, value: word,
score: wordScore[word], score: wordScore[word],
meta: "local" meta: "local"

View file

@ -392,16 +392,22 @@ exports.commands = [{
readOnly: true readOnly: true
}, { }, {
name: "jumptomatching", name: "jumptomatching",
bindKey: bindKey("Ctrl-P", "Ctrl-Shift-P"), bindKey: bindKey("Ctrl-P", "Ctrl-P"),
exec: function(editor) { editor.jumpToMatching(); }, exec: function(editor) { editor.jumpToMatching(); },
multiSelectAction: "forEach", multiSelectAction: "forEach",
readOnly: true readOnly: true
}, { }, {
name: "selecttomatching", name: "selecttomatching",
bindKey: bindKey("Ctrl-Shift-P", null), bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
exec: function(editor) { editor.jumpToMatching(true); }, exec: function(editor) { editor.jumpToMatching(true); },
multiSelectAction: "forEach", multiSelectAction: "forEach",
readOnly: true readOnly: true
}, {
name: "passKeysToBrowser",
bindKey: bindKey("null", "null"),
exec: function() {},
passEvent: true,
readOnly: true
}, },
// commands disabled in readOnly mode // commands disabled in readOnly mode

View file

@ -153,7 +153,11 @@ function init(packaged) {
var scriptOptions = {}; var scriptOptions = {};
var scriptUrl = ""; var scriptUrl = "";
var scripts = document.getElementsByTagName("script"); // Use currentScript.ownerDocument in case this file was loaded from imported document. (HTML Imports)
var currentScript = (document.currentScript || document._currentScript ); // native or polyfill
var currentDocument = currentScript && currentScript.ownerDocument || document;
var scripts = currentDocument.getElementsByTagName("script");
for (var i=0; i<scripts.length; i++) { for (var i=0; i<scripts.length; i++) {
var script = scripts[i]; var script = scripts[i];

View file

@ -485,15 +485,15 @@ function Folding() {
}; };
this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) { this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
if (startRow == null) { if (startRow == null)
startRow = foldLine.start.row; startRow = foldLine.start.row;
if (startColumn == null)
startColumn = 0; startColumn = 0;
} if (endRow == null)
if (endRow == null) {
endRow = foldLine.end.row; endRow = foldLine.end.row;
if (endColumn == null)
endColumn = this.getLine(endRow).length; endColumn = this.getLine(endRow).length;
}
// Build the textline using the FoldLine walker. // Build the textline using the FoldLine walker.
var doc = this.doc; var doc = this.doc;

View file

@ -48,6 +48,7 @@ var EventEmitter = require("./lib/event_emitter").EventEmitter;
var CommandManager = require("./commands/command_manager").CommandManager; var CommandManager = require("./commands/command_manager").CommandManager;
var defaultCommands = require("./commands/default_commands").commands; var defaultCommands = require("./commands/default_commands").commands;
var config = require("./config"); var config = require("./config");
var TokenIterator = require("./token_iterator").TokenIterator;
/** /**
* The main entry point into the Ace functionality. * The main entry point into the Ace functionality.
@ -210,13 +211,14 @@ var Editor = function(renderer, session) {
} }
}; };
// TODO use property on commands instead of this
this.$mergeableCommands = ["backspace", "del", "insertstring"];
this.$historyTracker = function(e) { this.$historyTracker = function(e) {
if (!this.$mergeUndoDeltas) if (!this.$mergeUndoDeltas)
return; return;
var prev = this.prevOp; var prev = this.prevOp;
var mergeableCommands = ["backspace", "del", "insertstring"]; var mergeableCommands = this.$mergeableCommands;
// previous command was the same // previous command was the same
var shouldMerge = prev.command && (e.command.name == prev.command.name); var shouldMerge = prev.command && (e.command.name == prev.command.name);
if (e.command.name == "insertstring") { if (e.command.name == "insertstring") {
@ -535,6 +537,89 @@ var Editor = function(renderer, session) {
}, 50); }, 50);
}; };
// todo: move to mode.getMatching
this.$highlightTags = function() {
var session = this.session;
if (this.$highlightTagPending) {
return;
}
// perform highlight async to not block the browser during navigation
var self = this;
this.$highlightTagPending = true;
setTimeout(function() {
self.$highlightTagPending = false;
var pos = self.getCursorPosition();
var iterator = new TokenIterator(self.session, pos.row, pos.column);
var token = iterator.getCurrentToken();
if (!token || token.type.indexOf('tag-name') === -1) {
session.removeMarker(session.$tagHighlight);
session.$tagHighlight = null;
return;
}
var tag = token.value;
var depth = 0;
var prevToken = iterator.stepBackward();
if (prevToken.value == '<'){
//find closing tag
do {
prevToken = token;
token = iterator.stepForward();
if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
if (prevToken.value==='<'){
depth++;
} else if (prevToken.value==='</'){
depth--;
}
}
} while (token && depth>=0);
}else{
//find opening tag
do {
token = prevToken;
prevToken = iterator.stepBackward();
if(token && token.value === tag && token.type.indexOf('tag-name') !== -1) {
if (prevToken.value==='<') {
depth++;
} else if( prevToken.value==='</') {
depth--;
}
}
} while (prevToken && depth<=0);
//select tag again
iterator.stepForward();
}
if (!token) {
session.removeMarker(session.$tagHighlight);
session.$tagHighlight = null;
return;
}
var row = iterator.getCurrentTokenRow();
var column = iterator.getCurrentTokenColumn();
var range = new Range(row, column, row, column+token.value.length);
//remove range if different
if (session.$tagHighlight && range.compareRange(session.$backMarkers[session.$tagHighlight].range)!==0) {
session.removeMarker(session.$tagHighlight);
session.$tagHighlight = null;
}
if (range && !session.$tagHighlight)
session.$tagHighlight = session.addMarker(range, "ace_bracket", "text");
}, 50);
};
/** /**
* *
* Brings the current `textInput` into focus. * Brings the current `textInput` into focus.
@ -651,6 +736,7 @@ var Editor = function(renderer, session) {
} }
this.$highlightBrackets(); this.$highlightBrackets();
this.$highlightTags();
this.$updateHighlightActiveLine(); this.$updateHighlightActiveLine();
this._signal("changeSelection"); this._signal("changeSelection");
}; };
@ -1915,25 +2001,158 @@ var Editor = function(renderer, session) {
}; };
/** /**
* Moves the cursor's row and column to the next matching bracket. * Moves the cursor's row and column to the next matching bracket or HTML tag.
* *
**/ **/
this.jumpToMatching = function(select) { this.jumpToMatching = function(select) {
var cursor = this.getCursorPosition(); var cursor = this.getCursorPosition();
var iterator = new TokenIterator(this.session, cursor.row, cursor.column);
var prevToken = iterator.getCurrentToken();
var token = prevToken;
var range = this.session.getBracketRange(cursor); if (!token)
token = iterator.stepForward();
if (!token)
return;
//get next closing tag or bracket
var matchType;
var found = false;
var depth = {};
var i = cursor.column - token.start;
var bracketType;
var brackets = {
")": "(",
"(": "(",
"]": "[",
"[": "[",
"{": "{",
"}": "{"
};
do {
if (token.value.match(/[{}()\[\]]/g)) {
for (; i<token.value.length && !found; i++) {
if (!brackets[token.value[i]]) {
continue;
}
bracketType = brackets[token.value[i]]+'.'+token.type.replace("rparen", "lparen");
if (isNaN(depth[bracketType])) {
depth[bracketType] = 0;
}
switch (token.value[i]) {
case '(':
case '[':
case '{':
depth[bracketType]++;
break;
case ')':
case ']':
case '}':
depth[bracketType]--;
if (depth[bracketType]===-1) {
matchType = 'bracket';
found = true;
}
break;
}
}
} else if (token && token.type.indexOf('tag-name') !== -1) {
if (isNaN(depth[token.value])) {
depth[token.value] = 0;
}
if (prevToken.value === '<') {
depth[token.value]++;
} else if (prevToken.value === '</') {
depth[token.value]--;
}
if (depth[token.value] === -1) {
matchType = 'tag';
found = true;
}
}
if (!found) {
prevToken = token;
token = iterator.stepForward();
i = 0;
}
} while (token && !found);
//no match found
if (!matchType) {
return;
}
var range;
if (matchType==='bracket') {
range = this.session.getBracketRange(cursor);
if (!range) { if (!range) {
range = this.find({ range = new Range(
needle: /[{}()\[\]]/g, iterator.getCurrentTokenRow(),
preventScroll:true, iterator.getCurrentTokenColumn()+i-1,
start: {row: cursor.row, column: cursor.column - 1} iterator.getCurrentTokenRow(),
}); iterator.getCurrentTokenColumn()+i-1
);
if (!range) if (!range)
return; return;
var pos = range.start; var pos = range.start;
if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2) if (pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2)
range = this.session.getBracketRange(pos); range = this.session.getBracketRange(pos);
} }
} else if(matchType==='tag') {
if (token && token.type.indexOf('tag-name') !== -1)
var tag = token.value;
else
return;
var range = new Range(
iterator.getCurrentTokenRow(),
iterator.getCurrentTokenColumn()-2,
iterator.getCurrentTokenRow(),
iterator.getCurrentTokenColumn()-2
);
//find matching tag
if (range.compare(cursor.row, cursor.column) === 0) {
found = false;
do {
token = prevToken;
prevToken = iterator.stepBackward();
if (prevToken) {
if (prevToken.type.indexOf('tag-close') !== -1) {
range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn()+1);
}
if (token.value === tag && token.type.indexOf('tag-name') !== -1) {
if (prevToken.value === '<') {
depth[tag]++;
} else if ( prevToken.value === '</') {
depth[tag]--;
}
if (depth[tag]===0)
found = true;
}
}
} while (prevToken && !found);
}
//we found it
if (token && token.type.indexOf('tag-name')) {
var pos = range.start;
if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
pos = range.end;
}
}
pos = range && range.cursor || pos; pos = range && range.cursor || pos;
if (pos) { if (pos) {

View file

@ -108,8 +108,9 @@ var loadSnippetFile = function(id) {
config.loadModule(snippetFilePath, function(m) { config.loadModule(snippetFilePath, function(m) {
if (m) { if (m) {
snippetManager.files[id] = m; snippetManager.files[id] = m;
if (!m.snippets && m.snippetText)
m.snippets = snippetManager.parseSnippetFile(m.snippetText); m.snippets = snippetManager.parseSnippetFile(m.snippetText);
snippetManager.register(m.snippets, m.scope); snippetManager.register(m.snippets || [], m.scope);
if (m.includeScopes) { if (m.includeScopes) {
snippetManager.snippetMap[m.scope].includeScopes = m.includeScopes; snippetManager.snippetMap[m.scope].includeScopes = m.includeScopes;
m.includeScopes.forEach(function(x) { m.includeScopes.forEach(function(x) {
@ -120,45 +121,46 @@ var loadSnippetFile = function(id) {
}); });
}; };
function getCompletionPrefix(editor) {
var pos = editor.getCursorPosition();
var line = editor.session.getLine(pos.row);
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
// Try to find custom prefixes on the completers
editor.completers.forEach(function(completer) {
if (completer.identifierRegexps) {
completer.identifierRegexps.forEach(function(identifierRegex) {
if (!prefix && identifierRegex)
prefix = util.retrievePrecedingIdentifier(line, pos.column, identifierRegex);
});
}
});
return prefix;
}
var doLiveAutocomplete = function(e) { var doLiveAutocomplete = function(e) {
var editor = e.editor; var editor = e.editor;
var text = e.args || ""; var text = e.args || "";
var pos = editor.getCursorPosition();
var line = editor.session.getLine(pos.row);
var hasCompleter = editor.completer && editor.completer.activated; var hasCompleter = editor.completer && editor.completer.activated;
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
//Try to find custom prefixes on the completers
completers.forEach(function(completer) {
if (completer.identifierRegexps) {
completer.identifierRegexps.forEach(function(identifierRegex) {
if (!prefix) {
prefix = util.retrievePrecedingIdentifier(line, pos.column, identifierRegex);
}
});
}
});
// We don't want to autocomplete with no prefix // We don't want to autocomplete with no prefix
if (e.command.name === "backspace" && !prefix) { if (e.command.name === "backspace") {
if (hasCompleter) if (hasCompleter && !getCompletionPrefix(editor))
editor.completer.detach(); editor.completer.detach();
} }
else if (e.command.name === "insertstring") { else if (e.command.name === "insertstring") {
var prefix = getCompletionPrefix(editor);
// Only autocomplete if there's a prefix that can be matched // Only autocomplete if there's a prefix that can be matched
if (prefix && !hasCompleter) { if (prefix && !hasCompleter) {
if (!editor.completer) { if (!editor.completer) {
// Create new autocompleter // Create new autocompleter
editor.completer = new Autocomplete(); editor.completer = new Autocomplete();
}
// Disable autoInsert // Disable autoInsert
editor.completer.autoSelect = false; editor.completer.autoSelect = false;
editor.completer.autoInsert = false; editor.completer.autoInsert = false;
}
editor.completer.showPopup(editor); editor.completer.showPopup(editor);
} else if (!prefix && hasCompleter) {
// When the prefix is empty
// close the autocomplete dialog
editor.completer.detach();
} }
} }
}; };
@ -168,6 +170,7 @@ require("../config").defineOptions(Editor.prototype, "editor", {
enableBasicAutocompletion: { enableBasicAutocompletion: {
set: function(val) { set: function(val) {
if (val) { if (val) {
if (!this.completers)
this.completers = Array.isArray(val)? val: completers; this.completers = Array.isArray(val)? val: completers;
this.commands.addCommand(Autocomplete.startCommand); this.commands.addCommand(Autocomplete.startCommand);
} else { } else {
@ -183,6 +186,7 @@ require("../config").defineOptions(Editor.prototype, "editor", {
enableLiveAutocompletion: { enableLiveAutocompletion: {
set: function(val) { set: function(val) {
if (val) { if (val) {
if (!this.completers)
this.completers = Array.isArray(val)? val: completers; this.completers = Array.isArray(val)? val: completers;
// On each change automatically trigger the autocomplete // On each change automatically trigger the autocomplete
this.commands.on('afterExec', doLiveAutocomplete); this.commands.on('afterExec', doLiveAutocomplete);

View file

@ -60,41 +60,47 @@ module.exports.addEditorMenuOptions = function addEditorMenuOptions (editor) {
var modelist = require('../modelist'); var modelist = require('../modelist');
var themelist = require('../themelist'); var themelist = require('../themelist');
editor.menuOptions = { editor.menuOptions = {
"setNewLineMode" : [{ setNewLineMode: [{
"textContent" : "unix", textContent: "unix",
"value" : "unix" value: "unix"
}, { }, {
"textContent" : "windows", textContent: "windows",
"value" : "windows" value: "windows"
}, { }, {
"textContent" : "auto", textContent: "auto",
"value" : "auto" value: "auto"
}], }],
"setTheme" : [], setTheme: [],
"setMode" : [], setMode: [],
"setKeyboardHandler": [{ setKeyboardHandler: [{
"textContent" : "ace", textContent: "ace",
"value" : "" value: ""
}, { }, {
"textContent" : "vim", textContent: "vim",
"value" : "ace/keyboard/vim" value: "ace/keyboard/vim"
}, { }, {
"textContent" : "emacs", textContent: "emacs",
"value" : "ace/keyboard/emacs" value: "ace/keyboard/emacs"
}, {
textContent: "textarea",
value: "ace/keyboard/textarea"
}, {
textContent: "sublime",
value: "ace/keyboard/sublime"
}] }]
}; };
editor.menuOptions.setTheme = themelist.themes.map(function(theme) { editor.menuOptions.setTheme = themelist.themes.map(function(theme) {
return { return {
'textContent' : theme.caption, textContent: theme.caption,
'value' : theme.theme value: theme.theme
}; };
}); });
editor.menuOptions.setMode = modelist.modes.map(function(mode) { editor.menuOptions.setMode = modelist.modes.map(function(mode) {
return { return {
'textContent' : mode.name, textContent: mode.name,
'value' : mode.mode value: mode.mode
}; };
}); });
}; };

View file

@ -53,7 +53,7 @@ var supportedModes = {
C9Search: ["c9search_results"], C9Search: ["c9search_results"],
C_Cpp: ["cpp|c|cc|cxx|h|hh|hpp"], C_Cpp: ["cpp|c|cc|cxx|h|hh|hpp"],
Cirru: ["cirru|cr"], Cirru: ["cirru|cr"],
Clojure: ["clj"], Clojure: ["clj|cljs"],
Cobol: ["CBL|COB"], Cobol: ["CBL|COB"],
coffee: ["coffee|cf|cson|^Cakefile"], coffee: ["coffee|cf|cson|^Cakefile"],
ColdFusion: ["cfm"], ColdFusion: ["cfm"],
@ -70,6 +70,7 @@ var supportedModes = {
Forth: ["frt|fs|ldr"], Forth: ["frt|fs|ldr"],
FTL: ["ftl"], FTL: ["ftl"],
Gherkin: ["feature"], Gherkin: ["feature"],
Gitignore: ["^.gitignore"],
Glsl: ["glsl|frag|vert"], Glsl: ["glsl|frag|vert"],
golang: ["go"], golang: ["go"],
Groovy: ["groovy"], Groovy: ["groovy"],
@ -144,6 +145,7 @@ var supportedModes = {
Toml: ["toml"], Toml: ["toml"],
Twig: ["twig"], Twig: ["twig"],
Typescript: ["ts|typescript|str"], Typescript: ["ts|typescript|str"],
Vala: ["vala"],
VBScript: ["vbs"], VBScript: ["vbs"],
Velocity: ["vm"], Velocity: ["vm"],
Verilog: ["v|vh|sv|svh"], Verilog: ["v|vh|sv|svh"],

View file

@ -155,7 +155,7 @@ function setupContainer(element, getValue) {
return container; return container;
} }
exports.transformTextarea = function(element, loader) { exports.transformTextarea = function(element, options) {
var session; var session;
var container = setupContainer(element, function() { var container = setupContainer(element, function() {
return session.getValue(); return session.getValue();
@ -215,9 +215,8 @@ exports.transformTextarea = function(element, loader) {
applyStyles(settingDiv, settingDivStyles); applyStyles(settingDiv, settingDivStyles);
container.appendChild(settingDiv); container.appendChild(settingDiv);
options = options || exports.defaultOptions;
// Power up ace on the textarea: // Power up ace on the textarea:
var options = {};
var editor = ace.edit(editorDiv); var editor = ace.edit(editorDiv);
session = editor.getSession(); session = editor.getSession();
@ -228,10 +227,10 @@ exports.transformTextarea = function(element, loader) {
container.appendChild(settingOpener); container.appendChild(settingOpener);
// Create the API. // Create the API.
setupApi(editor, editorDiv, settingDiv, ace, options, loader); setupApi(editor, editorDiv, settingDiv, ace, options, load);
// Create the setting's panel. // Create the setting's panel.
setupSettingPanel(settingDiv, settingOpener, editor, options); setupSettingPanel(settingDiv, settingOpener, editor);
var state = ""; var state = "";
event.addListener(settingOpener, "mousemove", function(e) { event.addListener(settingOpener, "mousemove", function(e) {
@ -296,37 +295,15 @@ function setupApi(editor, editorDiv, settingDiv, ace, options, loader) {
}; };
editor.$setOption = editor.setOption; editor.$setOption = editor.setOption;
editor.$getOption = editor.getOption;
editor.setOption = function(key, value) { editor.setOption = function(key, value) {
if (options[key] == value) return;
switch (key) { switch (key) {
case "mode": case "mode":
if (value != "text") { editor.$setOption("mode", "ace/mode/" + value)
// Load the required mode file. Files get loaded only once.
loader("mode-" + value + ".js", "ace/mode/" + value, function() {
var aceMode = require("../mode/" + value).Mode;
session.setMode(new aceMode());
});
} else {
session.setMode(new (require("../mode/text").Mode));
}
break; break;
case "theme": case "theme":
if (value != "textmate") { editor.$setOption("theme", "ace/theme/" + value)
// Load the required theme file. Files get loaded only once.
loader("theme-" + value + ".js", "ace/theme/" + value, function() {
editor.setTheme("ace/theme/" + value);
});
} else {
editor.setTheme("ace/theme/textmate");
}
break; break;
case "fontSize":
editorDiv.style.fontSize = value;
break;
case "keybindings": case "keybindings":
switch (value) { switch (value) {
case "vim": case "vim":
@ -341,58 +318,55 @@ function setupApi(editor, editorDiv, settingDiv, ace, options, loader) {
break; break;
case "softWrap": case "softWrap":
switch (value) { case "fontSize":
case "off": editor.$setOption(key, value);
session.setUseWrapMode(false);
renderer.setPrintMarginColumn(80);
break;
case "40":
session.setUseWrapMode(true);
session.setWrapLimitRange(40, 40);
renderer.setPrintMarginColumn(40);
break;
case "80":
session.setUseWrapMode(true);
session.setWrapLimitRange(80, 80);
renderer.setPrintMarginColumn(80);
break;
case "free":
session.setUseWrapMode(true);
session.setWrapLimitRange(null, null);
renderer.setPrintMarginColumn(80);
break;
}
break; break;
default: default:
editor.$setOption(key, toBool(value)); editor.$setOption(key, toBool(value));
} }
options[key] = value;
}; };
editor.getOption = function(key) { editor.getOption = function(key) {
return options[key]; switch (key) {
case "mode":
return editor.$getOption("mode").substr("ace/mode/".length)
break;
case "theme":
return editor.$getOption("theme").substr("ace/theme/".length)
break;
case "keybindings":
var value = editor.getKeyboardHandler()
switch (value && value.$id) {
case "ace/keyboard/vim":
return "vim";
case "ace/keyboard/emacs":
return "emacs";
default:
return "ace";
}
break;
default:
return editor.$getOption(key);
}
}; };
editor.getOptions = function() { editor.setOptions(options);
return options;
};
editor.setOptions(exports.options);
return editor; return editor;
} }
function setupSettingPanel(settingDiv, settingOpener, editor, options) { function setupSettingPanel(settingDiv, settingOpener, editor) {
var BOOL = null; var BOOL = null;
var desc = { var desc = {
mode: "Mode:", mode: "Mode:",
gutter: "Display Gutter:", wrap: "Soft Wrap:",
theme: "Theme:", theme: "Theme:",
fontSize: "Font Size:", fontSize: "Font Size:",
softWrap: "Soft Wrap:", showGutter: "Display Gutter:",
keybindings: "Keyboard", keybindings: "Keyboard",
showPrintMargin: "Show Print Margin:", showPrintMargin: "Show Print Margin:",
useSoftTabs: "Use Soft Tabs:", useSoftTabs: "Use Soft Tabs:",
@ -445,7 +419,7 @@ function setupSettingPanel(settingDiv, settingOpener, editor, options) {
twilight: "Twilight", twilight: "Twilight",
vibrant_ink: "Vibrant Ink" vibrant_ink: "Vibrant Ink"
}, },
gutter: BOOL, showGutter: BOOL,
fontSize: { fontSize: {
"10px": "10px", "10px": "10px",
"11px": "11px", "11px": "11px",
@ -453,7 +427,7 @@ function setupSettingPanel(settingDiv, settingOpener, editor, options) {
"14px": "14px", "14px": "14px",
"16px": "16px" "16px": "16px"
}, },
softWrap: { wrap: {
off: "Off", off: "Off",
40: "40", 40: "40",
80: "80", 80: "80",
@ -476,7 +450,7 @@ function setupSettingPanel(settingDiv, settingOpener, editor, options) {
if (!obj) { if (!obj) {
builder.push( builder.push(
"<input type='checkbox' title='", option, "' ", "<input type='checkbox' title='", option, "' ",
cValue == "true" ? "checked='true'" : "", cValue + "" == "true" ? "checked='true'" : "",
"'></input>" "'></input>"
); );
return; return;
@ -496,10 +470,10 @@ function setupSettingPanel(settingDiv, settingOpener, editor, options) {
builder.push("</select>"); builder.push("</select>");
} }
for (var option in options) { for (var option in exports.defaultOptions) {
table.push("<tr><td>", desc[option], "</td>"); table.push("<tr><td>", desc[option], "</td>");
table.push("<td>"); table.push("<td>");
renderOption(table, option, optionValues[option], options[option]); renderOption(table, option, optionValues[option], editor.getOption(option));
table.push("</td></tr>"); table.push("</td></tr>");
} }
table.push("</table>"); table.push("</table>");
@ -532,12 +506,12 @@ function setupSettingPanel(settingDiv, settingOpener, editor, options) {
} }
// Default startup options. // Default startup options.
exports.options = { exports.defaultOptions = {
mode: "text", mode: "javascript",
theme: "textmate", theme: "textmate",
gutter: "false", wrap: "off",
fontSize: "12px", fontSize: "12px",
softWrap: "off", showGutter: "false",
keybindings: "ace", keybindings: "ace",
showPrintMargin: "false", showPrintMargin: "false",
useSoftTabs: "true", useSoftTabs: "true",

View file

@ -46,7 +46,6 @@ exports.$detectIndentation = function(lines, fallback) {
if (!/^\s*[^*+\-\s]/.test(line)) if (!/^\s*[^*+\-\s]/.test(line))
continue; continue;
var tabs = line.match(/^\t*/)[0].length;
if (line[0] == "\t") if (line[0] == "\t")
tabIndents++; tabIndents++;
@ -65,9 +64,6 @@ exports.$detectIndentation = function(lines, fallback) {
line = lines[i++]; line = lines[i++];
} }
if (!stats.length)
return;
function getScore(indent) { function getScore(indent) {
var score = 0; var score = 0;
for (var i = indent; i < stats.length; i += indent) for (var i = indent; i < stats.length; i += indent)
@ -82,7 +78,7 @@ exports.$detectIndentation = function(lines, fallback) {
for (var i = 1; i < 12; i++) { for (var i = 1; i < 12; i++) {
if (i == 1) { if (i == 1) {
spaceIndents = getScore(i); spaceIndents = getScore(i);
var score = 1; var score = stats.length && 1;
} else } else
var score = getScore(i) / spaceIndents; var score = getScore(i) / spaceIndents;
@ -99,7 +95,7 @@ exports.$detectIndentation = function(lines, fallback) {
if (tabIndents > spaceIndents + 1) if (tabIndents > spaceIndents + 1)
return {ch: "\t", length: tabLength}; return {ch: "\t", length: tabLength};
if (spaceIndents + 1 > tabIndents) if (spaceIndents > tabIndents + 1)
return {ch: " ", length: tabLength}; return {ch: " ", length: tabLength};
}; };

View file

@ -0,0 +1,116 @@
if (typeof process !== "undefined") {
require("amd-loader");
require("../test/mockdom");
}
define(function(require, exports, module) {
"use strict";
var assert = require("assert");
var EditSession = require("../edit_session").EditSession;
var whitespace = require("./whitespace");
// Execution ORDER: test.setUpSuite, setUp, testFn, tearDown, test.tearDownSuite
module.exports = {
timeout: 10000,
"test tab detection": function(next) {
var s = new EditSession([
"define({",
"\tfoo:1,",
"\tbar:2,",
"\tbaz:{,",
"\t\tx:3",
"\t}",
"})"
]);
var indent = whitespace.$detectIndentation(s.doc.$lines);
assert.equal(indent.ch, "\t");
assert.equal(indent.length, undefined);
s.insert({row: 0, column: 0}, " ");
indent = whitespace.$detectIndentation(s.doc.$lines);
assert.equal(indent.ch, "\t");
assert.equal(indent.length, 4);
s.setValue("");
indent = whitespace.$detectIndentation(s.doc.$lines);
assert.ok(!indent);
next();
},
"test empty session": function(next) {
var s = new EditSession([
"define({",
"foo:1,",
"})"
]);
var indent = whitespace.$detectIndentation(s.doc.$lines);
assert.ok(!indent);
s.insert({row: 1, column: 0}, " x\n ");
indent = whitespace.$detectIndentation(s.doc.$lines);
assert.equal(indent.ch, " ");
assert.equal(indent.length, 4);
next();
},
"!test one line": function(next) {
var s = new EditSession([
"define({",
" foo:1,",
"})"
]);
var indent = whitespace.$detectIndentation(s.doc.$lines);
assert.equal(indent.ch, " ");
assert.equal(indent.length, 4);
next();
},
"test 1 width indents": function(next) {
var s = new EditSession([
"define({",
" foo:1,",
"})",
"define({",
" bar:1,",
"})",
" t",
" t",
" t",
" t",
" t",
" t",
" t",
" t"
]);
var indent = whitespace.$detectIndentation(s.doc.$lines);
// assert.equal(indent.ch, " ");
// assert.equal(indent.length, 4);
s = new EditSession([
"{",
" foo:1,",
" bar: {",
" baz:2",
" }",
"}"
]);
indent = whitespace.$detectIndentation(s.doc.$lines);
assert.equal(indent.ch, " ");
assert.equal(indent.length, 1);
next();
},
};
});
if (typeof module !== "undefined" && module === require.main) {
require("asyncjs").test.testcase(module.exports).exec();
}

View file

@ -0,0 +1,82 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
var HashHandler = require("./hash_handler").HashHandler;
exports.handler = new HashHandler();
[{
bindKey: "Shift-Tab|Tab",
command: "passKeysToBrowser"
}, {
bindKey: {win: "Ctrl-L", mac: "Cmd-L"},
command: "passKeysToBrowser"
}, {
bindKey: {win: "Ctrl-G", mac: "Cmd-G"},
command: "gotoline"
}, {
bindKey: {win: "Ctrl-T|Ctrl-Shift-T", mac: "Cmd-T|Cmd-Shift-T"},
command: "passKeysToBrowser"
}, {
bindKey: {win: "Ctrl-G", mac: "Cmd-G"},
command: "passKeysToBrowser"
}, {
bindKey: {win: "Ctrl-G", mac: "Cmd-G"},
command: "passKeysToBrowser"
}, {
name: "golineup",
bindKey: {win: null, mac: "Ctrl-P"},
}, {
name: "golinedown",
bindKey: {win: null, mac: "Ctrl-N"},
}, {
name: "gotoleft",
bindKey: {win: null, mac: "Ctrl-B"},
}, {
name: "gotoright",
bindKey: {win: null, mac: "Ctrl-F"},
}, {
name: "gotolineend",
bindKey: {win: null, mac: "Ctrl-E"},
}, {
name: "gotolinestart",
bindKey: {win: null, mac: "Ctrl-A"},
}
].forEach(function(k) {
var bindKey = k.bindKey;
if (typeof bindKey == "object")
bindKey = bindKey[exports.handler.platform];
exports.handler.bindKey(bindKey, k.command);
});
exports.handler.$id = "ace/keyboard/textarea";
});

View file

@ -428,13 +428,17 @@ var TextInput = function(parentNode, host) {
this.onContextMenu = function(e) { this.onContextMenu = function(e) {
afterContextMenu = true; afterContextMenu = true;
if (!tempStyle)
tempStyle = text.style.cssText;
text.style.cssText = "z-index:100000;" + (useragent.isIE ? "opacity:0.1;" : "");
resetSelection(host.selection.isEmpty()); resetSelection(host.selection.isEmpty());
host._emit("nativecontextmenu", {target: host, domEvent: e}); host._emit("nativecontextmenu", {target: host, domEvent: e});
this.moveToMouse(e, true);
};
this.moveToMouse = function(e, bringToFront) {
if (!tempStyle)
tempStyle = text.style.cssText;
text.style.cssText = (bringToFront ? "z-index:100000;" : "")
+ (useragent.isIE ? "opacity:0.1;" : "");
var rect = host.container.getBoundingClientRect(); var rect = host.container.getBoundingClientRect();
var style = dom.computedStyle(host.container); var style = dom.computedStyle(host.container);
var top = rect.top + (parseInt(style.borderTopWidth) || 0); var top = rect.top + (parseInt(style.borderTopWidth) || 0);

View file

@ -34,6 +34,7 @@ define(function(require, exports, module) {
var util = require("./util"); var util = require("./util");
var registers = require("../registers"); var registers = require("../registers");
var Range = require("../../../range").Range;
module.exports = { module.exports = {
"d": { "d": {
@ -90,15 +91,18 @@ module.exports = {
count = count || 1; count = count || 1;
switch (param) { switch (param) {
case "c": case "c":
for (var i = 0; i < count; i++) { editor.$blockScrolling++;
editor.removeLines(); editor.selection.$moveSelection(function() {
editor.selection.moveCursorBy(count - 1, 0);
});
var rows = editor.$getSelectedRows();
range = new Range(rows.first, 0, rows.last, Infinity);
editor.session.remove(range);
editor.$blockScrolling--;
util.insertMode(editor); util.insertMode(editor);
}
break; break;
default: default:
if (range) { if (range) {
// range.end.column ++; // range.end.column ++;
editor.session.remove(range); editor.session.remove(range);
util.insertMode(editor); util.insertMode(editor);

View file

@ -93,7 +93,7 @@ var Marker = function(parentEl) {
this.drawSingleLineMarker(html, range, marker.clazz + " ace_start", config); this.drawSingleLineMarker(html, range, marker.clazz + " ace_start", config);
} }
} }
this.element = dom.setInnerHtml(this.element, html.join("")); this.element.innerHTML = html.join("");
}; };
this.$getTop = function(row, layerConfig) { this.$getTop = function(row, layerConfig) {

View file

@ -203,7 +203,7 @@ var Text = function(parentEl) {
html, row, !this.$useLineGroups(), row == foldStart ? foldLine : false html, row, !this.$useLineGroups(), row == foldStart ? foldLine : false
); );
lineElement.style.height = config.lineHeight * this.session.getRowLength(row) + "px"; lineElement.style.height = config.lineHeight * this.session.getRowLength(row) + "px";
dom.setInnerHtml(lineElement, html.join("")); lineElement.innerHTML = html.join("");
} }
row++; row++;
} }
@ -310,7 +310,7 @@ var Text = function(parentEl) {
row++; row++;
} }
this.element = dom.setInnerHtml(this.element, html.join("")); this.element.innerHTML = html.join("");
}; };
this.$textToken = { this.$textToken = {

View file

@ -85,7 +85,7 @@ exports.preventDefault = function(e) {
exports.getButton = function(e) { exports.getButton = function(e) {
if (e.type == "dblclick") if (e.type == "dblclick")
return 0; return 0;
if (e.type == "contextmenu" || (e.ctrlKey && useragent.isMac)) if (e.type == "contextmenu" || (useragent.isMac && (e.ctrlKey && !e.altKey && !e.shiftKey)))
return 2; return 2;
// DOM Event // DOM Event
@ -183,7 +183,7 @@ exports.addMultiMouseDownListener = function(el, timeouts, eventHandler, callbac
if (!timer || isNewClick) if (!timer || isNewClick)
clicks = 1; clicks = 1;
if (timer) if (timer)
clearTimeout(timer) clearTimeout(timer);
timer = setTimeout(function() {timer = null}, timeouts[clicks - 1] || 600); timer = setTimeout(function() {timer = null}, timeouts[clicks - 1] || 600);
if (clicks == 1) { if (clicks == 1) {

View file

@ -82,7 +82,7 @@ exports.isIE =
exports.isOldIE = exports.isIE && exports.isIE < 9; exports.isOldIE = exports.isIE && exports.isIE < 9;
// Is this Firefox or related? // Is this Firefox or related?
exports.isGecko = exports.isMozilla = window.controllers && window.navigator.product === "Gecko"; exports.isGecko = exports.isMozilla = (window.Controllers || window.controllers) && window.navigator.product === "Gecko";
// oldGecko == rev < 2.0 // oldGecko == rev < 2.0
exports.isOldGecko = exports.isGecko && parseInt((ua.match(/rv\:(\d+)/)||[])[1], 10) < 4; exports.isOldGecko = exports.isGecko && parseInt((ua.match(/rv\:(\d+)/)||[])[1], 10) < 4;

View file

@ -87,7 +87,6 @@ function LineWidgets(session) {
editor.widgetManager = this; editor.widgetManager = this;
editor.setOption("enableLineWidgets", true);
editor.renderer.on("beforeRender", this.measureWidgets); editor.renderer.on("beforeRender", this.measureWidgets);
editor.renderer.on("afterRender", this.renderWidgets); editor.renderer.on("afterRender", this.renderWidgets);
}; };

View file

@ -47,6 +47,7 @@ oop.inherits(Mode, TextMode);
(function() { (function() {
this.lineCommentStart = "--"; this.lineCommentStart = "--";
this.blockComment = {start: "(*", end: "*)"}; this.blockComment = {start: "(*", end: "*)"};
this.$id = "ace/mode/applescript";
// Extra logic goes here. // Extra logic goes here.
}).call(Mode.prototype); }).call(Mode.prototype);

View file

@ -54,7 +54,7 @@ var DartHighlightRules = function() {
}, },
{ {
token: "keyword.other.import.dart", token: "keyword.other.import.dart",
regex: "(?:\\b)(?:library|import|part|of)(?:\\b)" regex: "(?:\\b)(?:library|import|export|part|of)(?:\\b)"
}, },
{ {
token : ["keyword.other.import.dart", "text"], token : ["keyword.other.import.dart", "text"],

19
lib/ace/mode/gitignore.js Normal file
View file

@ -0,0 +1,19 @@
define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var GitignoreHighlightRules = require("./gitignore_highlight_rules").GitignoreHighlightRules;
var Mode = function() {
this.HighlightRules = GitignoreHighlightRules;
};
oop.inherits(Mode, TextMode);
(function() {
this.$id = "ace/mode/gitignore";
}).call(Mode.prototype);
exports.Mode = Mode;
});

View file

@ -0,0 +1,31 @@
define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var GitignoreHighlightRules = function() {
this.$rules = {
"start" : [
{
token : "comment",
regex : /^\s*#.*$/
}, {
token : "keyword", // negated patterns
regex : /^\s*!.*$/
}
]
};
this.normalizeRules();
};
GitignoreHighlightRules.metaData = {
fileTypes: ['gitignore'],
name: 'Gitignore'
};
oop.inherits(GitignoreHighlightRules, TextHighlightRules);
exports.GitignoreHighlightRules = GitignoreHighlightRules;
});

View file

@ -72,9 +72,6 @@ define(function(require, exports, module) {
}, { }, {
token : "paren.rparen", token : "paren.rparen",
regex : "[\\])}]" regex : "[\\])}]"
}, {
token: "invalid",
regex: "\\s+$"
}, { }, {
token : "text", token : "text",
regex : "\\s+" regex : "\\s+"

View file

@ -27,9 +27,9 @@ module.exports = {
}, },
{}], {}],
2:[function(_dereq_,module,exports){ 2:[function(_dereq_,module,exports){
// Underscore.js 1.4.4 // Underscore.js 1.6.0
// http://underscorejs.org // http://underscorejs.org
// (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc. // (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
// Underscore may be freely distributed under the MIT license. // Underscore may be freely distributed under the MIT license.
(function() { (function() {
@ -37,7 +37,7 @@ module.exports = {
// Baseline setup // Baseline setup
// -------------- // --------------
// Establish the root object, `window` in the browser, or `global` on the server. // Establish the root object, `window` in the browser, or `exports` on the server.
var root = this; var root = this;
// Save the previous value of the `_` variable. // Save the previous value of the `_` variable.
@ -50,7 +50,8 @@ module.exports = {
var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype; var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
// Create quick reference variables for speed access to core prototypes. // Create quick reference variables for speed access to core prototypes.
var push = ArrayProto.push, var
push = ArrayProto.push,
slice = ArrayProto.slice, slice = ArrayProto.slice,
concat = ArrayProto.concat, concat = ArrayProto.concat,
toString = ObjProto.toString, toString = ObjProto.toString,
@ -93,7 +94,7 @@ module.exports = {
} }
// Current version. // Current version.
_.VERSION = '1.4.4'; _.VERSION = '1.6.0';
// Collection Functions // Collection Functions
// -------------------- // --------------------
@ -102,20 +103,20 @@ module.exports = {
// Handles objects with the built-in `forEach`, arrays, and raw objects. // Handles objects with the built-in `forEach`, arrays, and raw objects.
// Delegates to **ECMAScript 5**'s native `forEach` if available. // Delegates to **ECMAScript 5**'s native `forEach` if available.
var each = _.each = _.forEach = function(obj, iterator, context) { var each = _.each = _.forEach = function(obj, iterator, context) {
if (obj == null) return; if (obj == null) return obj;
if (nativeForEach && obj.forEach === nativeForEach) { if (nativeForEach && obj.forEach === nativeForEach) {
obj.forEach(iterator, context); obj.forEach(iterator, context);
} else if (obj.length === +obj.length) { } else if (obj.length === +obj.length) {
for (var i = 0, l = obj.length; i < l; i++) { for (var i = 0, length = obj.length; i < length; i++) {
if (iterator.call(context, obj[i], i, obj) === breaker) return; if (iterator.call(context, obj[i], i, obj) === breaker) return;
} }
} else { } else {
for (var key in obj) { var keys = _.keys(obj);
if (_.has(obj, key)) { for (var i = 0, length = keys.length; i < length; i++) {
if (iterator.call(context, obj[key], key, obj) === breaker) return; if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return;
}
} }
} }
return obj;
}; };
// Return the results of applying the iterator to each element. // Return the results of applying the iterator to each element.
@ -125,7 +126,7 @@ module.exports = {
if (obj == null) return results; if (obj == null) return results;
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context); if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
each(obj, function(value, index, list) { each(obj, function(value, index, list) {
results[results.length] = iterator.call(context, value, index, list); results.push(iterator.call(context, value, index, list));
}); });
return results; return results;
}; };
@ -181,10 +182,10 @@ module.exports = {
}; };
// Return the first value which passes a truth test. Aliased as `detect`. // Return the first value which passes a truth test. Aliased as `detect`.
_.find = _.detect = function(obj, iterator, context) { _.find = _.detect = function(obj, predicate, context) {
var result; var result;
any(obj, function(value, index, list) { any(obj, function(value, index, list) {
if (iterator.call(context, value, index, list)) { if (predicate.call(context, value, index, list)) {
result = value; result = value;
return true; return true;
} }
@ -195,33 +196,33 @@ module.exports = {
// Return all the elements that pass a truth test. // Return all the elements that pass a truth test.
// Delegates to **ECMAScript 5**'s native `filter` if available. // Delegates to **ECMAScript 5**'s native `filter` if available.
// Aliased as `select`. // Aliased as `select`.
_.filter = _.select = function(obj, iterator, context) { _.filter = _.select = function(obj, predicate, context) {
var results = []; var results = [];
if (obj == null) return results; if (obj == null) return results;
if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context); if (nativeFilter && obj.filter === nativeFilter) return obj.filter(predicate, context);
each(obj, function(value, index, list) { each(obj, function(value, index, list) {
if (iterator.call(context, value, index, list)) results[results.length] = value; if (predicate.call(context, value, index, list)) results.push(value);
}); });
return results; return results;
}; };
// Return all the elements for which a truth test fails. // Return all the elements for which a truth test fails.
_.reject = function(obj, iterator, context) { _.reject = function(obj, predicate, context) {
return _.filter(obj, function(value, index, list) { return _.filter(obj, function(value, index, list) {
return !iterator.call(context, value, index, list); return !predicate.call(context, value, index, list);
}, context); }, context);
}; };
// Determine whether all of the elements match a truth test. // Determine whether all of the elements match a truth test.
// Delegates to **ECMAScript 5**'s native `every` if available. // Delegates to **ECMAScript 5**'s native `every` if available.
// Aliased as `all`. // Aliased as `all`.
_.every = _.all = function(obj, iterator, context) { _.every = _.all = function(obj, predicate, context) {
iterator || (iterator = _.identity); predicate || (predicate = _.identity);
var result = true; var result = true;
if (obj == null) return result; if (obj == null) return result;
if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context); if (nativeEvery && obj.every === nativeEvery) return obj.every(predicate, context);
each(obj, function(value, index, list) { each(obj, function(value, index, list) {
if (!(result = result && iterator.call(context, value, index, list))) return breaker; if (!(result = result && predicate.call(context, value, index, list))) return breaker;
}); });
return !!result; return !!result;
}; };
@ -229,13 +230,13 @@ module.exports = {
// Determine if at least one element in the object matches a truth test. // Determine if at least one element in the object matches a truth test.
// Delegates to **ECMAScript 5**'s native `some` if available. // Delegates to **ECMAScript 5**'s native `some` if available.
// Aliased as `any`. // Aliased as `any`.
var any = _.some = _.any = function(obj, iterator, context) { var any = _.some = _.any = function(obj, predicate, context) {
iterator || (iterator = _.identity); predicate || (predicate = _.identity);
var result = false; var result = false;
if (obj == null) return result; if (obj == null) return result;
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context); if (nativeSome && obj.some === nativeSome) return obj.some(predicate, context);
each(obj, function(value, index, list) { each(obj, function(value, index, list) {
if (result || (result = iterator.call(context, value, index, list))) return breaker; if (result || (result = predicate.call(context, value, index, list))) return breaker;
}); });
return !!result; return !!result;
}; };
@ -261,41 +262,37 @@ module.exports = {
// Convenience version of a common use case of `map`: fetching a property. // Convenience version of a common use case of `map`: fetching a property.
_.pluck = function(obj, key) { _.pluck = function(obj, key) {
return _.map(obj, function(value){ return value[key]; }); return _.map(obj, _.property(key));
}; };
// Convenience version of a common use case of `filter`: selecting only objects // Convenience version of a common use case of `filter`: selecting only objects
// containing specific `key:value` pairs. // containing specific `key:value` pairs.
_.where = function(obj, attrs, first) { _.where = function(obj, attrs) {
if (_.isEmpty(attrs)) return first ? null : []; return _.filter(obj, _.matches(attrs));
return _[first ? 'find' : 'filter'](obj, function(value) {
for (var key in attrs) {
if (attrs[key] !== value[key]) return false;
}
return true;
});
}; };
// Convenience version of a common use case of `find`: getting the first object // Convenience version of a common use case of `find`: getting the first object
// containing specific `key:value` pairs. // containing specific `key:value` pairs.
_.findWhere = function(obj, attrs) { _.findWhere = function(obj, attrs) {
return _.where(obj, attrs, true); return _.find(obj, _.matches(attrs));
}; };
// Return the maximum element or (element-based computation). // Return the maximum element or (element-based computation).
// Can't optimize arrays of integers longer than 65,535 elements. // Can't optimize arrays of integers longer than 65,535 elements.
// See: https://bugs.webkit.org/show_bug.cgi?id=80797 // See [WebKit Bug 80797](https://bugs.webkit.org/show_bug.cgi?id=80797)
_.max = function(obj, iterator, context) { _.max = function(obj, iterator, context) {
if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) { if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
return Math.max.apply(Math, obj); return Math.max.apply(Math, obj);
} }
if (!iterator && _.isEmpty(obj)) return -Infinity; var result = -Infinity, lastComputed = -Infinity;
var result = {computed : -Infinity, value: -Infinity};
each(obj, function(value, index, list) { each(obj, function(value, index, list) {
var computed = iterator ? iterator.call(context, value, index, list) : value; var computed = iterator ? iterator.call(context, value, index, list) : value;
computed >= result.computed && (result = {value : value, computed : computed}); if (computed > lastComputed) {
result = value;
lastComputed = computed;
}
}); });
return result.value; return result;
}; };
// Return the minimum element (or element-based computation). // Return the minimum element (or element-based computation).
@ -303,16 +300,19 @@ module.exports = {
if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) { if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
return Math.min.apply(Math, obj); return Math.min.apply(Math, obj);
} }
if (!iterator && _.isEmpty(obj)) return Infinity; var result = Infinity, lastComputed = Infinity;
var result = {computed : Infinity, value: Infinity};
each(obj, function(value, index, list) { each(obj, function(value, index, list) {
var computed = iterator ? iterator.call(context, value, index, list) : value; var computed = iterator ? iterator.call(context, value, index, list) : value;
computed < result.computed && (result = {value : value, computed : computed}); if (computed < lastComputed) {
result = value;
lastComputed = computed;
}
}); });
return result.value; return result;
}; };
// Shuffle an array. // Shuffle an array, using the modern version of the
// [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
_.shuffle = function(obj) { _.shuffle = function(obj) {
var rand; var rand;
var index = 0; var index = 0;
@ -325,14 +325,27 @@ module.exports = {
return shuffled; return shuffled;
}; };
// Sample **n** random values from a collection.
// If **n** is not specified, returns a single random element.
// The internal `guard` argument allows it to work with `map`.
_.sample = function(obj, n, guard) {
if (n == null || guard) {
if (obj.length !== +obj.length) obj = _.values(obj);
return obj[_.random(obj.length - 1)];
}
return _.shuffle(obj).slice(0, Math.max(0, n));
};
// An internal function to generate lookup iterators. // An internal function to generate lookup iterators.
var lookupIterator = function(value) { var lookupIterator = function(value) {
return _.isFunction(value) ? value : function(obj){ return obj[value]; }; if (value == null) return _.identity;
if (_.isFunction(value)) return value;
return _.property(value);
}; };
// Sort the object's values by a criterion produced by an iterator. // Sort the object's values by a criterion produced by an iterator.
_.sortBy = function(obj, value, context) { _.sortBy = function(obj, iterator, context) {
var iterator = lookupIterator(value); iterator = lookupIterator(iterator);
return _.pluck(_.map(obj, function(value, index, list) { return _.pluck(_.map(obj, function(value, index, list) {
return { return {
value: value, value: value,
@ -346,43 +359,46 @@ module.exports = {
if (a > b || a === void 0) return 1; if (a > b || a === void 0) return 1;
if (a < b || b === void 0) return -1; if (a < b || b === void 0) return -1;
} }
return left.index < right.index ? -1 : 1; return left.index - right.index;
}), 'value'); }), 'value');
}; };
// An internal function used for aggregate "group by" operations. // An internal function used for aggregate "group by" operations.
var group = function(obj, value, context, behavior) { var group = function(behavior) {
return function(obj, iterator, context) {
var result = {}; var result = {};
var iterator = lookupIterator(value || _.identity); iterator = lookupIterator(iterator);
each(obj, function(value, index) { each(obj, function(value, index) {
var key = iterator.call(context, value, index, obj); var key = iterator.call(context, value, index, obj);
behavior(result, key, value); behavior(result, key, value);
}); });
return result; return result;
}; };
};
// Groups the object's values by a criterion. Pass either a string attribute // Groups the object's values by a criterion. Pass either a string attribute
// to group by, or a function that returns the criterion. // to group by, or a function that returns the criterion.
_.groupBy = function(obj, value, context) { _.groupBy = group(function(result, key, value) {
return group(obj, value, context, function(result, key, value) { _.has(result, key) ? result[key].push(value) : result[key] = [value];
(_.has(result, key) ? result[key] : (result[key] = [])).push(value); });
// Indexes the object's values by a criterion, similar to `groupBy`, but for
// when you know that your index values will be unique.
_.indexBy = group(function(result, key, value) {
result[key] = value;
}); });
};
// Counts instances of an object that group by a certain criterion. Pass // Counts instances of an object that group by a certain criterion. Pass
// either a string attribute to count by, or a function that returns the // either a string attribute to count by, or a function that returns the
// criterion. // criterion.
_.countBy = function(obj, value, context) { _.countBy = group(function(result, key) {
return group(obj, value, context, function(result, key) { _.has(result, key) ? result[key]++ : result[key] = 1;
if (!_.has(result, key)) result[key] = 0;
result[key]++;
}); });
};
// Use a comparator function to figure out the smallest index at which // Use a comparator function to figure out the smallest index at which
// an object should be inserted so as to maintain order. Uses binary search. // an object should be inserted so as to maintain order. Uses binary search.
_.sortedIndex = function(array, obj, iterator, context) { _.sortedIndex = function(array, obj, iterator, context) {
iterator = iterator == null ? _.identity : lookupIterator(iterator); iterator = lookupIterator(iterator);
var value = iterator.call(context, obj); var value = iterator.call(context, obj);
var low = 0, high = array.length; var low = 0, high = array.length;
while (low < high) { while (low < high) {
@ -392,7 +408,7 @@ module.exports = {
return low; return low;
}; };
// Safely convert anything iterable into a real, live array. // Safely create a real, live array from anything iterable.
_.toArray = function(obj) { _.toArray = function(obj) {
if (!obj) return []; if (!obj) return [];
if (_.isArray(obj)) return slice.call(obj); if (_.isArray(obj)) return slice.call(obj);
@ -414,7 +430,9 @@ module.exports = {
// allows it to work with `_.map`. // allows it to work with `_.map`.
_.first = _.head = _.take = function(array, n, guard) { _.first = _.head = _.take = function(array, n, guard) {
if (array == null) return void 0; if (array == null) return void 0;
return (n != null) && !guard ? slice.call(array, 0, n) : array[0]; if ((n == null) || guard) return array[0];
if (n < 0) return [];
return slice.call(array, 0, n);
}; };
// Returns everything but the last entry of the array. Especially useful on // Returns everything but the last entry of the array. Especially useful on
@ -429,11 +447,8 @@ module.exports = {
// values in the array. The **guard** check allows it to work with `_.map`. // values in the array. The **guard** check allows it to work with `_.map`.
_.last = function(array, n, guard) { _.last = function(array, n, guard) {
if (array == null) return void 0; if (array == null) return void 0;
if ((n != null) && !guard) { if ((n == null) || guard) return array[array.length - 1];
return slice.call(array, Math.max(array.length - n, 0)); return slice.call(array, Math.max(array.length - n, 0));
} else {
return array[array.length - 1];
}
}; };
// Returns everything but the first entry of the array. Aliased as `tail` and `drop`. // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
@ -451,8 +466,11 @@ module.exports = {
// Internal implementation of a recursive `flatten` function. // Internal implementation of a recursive `flatten` function.
var flatten = function(input, shallow, output) { var flatten = function(input, shallow, output) {
if (shallow && _.every(input, _.isArray)) {
return concat.apply(output, input);
}
each(input, function(value) { each(input, function(value) {
if (_.isArray(value)) { if (_.isArray(value) || _.isArguments(value)) {
shallow ? push.apply(output, value) : flatten(value, shallow, output); shallow ? push.apply(output, value) : flatten(value, shallow, output);
} else { } else {
output.push(value); output.push(value);
@ -461,7 +479,7 @@ module.exports = {
return output; return output;
}; };
// Return a completely flattened version of an array. // Flatten out an array, either recursively (by default), or just one level.
_.flatten = function(array, shallow) { _.flatten = function(array, shallow) {
return flatten(array, shallow, []); return flatten(array, shallow, []);
}; };
@ -471,6 +489,16 @@ module.exports = {
return _.difference(array, slice.call(arguments, 1)); return _.difference(array, slice.call(arguments, 1));
}; };
// Split an array into two arrays: one whose elements all satisfy the given
// predicate, and one whose elements all do not satisfy the predicate.
_.partition = function(array, predicate) {
var pass = [], fail = [];
each(array, function(elem) {
(predicate(elem) ? pass : fail).push(elem);
});
return [pass, fail];
};
// Produce a duplicate-free version of the array. If the array has already // Produce a duplicate-free version of the array. If the array has already
// been sorted, you have the option of using a faster algorithm. // been sorted, you have the option of using a faster algorithm.
// Aliased as `unique`. // Aliased as `unique`.
@ -495,7 +523,7 @@ module.exports = {
// Produce an array that contains the union: each distinct element from all of // Produce an array that contains the union: each distinct element from all of
// the passed-in arrays. // the passed-in arrays.
_.union = function() { _.union = function() {
return _.uniq(concat.apply(ArrayProto, arguments)); return _.uniq(_.flatten(arguments, true));
}; };
// Produce an array that contains every item shared between all the // Produce an array that contains every item shared between all the
@ -504,7 +532,7 @@ module.exports = {
var rest = slice.call(arguments, 1); var rest = slice.call(arguments, 1);
return _.filter(_.uniq(array), function(item) { return _.filter(_.uniq(array), function(item) {
return _.every(rest, function(other) { return _.every(rest, function(other) {
return _.indexOf(other, item) >= 0; return _.contains(other, item);
}); });
}); });
}; };
@ -519,11 +547,10 @@ module.exports = {
// Zip together multiple lists into a single array -- elements that share // Zip together multiple lists into a single array -- elements that share
// an index go together. // an index go together.
_.zip = function() { _.zip = function() {
var args = slice.call(arguments); var length = _.max(_.pluck(arguments, 'length').concat(0));
var length = _.max(_.pluck(args, 'length'));
var results = new Array(length); var results = new Array(length);
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
results[i] = _.pluck(args, "" + i); results[i] = _.pluck(arguments, '' + i);
} }
return results; return results;
}; };
@ -534,7 +561,7 @@ module.exports = {
_.object = function(list, values) { _.object = function(list, values) {
if (list == null) return {}; if (list == null) return {};
var result = {}; var result = {};
for (var i = 0, l = list.length; i < l; i++) { for (var i = 0, length = list.length; i < length; i++) {
if (values) { if (values) {
result[list[i]] = values[i]; result[list[i]] = values[i];
} else { } else {
@ -552,17 +579,17 @@ module.exports = {
// for **isSorted** to use binary search. // for **isSorted** to use binary search.
_.indexOf = function(array, item, isSorted) { _.indexOf = function(array, item, isSorted) {
if (array == null) return -1; if (array == null) return -1;
var i = 0, l = array.length; var i = 0, length = array.length;
if (isSorted) { if (isSorted) {
if (typeof isSorted == 'number') { if (typeof isSorted == 'number') {
i = (isSorted < 0 ? Math.max(0, l + isSorted) : isSorted); i = (isSorted < 0 ? Math.max(0, length + isSorted) : isSorted);
} else { } else {
i = _.sortedIndex(array, item); i = _.sortedIndex(array, item);
return array[i] === item ? i : -1; return array[i] === item ? i : -1;
} }
} }
if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted); if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);
for (; i < l; i++) if (array[i] === item) return i; for (; i < length; i++) if (array[i] === item) return i;
return -1; return -1;
}; };
@ -588,11 +615,11 @@ module.exports = {
} }
step = arguments[2] || 1; step = arguments[2] || 1;
var len = Math.max(Math.ceil((stop - start) / step), 0); var length = Math.max(Math.ceil((stop - start) / step), 0);
var idx = 0; var idx = 0;
var range = new Array(len); var range = new Array(length);
while(idx < len) { while(idx < length) {
range[idx++] = start; range[idx++] = start;
start += step; start += step;
} }
@ -603,31 +630,50 @@ module.exports = {
// Function (ahem) Functions // Function (ahem) Functions
// ------------------ // ------------------
// Reusable constructor function for prototype setting.
var ctor = function(){};
// Create a function bound to a given object (assigning `this`, and arguments, // Create a function bound to a given object (assigning `this`, and arguments,
// optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
// available. // available.
_.bind = function(func, context) { _.bind = function(func, context) {
if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1)); var args, bound;
var args = slice.call(arguments, 2); if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
return function() { if (!_.isFunction(func)) throw new TypeError;
return func.apply(context, args.concat(slice.call(arguments))); args = slice.call(arguments, 2);
return bound = function() {
if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));
ctor.prototype = func.prototype;
var self = new ctor;
ctor.prototype = null;
var result = func.apply(self, args.concat(slice.call(arguments)));
if (Object(result) === result) return result;
return self;
}; };
}; };
// Partially apply a function by creating a version that has had some of its // Partially apply a function by creating a version that has had some of its
// arguments pre-filled, without changing its dynamic `this` context. // arguments pre-filled, without changing its dynamic `this` context. _ acts
// as a placeholder, allowing any combination of arguments to be pre-filled.
_.partial = function(func) { _.partial = function(func) {
var args = slice.call(arguments, 1); var boundArgs = slice.call(arguments, 1);
return function() { return function() {
return func.apply(this, args.concat(slice.call(arguments))); var position = 0;
var args = boundArgs.slice();
for (var i = 0, length = args.length; i < length; i++) {
if (args[i] === _) args[i] = arguments[position++];
}
while (position < arguments.length) args.push(arguments[position++]);
return func.apply(this, args);
}; };
}; };
// Bind all of an object's methods to that object. Useful for ensuring that // Bind a number of an object's methods to that object. Remaining arguments
// all callbacks defined on an object belong to it. // are the method names to be bound. Useful for ensuring that all callbacks
// defined on an object belong to it.
_.bindAll = function(obj) { _.bindAll = function(obj) {
var funcs = slice.call(arguments, 1); var funcs = slice.call(arguments, 1);
if (funcs.length === 0) funcs = _.functions(obj); if (funcs.length === 0) throw new Error('bindAll must be passed function names');
each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); }); each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
return obj; return obj;
}; };
@ -656,17 +702,24 @@ module.exports = {
}; };
// Returns a function, that, when invoked, will only be triggered at most once // Returns a function, that, when invoked, will only be triggered at most once
// during a given window of time. // during a given window of time. Normally, the throttled function will run
_.throttle = function(func, wait) { // as much as it can, without ever going more than once per `wait` duration;
var context, args, timeout, result; // but if you'd like to disable the execution on the leading edge, pass
// `{leading: false}`. To disable execution on the trailing edge, ditto.
_.throttle = function(func, wait, options) {
var context, args, result;
var timeout = null;
var previous = 0; var previous = 0;
options || (options = {});
var later = function() { var later = function() {
previous = new Date; previous = options.leading === false ? 0 : _.now();
timeout = null; timeout = null;
result = func.apply(context, args); result = func.apply(context, args);
context = args = null;
}; };
return function() { return function() {
var now = new Date; var now = _.now();
if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous); var remaining = wait - (now - previous);
context = this; context = this;
args = arguments; args = arguments;
@ -675,7 +728,8 @@ module.exports = {
timeout = null; timeout = null;
previous = now; previous = now;
result = func.apply(context, args); result = func.apply(context, args);
} else if (!timeout) { context = args = null;
} else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining); timeout = setTimeout(later, remaining);
} }
return result; return result;
@ -687,17 +741,34 @@ module.exports = {
// N milliseconds. If `immediate` is passed, trigger the function on the // N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing. // leading edge, instead of the trailing.
_.debounce = function(func, wait, immediate) { _.debounce = function(func, wait, immediate) {
var timeout, result; var timeout, args, context, timestamp, result;
return function() {
var context = this, args = arguments;
var later = function() { var later = function() {
var last = _.now() - timestamp;
if (last < wait) {
timeout = setTimeout(later, wait - last);
} else {
timeout = null; timeout = null;
if (!immediate) result = func.apply(context, args); if (!immediate) {
result = func.apply(context, args);
context = args = null;
}
}
}; };
return function() {
context = this;
args = arguments;
timestamp = _.now();
var callNow = immediate && !timeout; var callNow = immediate && !timeout;
clearTimeout(timeout); if (!timeout) {
timeout = setTimeout(later, wait); timeout = setTimeout(later, wait);
if (callNow) result = func.apply(context, args); }
if (callNow) {
result = func.apply(context, args);
context = args = null;
}
return result; return result;
}; };
}; };
@ -719,11 +790,7 @@ module.exports = {
// allowing you to adjust arguments, run code before and after, and // allowing you to adjust arguments, run code before and after, and
// conditionally execute the original function. // conditionally execute the original function.
_.wrap = function(func, wrapper) { _.wrap = function(func, wrapper) {
return function() { return _.partial(wrapper, func);
var args = [func];
push.apply(args, arguments);
return wrapper.apply(this, args);
};
}; };
// Returns a function that is the composition of a list of functions, each // Returns a function that is the composition of a list of functions, each
@ -741,7 +808,6 @@ module.exports = {
// Returns a function that will only be executed after being called N times. // Returns a function that will only be executed after being called N times.
_.after = function(times, func) { _.after = function(times, func) {
if (times <= 0) return func();
return function() { return function() {
if (--times < 1) { if (--times < 1) {
return func.apply(this, arguments); return func.apply(this, arguments);
@ -754,31 +820,43 @@ module.exports = {
// Retrieve the names of an object's properties. // Retrieve the names of an object's properties.
// Delegates to **ECMAScript 5**'s native `Object.keys` // Delegates to **ECMAScript 5**'s native `Object.keys`
_.keys = nativeKeys || function(obj) { _.keys = function(obj) {
if (obj !== Object(obj)) throw new TypeError('Invalid object'); if (!_.isObject(obj)) return [];
if (nativeKeys) return nativeKeys(obj);
var keys = []; var keys = [];
for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key; for (var key in obj) if (_.has(obj, key)) keys.push(key);
return keys; return keys;
}; };
// Retrieve the values of an object's properties. // Retrieve the values of an object's properties.
_.values = function(obj) { _.values = function(obj) {
var values = []; var keys = _.keys(obj);
for (var key in obj) if (_.has(obj, key)) values.push(obj[key]); var length = keys.length;
var values = new Array(length);
for (var i = 0; i < length; i++) {
values[i] = obj[keys[i]];
}
return values; return values;
}; };
// Convert an object into a list of `[key, value]` pairs. // Convert an object into a list of `[key, value]` pairs.
_.pairs = function(obj) { _.pairs = function(obj) {
var pairs = []; var keys = _.keys(obj);
for (var key in obj) if (_.has(obj, key)) pairs.push([key, obj[key]]); var length = keys.length;
var pairs = new Array(length);
for (var i = 0; i < length; i++) {
pairs[i] = [keys[i], obj[keys[i]]];
}
return pairs; return pairs;
}; };
// Invert the keys and values of an object. The values must be serializable. // Invert the keys and values of an object. The values must be serializable.
_.invert = function(obj) { _.invert = function(obj) {
var result = {}; var result = {};
for (var key in obj) if (_.has(obj, key)) result[obj[key]] = key; var keys = _.keys(obj);
for (var i = 0, length = keys.length; i < length; i++) {
result[obj[keys[i]]] = keys[i];
}
return result; return result;
}; };
@ -829,7 +907,7 @@ module.exports = {
each(slice.call(arguments, 1), function(source) { each(slice.call(arguments, 1), function(source) {
if (source) { if (source) {
for (var prop in source) { for (var prop in source) {
if (obj[prop] == null) obj[prop] = source[prop]; if (obj[prop] === void 0) obj[prop] = source[prop];
} }
} }
}); });
@ -853,7 +931,7 @@ module.exports = {
// Internal recursive comparison function for `isEqual`. // Internal recursive comparison function for `isEqual`.
var eq = function(a, b, aStack, bStack) { var eq = function(a, b, aStack, bStack) {
// Identical objects are equal. `0 === -0`, but they aren't identical. // Identical objects are equal. `0 === -0`, but they aren't identical.
// See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal. // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
if (a === b) return a !== 0 || 1 / a == 1 / b; if (a === b) return a !== 0 || 1 / a == 1 / b;
// A strict comparison is necessary because `null == undefined`. // A strict comparison is necessary because `null == undefined`.
if (a == null || b == null) return a === b; if (a == null || b == null) return a === b;
@ -895,6 +973,14 @@ module.exports = {
// unique nested structures. // unique nested structures.
if (aStack[length] == a) return bStack[length] == b; if (aStack[length] == a) return bStack[length] == b;
} }
// Objects with different constructors are not equivalent, but `Object`s
// from different frames are.
var aCtor = a.constructor, bCtor = b.constructor;
if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
_.isFunction(bCtor) && (bCtor instanceof bCtor))
&& ('constructor' in a && 'constructor' in b)) {
return false;
}
// Add the first object to the stack of traversed objects. // Add the first object to the stack of traversed objects.
aStack.push(a); aStack.push(a);
bStack.push(b); bStack.push(b);
@ -911,13 +997,6 @@ module.exports = {
} }
} }
} else { } else {
// Objects with different constructors are not equivalent, but `Object`s
// from different frames are.
var aCtor = a.constructor, bCtor = b.constructor;
if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
_.isFunction(bCtor) && (bCtor instanceof bCtor))) {
return false;
}
// Deep compare objects. // Deep compare objects.
for (var key in a) { for (var key in a) {
if (_.has(a, key)) { if (_.has(a, key)) {
@ -1039,9 +1118,33 @@ module.exports = {
return value; return value;
}; };
_.constant = function(value) {
return function () {
return value;
};
};
_.property = function(key) {
return function(obj) {
return obj[key];
};
};
// Returns a predicate for checking whether an object has a given set of `key:value` pairs.
_.matches = function(attrs) {
return function(obj) {
if (obj === attrs) return true; //avoid comparing an object to itself.
for (var key in attrs) {
if (attrs[key] !== obj[key])
return false;
}
return true;
}
};
// Run a function **n** times. // Run a function **n** times.
_.times = function(n, iterator, context) { _.times = function(n, iterator, context) {
var accum = Array(n); var accum = Array(Math.max(0, n));
for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i); for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i);
return accum; return accum;
}; };
@ -1055,6 +1158,9 @@ module.exports = {
return min + Math.floor(Math.random() * (max - min + 1)); return min + Math.floor(Math.random() * (max - min + 1));
}; };
// A (possibly faster) way to get the current timestamp as an integer.
_.now = Date.now || function() { return new Date().getTime(); };
// List of HTML entities for escaping. // List of HTML entities for escaping.
var entityMap = { var entityMap = {
escape: { escape: {
@ -1062,8 +1168,7 @@ module.exports = {
'<': '&lt;', '<': '&lt;',
'>': '&gt;', '>': '&gt;',
'"': '&quot;', '"': '&quot;',
"'": '&#x27;', "'": '&#x27;'
'/': '&#x2F;'
} }
}; };
entityMap.unescape = _.invert(entityMap.escape); entityMap.unescape = _.invert(entityMap.escape);
@ -1084,10 +1189,10 @@ module.exports = {
}; };
}); });
// If the value of the named property is a function then invoke it; // If the value of the named `property` is a function then invoke it with the
// otherwise, return it. // `object` as context; otherwise, return it.
_.result = function(object, property) { _.result = function(object, property) {
if (object == null) return null; if (object == null) return void 0;
var value = object[property]; var value = object[property];
return _.isFunction(value) ? value.call(object) : value; return _.isFunction(value) ? value.call(object) : value;
}; };
@ -1252,6 +1357,18 @@ module.exports = {
}); });
// AMD registration happens at the end for compatibility with AMD loaders
// that may not enforce next-turn semantics on modules. Even though general
// practice for AMD registration is to be anonymous, underscore registers
// as a named module because, like jQuery, it is a base library that is
// popular enough to be bundled in a third party lib, but not be part of
// an AMD load request. Those cases could generate an error when an
// anonymous define() is called outside of a loader request.
if (typeof define === 'function' && define.amd) {
define('underscore', [], function() {
return _;
});
}
}).call(this); }).call(this);
}, },
@ -1353,6 +1470,7 @@ var JSHINT = (function () {
globalstrict: true, // if global "use strict"; should be allowed (also enables 'strict') globalstrict: true, // if global "use strict"; should be allowed (also enables 'strict')
immed : true, // if immediate invocations must be wrapped in parens immed : true, // if immediate invocations must be wrapped in parens
iterator : true, // if the `__iterator__` property should be allowed iterator : true, // if the `__iterator__` property should be allowed
jasmine : true, // Jasmine functions should be predefined
jquery : true, // if jQuery globals should be predefined jquery : true, // if jQuery globals should be predefined
lastsemic : true, // if semicolons may be ommitted for the trailing lastsemic : true, // if semicolons may be ommitted for the trailing
// statements inside of a one-line blocks. // statements inside of a one-line blocks.
@ -1378,6 +1496,7 @@ var JSHINT = (function () {
proto : true, // if the `__proto__` property should be allowed proto : true, // if the `__proto__` property should be allowed
prototypejs : true, // if Prototype and Scriptaculous globals should be prototypejs : true, // if Prototype and Scriptaculous globals should be
// predefined // predefined
qunit : true, // if the QUnit environment globals should be predefined
rhino : true, // if the Rhino environment globals should be predefined rhino : true, // if the Rhino environment globals should be predefined
shelljs : true, // if ShellJS globals should be predefined shelljs : true, // if ShellJS globals should be predefined
typed : true, // if typed array globals should be predefined typed : true, // if typed array globals should be predefined
@ -1570,7 +1689,7 @@ var JSHINT = (function () {
function combine(dest, src) { function combine(dest, src) {
Object.keys(src).forEach(function (name) { Object.keys(src).forEach(function (name) {
if (JSHINT.blacklist.hasOwnProperty(name)) return; if (_.has(JSHINT.blacklist, name)) return;
dest[name] = src[name]; dest[name] = src[name];
}); });
} }
@ -1584,6 +1703,10 @@ var JSHINT = (function () {
combine(predefined, vars.couch); combine(predefined, vars.couch);
} }
if (state.option.qunit) {
combine(predefined, vars.qunit);
}
if (state.option.rhino) { if (state.option.rhino) {
combine(predefined, vars.rhino); combine(predefined, vars.rhino);
} }
@ -1626,6 +1749,10 @@ var JSHINT = (function () {
combine(predefined, vars.nonstandard); combine(predefined, vars.nonstandard);
} }
if (state.option.jasmine) {
combine(predefined, vars.jasmine);
}
if (state.option.jquery) { if (state.option.jquery) {
combine(predefined, vars.jquery); combine(predefined, vars.jquery);
} }
@ -2208,11 +2335,13 @@ var JSHINT = (function () {
if (state.tokens.next.id === "(end)") if (state.tokens.next.id === "(end)")
error("E006", state.tokens.curr); error("E006", state.tokens.curr);
if (state.option.asi && var isDangerous =
(state.tokens.curr.id === "[" || state.option.asi &&
state.tokens.curr.id === "(" || state.tokens.prev.line < state.tokens.curr.line &&
state.tokens.curr.id === "/") && _.contains(["]", ")"], state.tokens.prev.id) &&
state.tokens.prev.line < state.tokens.curr.line) _.contains(["[", "("], state.tokens.curr.id);
if (isDangerous)
warning("W014", state.tokens.curr, state.tokens.curr.id); warning("W014", state.tokens.curr, state.tokens.curr.id);
advance(); advance();
@ -2792,6 +2921,21 @@ var JSHINT = (function () {
} }
} }
function parseFinalSemicolon() {
if (state.tokens.next.id !== ";") {
if (!state.option.asi) {
// If this is the last statement in a block that ends on
// the same line *and* option lastsemic is on, ignore the warning.
// Otherwise, complain about missing semicolon.
if (!state.option.lastsemic || state.tokens.next.id !== "}" ||
state.tokens.next.line !== state.tokens.curr.line) {
warningAt("W033", state.tokens.curr.line, state.tokens.curr.character);
}
}
} else {
advance(";");
}
}
function statement() { function statement() {
var values; var values;
@ -2814,6 +2958,23 @@ var JSHINT = (function () {
res = false; res = false;
} }
// detect a module import declaration
if (t.value === "module" && t.type === "(identifier)") {
if (peek().type === "(identifier)") {
if (!state.option.inESNext()) {
warning("W119", state.tokens.curr, "module");
}
advance("module");
var name = identifier();
addlabel(name, { type: "unused", token: state.tokens.curr });
advance("from");
advance("(string)");
parseFinalSemicolon();
return;
}
}
// detect a destructuring assignment // detect a destructuring assignment
if (_.has(["[", "{"], t.value)) { if (_.has(["[", "{"], t.value)) {
if (lookupBlockType().isDestAssign) { if (lookupBlockType().isDestAssign) {
@ -2879,21 +3040,9 @@ var JSHINT = (function () {
} else if (state.option.nonew && r && r.left && r.id === "(" && r.left.id === "new") { } else if (state.option.nonew && r && r.left && r.id === "(" && r.left.id === "new") {
warning("W031", t); warning("W031", t);
} }
parseFinalSemicolon();
}
if (state.tokens.next.id !== ";") {
if (!state.option.asi) {
// If this is the last statement in a block that ends on
// the same line *and* option lastsemic is on, ignore the warning.
// Otherwise, complain about missing semicolon.
if (!state.option.lastsemic || state.tokens.next.id !== "}" ||
state.tokens.next.line !== state.tokens.curr.line) {
warningAt("W033", state.tokens.curr.line, state.tokens.curr.character);
}
}
} else {
advance(";");
}
}
// Restore the indentation. // Restore the indentation.
@ -5432,7 +5581,6 @@ var JSHINT = (function () {
FutureReservedWord("static", { es5: true, strictOnly: true }); FutureReservedWord("static", { es5: true, strictOnly: true });
FutureReservedWord("super", { es5: true }); FutureReservedWord("super", { es5: true });
FutureReservedWord("synchronized"); FutureReservedWord("synchronized");
FutureReservedWord("throws");
FutureReservedWord("transient"); FutureReservedWord("transient");
FutureReservedWord("volatile"); FutureReservedWord("volatile");
@ -8150,7 +8298,7 @@ exports.starSlash = /\*\//;
exports.identifier = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/; exports.identifier = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/;
// JavaScript URL (jx) // JavaScript URL (jx)
exports.javascriptURL = /^(?:javascript|jscript|ecmascript|vbscript|mocha|livescript)\s*:/i; exports.javascriptURL = /^(?:javascript|jscript|ecmascript|vbscript|livescript)\s*:/i;
// Catches /* falls through */ comments (ft) // Catches /* falls through */ comments (ft)
exports.fallsThrough = /^\s*\/\*\s*falls?\sthrough\s*\*\/\s*$/; exports.fallsThrough = /^\s*\/\*\s*falls?\sthrough\s*\*\/\s*$/;
@ -8323,7 +8471,7 @@ exports.register = function (linter) {
// Warn about script URLs. // Warn about script URLs.
linter.on("String", function style_scanJavaScriptURLs(data) { linter.on("String", function style_scanJavaScriptURLs(data) {
var re = /^(?:javascript|jscript|ecmascript|vbscript|mocha|livescript)\s*:/i; var re = /^(?:javascript|jscript|ecmascript|vbscript|livescript)\s*:/i;
if (linter.getOption("scripturl")) { if (linter.getOption("scripturl")) {
return; return;
@ -8756,6 +8904,27 @@ exports.phantom = {
exports : true // v1.7+ exports : true // v1.7+
}; };
exports.qunit = {
asyncTest : false,
deepEqual : false,
equal : false,
expect : false,
module : false,
notDeepEqual : false,
notEqual : false,
notPropEqual : false,
notStrictEqual : false,
ok : false,
propEqual : false,
QUnit : false,
raises : false,
start : false,
stop : false,
strictEqual : false,
test : false,
"throws" : false
};
exports.rhino = { exports.rhino = {
defineClass : false, defineClass : false,
deserialize : false, deserialize : false,
@ -8875,7 +9044,7 @@ exports.mootools = {
Group : false, Group : false,
Hash : false, Hash : false,
HtmlTable : false, HtmlTable : false,
Iframe : false, IFrame : false,
IframeShim : false, IframeShim : false,
InputValidator: false, InputValidator: false,
instanceOf : false, instanceOf : false,
@ -8962,6 +9131,23 @@ exports.mocha = {
teardown : false teardown : false
}; };
exports.jasmine = {
jasmine : false,
describe : false,
it : false,
xit : false,
beforeEach : false,
afterEach : false,
setFixtures : false,
loadFixtures: false,
spyOn : false,
expect : false,
// Jasmine 1.3
runs : false,
waitsFor : false,
waits : false
};
}, },
{}], {}],
10:[function(_dereq_,module,exports){ 10:[function(_dereq_,module,exports){

View file

@ -717,34 +717,52 @@ PHP.Lexer = function( src, ini ) {
var re; var re;
if ( curlyOpen > 0) { if ( curlyOpen > 0) {
re = /^([^\\\$"{}\]\)]|\\.)+/g; re = /^([^\\\$"{}\]\(\)\->]|\\.)+/g;
} else { } else {
re = /^([^\\\$"{]|\\.|{[^\$]|\$(?=[^a-zA-Z_\x7f-\uffff]))+/g;; re = /^([^\\\$"{]|\\.|{[^\$]|\$(?=[^a-zA-Z_\x7f-\uffff]))+/g;;
} }
var type, match2;
while(( match = result.match( re )) !== null ) { while(( match = result.match( re )) !== null ) {
if (result.length === 1) { if (result.length === 1) {
throw new Error(match); throw new Error(match);
} }
type = 0;
if( curlyOpen > 0 ){
if( match2 = match[0].match(/^[\[\]\;\:\?\(\)\!\.\,\>\<\=\+\-\/\*\|\&\{\}\@\^\%\$\~]/) ){
results.push(match2[0]);
}else{
type = PHP.Constants.T_STRING;
}
}else{
type = PHP.Constants.T_ENCAPSED_AND_WHITESPACE;
}
if( type ){
results.push([ results.push([
parseInt(( curlyOpen > 0 ) ? PHP.Constants.T_CONSTANT_ENCAPSED_STRING : PHP.Constants.T_ENCAPSED_AND_WHITESPACE, 10), parseInt(type, 10),
match[ 0 ].replace(/\n/g,"\\n").replace(/\r/g,""), match[ 0 ].replace(/\n/g,"\\n").replace(/\r/g,""),
line line
]); ]);
}
line += match[ 0 ].split('\n').length - 1; line += match[ 0 ].split('\n').length - 1;
result = result.substring( match[ 0 ].length ); result = result.substring( match[ 0 ].length );
}
if( curlyOpen > 0 && result.match(/^\->/) !== null ) {
results.push([
parseInt(PHP.Constants.T_OBJECT_OPERATOR, 10),
'->',
line
]);
result = result.substring( 2 );
} }
if( result.match(/^{\$/) !== null ) { if( result.match(/^{\$/) !== null ) {
results.push([ results.push([
parseInt(PHP.Constants.T_CURLY_OPEN, 10), parseInt(PHP.Constants.T_CURLY_OPEN, 10),
"{", "{",

View file

@ -74,14 +74,21 @@ oop.inherits(Mode, TextMode);
}; };
this.checkOutdent = function(state, line, input) { this.checkOutdent = function(state, line, input) {
return /^\s+end$/.test(line + input) || /^\s+}$/.test(line + input) || /^\s+else$/.test(line + input); return /^\s+(end|else)$/.test(line + input) || this.$outdent.checkOutdent(line, input);
}; };
this.autoOutdent = function(state, doc, row) { this.autoOutdent = function(state, session, row) {
var indent = this.$getIndent(doc.getLine(row)); var line = session.getLine(row);
var tab = doc.getTabString(); if (/}/.test(line))
return this.$outdent.autoOutdent(session, row);
var indent = this.$getIndent(line);
var prevLine = session.getLine(row - 1);
var prevIndent = this.$getIndent(prevLine);
var tab = session.getTabString();
if (prevIndent.length <= indent.length) {
if (indent.slice(-tab.length) == tab) if (indent.slice(-tab.length) == tab)
doc.remove(new Range(row, indent.length-tab.length, row, indent.length)); session.remove(new Range(row, indent.length-tab.length, row, indent.length));
}
}; };
this.$id = "ace/mode/ruby"; this.$id = "ace/mode/ruby";

View file

@ -62,7 +62,7 @@ var Mode = function() {
this.getTokenizer = function() { this.getTokenizer = function() {
if (!this.$tokenizer) { if (!this.$tokenizer) {
this.$highlightRules = new this.HighlightRules(); this.$highlightRules = this.$highlightRules || new this.HighlightRules();
this.$tokenizer = new Tokenizer(this.$highlightRules.getRules()); this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
} }
return this.$tokenizer; return this.$tokenizer;

105
lib/ace/mode/vala.js Normal file
View file

@ -0,0 +1,105 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2012, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
/*
THIS FILE WAS AUTOGENERATED BY mode.tmpl.js
*/
define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer;
var ValaHighlightRules = require("./vala_highlight_rules").ValaHighlightRules;
var FoldMode = require("./folding/cstyle").FoldMode;
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var Mode = function() {
this.HighlightRules = ValaHighlightRules;
this.$outdent = new MatchingBraceOutdent();
this.$behaviour = new CstyleBehaviour();
this.foldingRules = new CStyleFoldMode();
};
oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);
var tokenizedLine = this.getTokenizer().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" || state == "no_regex") {
var match = line.match(/^.*(?:\bcase\b.*\:|[\{\(\[])\s*$/);
if (match) {
indent += tab;
}
} else if (state == "doc-start") {
if (endState == "start" || endState == "no_regex") {
return "";
}
var match = line.match(/^\s*(\/?)\*/);
if (match) {
if (match[1]) {
indent += " ";
}
indent += "* ";
}
}
return indent;
};
this.checkOutdent = function(state, line, input) {
return this.$outdent.checkOutdent(line, input);
};
this.autoOutdent = function(state, doc, row) {
this.$outdent.autoOutdent(doc, row);
};
// Extra logic goes here.
this.$id = "ace/mode/vala"
}).call(Mode.prototype);
exports.Mode = Mode;
});

View file

@ -0,0 +1,457 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2012, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
/* This file was autogenerated from https://raw.githubusercontent.com/technosophos/Vala-TMBundle/master/Syntaxes/Vala.tmLanguage (uuid: ) */
/****************************************************************************************
* IT MIGHT NOT BE PERFECT ...But it's a good start from an existing *.tmlanguage file. *
* fileTypes *
****************************************************************************************/
define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var ValaHighlightRules = function() {
// regexp must not have capturing parentheses. Use (?:) instead.
// regexps are ordered -> the first match is used
this.$rules = { start:
[ { token:
[ 'meta.using.vala',
'keyword.other.using.vala',
'meta.using.vala',
'storage.modifier.using.vala',
'meta.using.vala',
'punctuation.terminator.vala' ],
regex: '^(\\s*)(using)\\b(?:(\\s*)([^ ;$]+)(\\s*)((?:;)?))?' },
{ include: '#code' } ],
'#all-types':
[ { include: '#primitive-arrays' },
{ include: '#primitive-types' },
{ include: '#object-types' } ],
'#annotations':
[ { token:
[ 'storage.type.annotation.vala',
'punctuation.definition.annotation-arguments.begin.vala' ],
regex: '(@[^ (]+)(\\()',
push:
[ { token: 'punctuation.definition.annotation-arguments.end.vala',
regex: '\\)',
next: 'pop' },
{ token:
[ 'constant.other.key.vala',
'text',
'keyword.operator.assignment.vala' ],
regex: '(\\w*)(\\s*)(=)' },
{ include: '#code' },
{ token: 'punctuation.seperator.property.vala', regex: ',' },
{ defaultToken: 'meta.declaration.annotation.vala' } ] },
{ token: 'storage.type.annotation.vala', regex: '@\\w*' } ],
'#anonymous-classes-and-new':
[ { token: 'keyword.control.new.vala',
regex: '\\bnew\\b',
push_disabled:
[ { token: 'text',
regex: '(?<=\\)|\\])(?!\\s*{)|(?<=})|(?=;)',
TODO: 'FIXME: regexp doesn\'t have js equivalent',
originalRegex: '(?<=\\)|\\])(?!\\s*{)|(?<=})|(?=;)',
next: 'pop' },
{ token: [ 'storage.type.vala', 'text' ],
regex: '(\\w+)(\\s*)(?=\\[)',
push:
[ { token: 'text', regex: '}|(?=;|\\))', next: 'pop' },
{ token: 'text',
regex: '\\[',
push:
[ { token: 'text', regex: '\\]', next: 'pop' },
{ include: '#code' } ] },
{ token: 'text',
regex: '{',
push:
[ { token: 'text', regex: '(?=})', next: 'pop' },
{ include: '#code' } ] } ] },
{ token: 'text',
regex: '(?=\\w.*\\()',
push:
[ { token: 'text',
regex: '(?<=\\))',
TODO: 'FIXME: regexp doesn\'t have js equivalent',
originalRegex: '(?<=\\))',
next: 'pop' },
{ include: '#object-types' },
{ token: 'text',
regex: '\\(',
push:
[ { token: 'text', regex: '\\)', next: 'pop' },
{ include: '#code' } ] } ] },
{ token: 'meta.inner-class.vala',
regex: '{',
push:
[ { token: 'meta.inner-class.vala', regex: '}', next: 'pop' },
{ include: '#class-body' },
{ defaultToken: 'meta.inner-class.vala' } ] } ] } ],
'#assertions':
[ { token:
[ 'keyword.control.assert.vala',
'meta.declaration.assertion.vala' ],
regex: '\\b(assert|requires|ensures)(\\s)',
push:
[ { token: 'meta.declaration.assertion.vala',
regex: '$',
next: 'pop' },
{ token: 'keyword.operator.assert.expression-seperator.vala',
regex: ':' },
{ include: '#code' },
{ defaultToken: 'meta.declaration.assertion.vala' } ] } ],
'#class':
[ { token: 'meta.class.vala',
regex: '(?=\\w?[\\w\\s]*(?:class|(?:@)?interface|enum|struct|namespace)\\s+\\w+)',
push:
[ { token: 'punctuation.section.class.end.vala',
regex: '}',
next: 'pop' },
{ include: '#storage-modifiers' },
{ include: '#comments' },
{ token:
[ 'storage.modifier.vala',
'meta.class.identifier.vala',
'entity.name.type.class.vala' ],
regex: '(class|(?:@)?interface|enum|struct|namespace)(\\s+)([\\w\\.]+)' },
{ token: 'storage.modifier.extends.vala',
regex: ':',
push:
[ { token: 'meta.definition.class.inherited.classes.vala',
regex: '(?={|,)',
next: 'pop' },
{ include: '#object-types-inherited' },
{ include: '#comments' },
{ defaultToken: 'meta.definition.class.inherited.classes.vala' } ] },
{ token:
[ 'storage.modifier.implements.vala',
'meta.definition.class.implemented.interfaces.vala' ],
regex: '(,)(\\s)',
push:
[ { token: 'meta.definition.class.implemented.interfaces.vala',
regex: '(?=\\{)',
next: 'pop' },
{ include: '#object-types-inherited' },
{ include: '#comments' },
{ defaultToken: 'meta.definition.class.implemented.interfaces.vala' } ] },
{ token: 'meta.class.body.vala',
regex: '{',
push:
[ { token: 'meta.class.body.vala', regex: '(?=})', next: 'pop' },
{ include: '#class-body' },
{ defaultToken: 'meta.class.body.vala' } ] },
{ defaultToken: 'meta.class.vala' } ],
comment: 'attempting to put namespace in here.' } ],
'#class-body':
[ { include: '#comments' },
{ include: '#class' },
{ include: '#enums' },
{ include: '#methods' },
{ include: '#annotations' },
{ include: '#storage-modifiers' },
{ include: '#code' } ],
'#code':
[ { include: '#comments' },
{ include: '#class' },
{ token: 'text',
regex: '{',
push:
[ { token: 'text', regex: '}', next: 'pop' },
{ include: '#code' } ] },
{ include: '#assertions' },
{ include: '#parens' },
{ include: '#constants-and-special-vars' },
{ include: '#anonymous-classes-and-new' },
{ include: '#keywords' },
{ include: '#storage-modifiers' },
{ include: '#strings' },
{ include: '#all-types' } ],
'#comments':
[ { token: 'punctuation.definition.comment.vala',
regex: '/\\*\\*/' },
{ include: 'text.html.javadoc' },
{ include: '#comments-inline' } ],
'#comments-inline':
[ { token: 'punctuation.definition.comment.vala',
regex: '/\\*',
push:
[ { token: 'punctuation.definition.comment.vala',
regex: '\\*/',
next: 'pop' },
{ defaultToken: 'comment.block.vala' } ] },
{ token:
[ 'text',
'punctuation.definition.comment.vala',
'comment.line.double-slash.vala' ],
regex: '(\\s*)(//)(.*$)' } ],
'#constants-and-special-vars':
[ { token: 'constant.language.vala',
regex: '\\b(?:true|false|null)\\b' },
{ token: 'variable.language.vala',
regex: '\\b(?:this|base)\\b' },
{ token: 'constant.numeric.vala',
regex: '\\b(?:0(?:x|X)[0-9a-fA-F]*|(?:[0-9]+\\.?[0-9]*|\\.[0-9]+)(?:(?:e|E)(?:\\+|-)?[0-9]+)?)(?:[LlFfUuDd]|UL|ul)?\\b' },
{ token: [ 'keyword.operator.dereference.vala', 'constant.other.vala' ],
regex: '((?:\\.)?)\\b([A-Z][A-Z0-9_]+)(?!<|\\.class|\\s*\\w+\\s*=)\\b' } ],
'#enums':
[ { token: 'text',
regex: '^(?=\\s*[A-Z0-9_]+\\s*(?:{|\\(|,))',
push:
[ { token: 'text', regex: '(?=;|})', next: 'pop' },
{ token: 'constant.other.enum.vala',
regex: '\\w+',
push:
[ { token: 'meta.enum.vala', regex: '(?=,|;|})', next: 'pop' },
{ include: '#parens' },
{ token: 'text',
regex: '{',
push:
[ { token: 'text', regex: '}', next: 'pop' },
{ include: '#class-body' } ] },
{ defaultToken: 'meta.enum.vala' } ] } ] } ],
'#keywords':
[ { token: 'keyword.control.catch-exception.vala',
regex: '\\b(?:try|catch|finally|throw)\\b' },
{ token: 'keyword.control.vala', regex: '\\?|:|\\?\\?' },
{ token: 'keyword.control.vala',
regex: '\\b(?:return|break|case|continue|default|do|while|for|foreach|switch|if|else|in|yield|get|set|value)\\b' },
{ token: 'keyword.operator.vala',
regex: '\\b(?:typeof|is|as)\\b' },
{ token: 'keyword.operator.comparison.vala',
regex: '==|!=|<=|>=|<>|<|>' },
{ token: 'keyword.operator.assignment.vala', regex: '=' },
{ token: 'keyword.operator.increment-decrement.vala',
regex: '\\-\\-|\\+\\+' },
{ token: 'keyword.operator.arithmetic.vala',
regex: '\\-|\\+|\\*|\\/|%' },
{ token: 'keyword.operator.logical.vala', regex: '!|&&|\\|\\|' },
{ token: 'keyword.operator.dereference.vala',
regex: '\\.(?=\\S)',
originalRegex: '(?<=\\S)\\.(?=\\S)' },
{ token: 'punctuation.terminator.vala', regex: ';' },
{ token: 'keyword.operator.ownership', regex: 'owned|unowned' } ],
'#methods':
[ { token: 'meta.method.vala',
regex: '(?!new)(?=\\w.*\\s+)(?=[^=]+\\()',
push:
[ { token: 'meta.method.vala', regex: '}|(?=;)', next: 'pop' },
{ include: '#storage-modifiers' },
{ token: [ 'entity.name.function.vala', 'meta.method.identifier.vala' ],
regex: '([\\~\\w\\.]+)(\\s*\\()',
push:
[ { token: 'meta.method.identifier.vala',
regex: '\\)',
next: 'pop' },
{ include: '#parameters' },
{ defaultToken: 'meta.method.identifier.vala' } ] },
{ token: 'meta.method.return-type.vala',
regex: '(?=\\w.*\\s+\\w+\\s*\\()',
push:
[ { token: 'meta.method.return-type.vala',
regex: '(?=\\w+\\s*\\()',
next: 'pop' },
{ include: '#all-types' },
{ defaultToken: 'meta.method.return-type.vala' } ] },
{ include: '#throws' },
{ token: 'meta.method.body.vala',
regex: '{',
push:
[ { token: 'meta.method.body.vala', regex: '(?=})', next: 'pop' },
{ include: '#code' },
{ defaultToken: 'meta.method.body.vala' } ] },
{ defaultToken: 'meta.method.vala' } ] } ],
'#namespace':
[ { token: 'text',
regex: '^(?=\\s*[A-Z0-9_]+\\s*(?:{|\\(|,))',
push:
[ { token: 'text', regex: '(?=;|})', next: 'pop' },
{ token: 'constant.other.namespace.vala',
regex: '\\w+',
push:
[ { token: 'meta.namespace.vala', regex: '(?=,|;|})', next: 'pop' },
{ include: '#parens' },
{ token: 'text',
regex: '{',
push:
[ { token: 'text', regex: '}', next: 'pop' },
{ include: '#code' } ] },
{ defaultToken: 'meta.namespace.vala' } ] } ],
comment: 'This is not quite right. See the class grammar right now' } ],
'#object-types':
[ { token: 'storage.type.generic.vala',
regex: '\\b(?:[a-z]\\w*\\.)*[A-Z]+\\w*<',
push:
[ { token: 'storage.type.generic.vala',
regex: '>|[^\\w\\s,\\?<\\[()\\]]',
TODO: 'FIXME: regexp doesn\'t have js equivalent',
originalRegex: '>|[^\\w\\s,\\?<\\[(?:[,]+)\\]]',
next: 'pop' },
{ include: '#object-types' },
{ token: 'storage.type.generic.vala',
regex: '<',
push:
[ { token: 'storage.type.generic.vala',
regex: '>|[^\\w\\s,\\[\\]<]',
next: 'pop' },
{ defaultToken: 'storage.type.generic.vala' } ],
comment: 'This is just to support <>\'s with no actual type prefix' },
{ defaultToken: 'storage.type.generic.vala' } ] },
{ token: 'storage.type.object.array.vala',
regex: '\\b(?:[a-z]\\w*\\.)*[A-Z]+\\w*(?=\\[)',
push:
[ { token: 'storage.type.object.array.vala',
regex: '(?=[^\\]\\s])',
next: 'pop' },
{ token: 'text',
regex: '\\[',
push:
[ { token: 'text', regex: '\\]', next: 'pop' },
{ include: '#code' } ] },
{ defaultToken: 'storage.type.object.array.vala' } ] },
{ token:
[ 'storage.type.vala',
'keyword.operator.dereference.vala',
'storage.type.vala' ],
regex: '\\b(?:([a-z]\\w*)(\\.))*([A-Z]+\\w*\\b)' } ],
'#object-types-inherited':
[ { token: 'entity.other.inherited-class.vala',
regex: '\\b(?:[a-z]\\w*\\.)*[A-Z]+\\w*<',
push:
[ { token: 'entity.other.inherited-class.vala',
regex: '>|[^\\w\\s,<]',
next: 'pop' },
{ include: '#object-types' },
{ token: 'storage.type.generic.vala',
regex: '<',
push:
[ { token: 'storage.type.generic.vala',
regex: '>|[^\\w\\s,<]',
next: 'pop' },
{ defaultToken: 'storage.type.generic.vala' } ],
comment: 'This is just to support <>\'s with no actual type prefix' },
{ defaultToken: 'entity.other.inherited-class.vala' } ] },
{ token:
[ 'entity.other.inherited-class.vala',
'keyword.operator.dereference.vala',
'entity.other.inherited-class.vala' ],
regex: '\\b(?:([a-z]\\w*)(\\.))*([A-Z]+\\w*)' } ],
'#parameters':
[ { token: 'storage.modifier.vala', regex: 'final' },
{ include: '#primitive-arrays' },
{ include: '#primitive-types' },
{ include: '#object-types' },
{ token: 'variable.parameter.vala', regex: '\\w+' } ],
'#parens':
[ { token: 'text',
regex: '\\(',
push:
[ { token: 'text', regex: '\\)', next: 'pop' },
{ include: '#code' } ] } ],
'#primitive-arrays':
[ { token: 'storage.type.primitive.array.vala',
regex: '\\b(?:bool|byte|sbyte|char|decimal|double|float|int|uint|long|ulong|object|short|ushort|string|void|int8|int16|int32|int64|uint8|uint16|uint32|uint64)(?:\\[\\])*\\b' } ],
'#primitive-types':
[ { token: 'storage.type.primitive.vala',
regex: '\\b(?:var|bool|byte|sbyte|char|decimal|double|float|int|uint|long|ulong|object|short|ushort|string|void|signal|int8|int16|int32|int64|uint8|uint16|uint32|uint64)\\b',
comment: 'var is not really a primitive, but acts like one in most cases' } ],
'#storage-modifiers':
[ { token: 'storage.modifier.vala',
regex: '\\b(?:public|private|protected|internal|static|final|sealed|virtual|override|abstract|readonly|volatile|dynamic|async|unsafe|out|ref|weak|owned|unowned|const)\\b',
comment: 'Not sure about unsafe and readonly' } ],
'#strings':
[ { token: 'punctuation.definition.string.begin.vala',
regex: '@"',
push:
[ { token: 'punctuation.definition.string.end.vala',
regex: '"',
next: 'pop' },
{ token: 'constant.character.escape.vala',
regex: '\\\\.|%[\\w\\.\\-]+|\\$(?:\\w+|\\([\\w\\s\\+\\-\\*\\/]+\\))' },
{ defaultToken: 'string.quoted.interpolated.vala' } ] },
{ token: 'punctuation.definition.string.begin.vala',
regex: '"',
push:
[ { token: 'punctuation.definition.string.end.vala',
regex: '"',
next: 'pop' },
{ token: 'constant.character.escape.vala', regex: '\\\\.' },
{ token: 'constant.character.escape.vala',
regex: '%[\\w\\.\\-]+' },
{ defaultToken: 'string.quoted.double.vala' } ] },
{ token: 'punctuation.definition.string.begin.vala',
regex: '\'',
push:
[ { token: 'punctuation.definition.string.end.vala',
regex: '\'',
next: 'pop' },
{ token: 'constant.character.escape.vala', regex: '\\\\.' },
{ defaultToken: 'string.quoted.single.vala' } ] },
{ token: 'punctuation.definition.string.begin.vala',
regex: '"""',
push:
[ { token: 'punctuation.definition.string.end.vala',
regex: '"""',
next: 'pop' },
{ token: 'constant.character.escape.vala',
regex: '%[\\w\\.\\-]+' },
{ defaultToken: 'string.quoted.triple.vala' } ] } ],
'#throws':
[ { token: 'storage.modifier.vala',
regex: 'throws',
push:
[ { token: 'meta.throwables.vala', regex: '(?={|;)', next: 'pop' },
{ include: '#object-types' },
{ defaultToken: 'meta.throwables.vala' } ] } ],
'#values':
[ { include: '#strings' },
{ include: '#object-types' },
{ include: '#constants-and-special-vars' } ] }
this.normalizeRules();
};
ValaHighlightRules.metaData = {
comment: 'Based heavily on the Java bundle\'s language syntax. TODO:\n* Closures\n* Delegates\n* Properties: Better support for properties.\n* Annotations\n* Error domains\n* Named arguments\n* Array slicing, negative indexes, multidimensional\n* construct blocks\n* lock blocks?\n* regex literals\n* DocBlock syntax highlighting. (Currently importing javadoc)\n* Folding rule for comments.\n',
fileTypes: [ 'vala' ],
foldingStartMarker: '(\\{\\s*(//.*)?$|^\\s*// \\{\\{\\{)',
foldingStopMarker: '^\\s*(\\}|// \\}\\}\\}$)',
name: 'Vala',
scopeName: 'source.vala' }
oop.inherits(ValaHighlightRules, TextHighlightRules);
exports.ValaHighlightRules = ValaHighlightRules;
});

View file

@ -109,12 +109,15 @@ function DefaultHandlers(mouseHandler) {
var editor = this.editor; var editor = this.editor;
// allow double/triple click handlers to change selection // allow double/triple click handlers to change selection
var shiftPressed = this.mousedownEvent.getShiftKey(); var shiftPressed = this.mousedownEvent.getShiftKey();
setTimeout(function(){
if (shiftPressed) { if (shiftPressed) {
editor.selection.selectToPosition(pos); editor.selection.selectToPosition(pos);
} }
else if (!this.$clickSelection) { else if (!this.$clickSelection) {
editor.selection.moveToPosition(pos); editor.selection.moveToPosition(pos);
} }
this.select();
}.bind(this), 0);
if (editor.renderer.scroller.setCapture) { if (editor.renderer.scroller.setCapture) {
editor.renderer.scroller.setCapture(); editor.renderer.scroller.setCapture();
} }
@ -213,7 +216,6 @@ function DefaultHandlers(mouseHandler) {
this.setState("selectByWords"); this.setState("selectByWords");
} }
this.$clickSelection = range; this.$clickSelection = range;
this[this.state] && this[this.state](ev);
}; };
this.onTripleClick = function(ev) { this.onTripleClick = function(ev) {
@ -221,8 +223,13 @@ function DefaultHandlers(mouseHandler) {
var editor = this.editor; var editor = this.editor;
this.setState("selectByLines"); this.setState("selectByLines");
var range = editor.getSelectionRange();
if (range.isMultiLine() && range.contains(pos.row, pos.column)) {
this.$clickSelection = editor.selection.getLineRange(range.start.row);
this.$clickSelection.end = editor.selection.getLineRange(range.end.row).end;
} else {
this.$clickSelection = editor.selection.getLineRange(pos.row); this.$clickSelection = editor.selection.getLineRange(pos.row);
this[this.state] && this[this.state](ev); }
}; };
this.onQuadClick = function(ev) { this.onQuadClick = function(ev) {

View file

@ -40,13 +40,18 @@ var DragdropHandler = require("./dragdrop_handler").DragdropHandler;
var config = require("../config"); var config = require("../config");
var MouseHandler = function(editor) { var MouseHandler = function(editor) {
var _self = this;
this.editor = editor; this.editor = editor;
new DefaultHandlers(this); new DefaultHandlers(this);
new DefaultGutterHandler(this); new DefaultGutterHandler(this);
new DragdropHandler(this); new DragdropHandler(this);
var focusEditor = function(e) { editor.focus() }; var focusEditor = function(e) {
if (!editor.isFocused() && editor.textInput)
editor.textInput.moveToMouse(e);
editor.focus()
};
var mouseTarget = editor.renderer.getMouseEventTarget(); var mouseTarget = editor.renderer.getMouseEventTarget();
event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click")); event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"));
@ -74,6 +79,21 @@ var MouseHandler = function(editor) {
editor.focus(); editor.focus();
return event.preventDefault(e); return event.preventDefault(e);
}); });
editor.on("mousemove", function(e){
if (_self.state || _self.$dragDelay || !_self.$dragEnabled)
return;
var char = editor.renderer.screenToTextCoordinates(e.x, e.y);
var range = editor.session.selection.getRange();
var renderer = editor.renderer;
if (!range.isEmpty() && range.insideStart(char.row, char.column)) {
renderer.setCursorStyle("default");
} else {
renderer.setCursorStyle("");
}
});
}; };
(function() { (function() {
@ -157,11 +177,22 @@ var MouseHandler = function(editor) {
var timerId = setInterval(onCaptureInterval, 20); var timerId = setInterval(onCaptureInterval, 20);
}; };
this.releaseMouse = null; this.releaseMouse = null;
this.cancelContextMenu = function() {
var stop = function(e) {
if (e && e.domEvent && e.domEvent.type != "contextmenu")
return;
this.editor.off("nativecontextmenu", stop);
if (e && e.domEvent)
event.stopEvent(e.domEvent);
}.bind(this);
setTimeout(stop, 10);
this.editor.on("nativecontextmenu", stop);
};
}).call(MouseHandler.prototype); }).call(MouseHandler.prototype);
config.defineOptions(MouseHandler.prototype, "mouseHandler", { config.defineOptions(MouseHandler.prototype, "mouseHandler", {
scrollSpeed: {initialValue: 2}, scrollSpeed: {initialValue: 2},
dragDelay: {initialValue: 150}, dragDelay: {initialValue: (useragent.isMac ? 150 : 0)},
dragEnabled: {initialValue: true}, dragEnabled: {initialValue: true},
focusTimout: {initialValue: 0}, focusTimout: {initialValue: 0},
tooltipFollowsMouse: {initialValue: true} tooltipFollowsMouse: {initialValue: true}

View file

@ -58,15 +58,17 @@ module.exports = {
next(); next();
}, },
"test: double tap. issue #956" : function() { "test: double tap. issue #956" : function(done) {
// mouse up fired immediately after mouse down // mouse up fired immediately after mouse down
var target = this.editor.renderer.getMouseEventTarget(); var target = this.editor.renderer.getMouseEventTarget();
target.dispatchEvent(MouseEvent("down", {x: 1, y: 1})); target.dispatchEvent(MouseEvent("down", {x: 1, y: 1}));
target.dispatchEvent(MouseEvent("up", {x: 1, y: 1})); target.dispatchEvent(MouseEvent("up", {x: 1, y: 1}));
target.dispatchEvent(MouseEvent("down", {x: 1, y: 1, detail: 2})); target.dispatchEvent(MouseEvent("down", {x: 1, y: 1, detail: 2}));
target.dispatchEvent(MouseEvent("up", {x: 1, y: 1, detail: 2})); target.dispatchEvent(MouseEvent("up", {x: 1, y: 1, detail: 2}));
setTimeout(function() {
assert.equal(this.editor.getSelectedText(), "Juhu"); assert.equal(this.editor.getSelectedText(), "Juhu");
done();
}.bind(this));
} }
}; };

View file

@ -31,6 +31,7 @@
define(function(require, exports, module) { define(function(require, exports, module) {
var event = require("../lib/event"); var event = require("../lib/event");
var useragent = require("../lib/useragent");
// mouse // mouse
function isSamePoint(p1, p2) { function isSamePoint(p1, p2) {
@ -41,20 +42,27 @@ function onMouseDown(e) {
var ev = e.domEvent; var ev = e.domEvent;
var alt = ev.altKey; var alt = ev.altKey;
var shift = ev.shiftKey; var shift = ev.shiftKey;
var ctrl = e.getAccelKey(); var ctrl = ev.ctrlKey;
var accel = e.getAccelKey();
var button = e.getButton(); var button = e.getButton();
if (ctrl && useragent.isMac)
button = ev.button;
if (e.editor.inMultiSelectMode && button == 2) { if (e.editor.inMultiSelectMode && button == 2) {
e.editor.textInput.onContextMenu(e.domEvent); e.editor.textInput.onContextMenu(e.domEvent);
return; return;
} }
if (!ctrl && !alt) { if (!ctrl && !alt && !accel) {
if (button === 0 && e.editor.inMultiSelectMode) if (button === 0 && e.editor.inMultiSelectMode)
e.editor.exitMultiSelectMode(); e.editor.exitMultiSelectMode();
return; return;
} }
if (button !== 0)
return;
var editor = e.editor; var editor = e.editor;
var selection = editor.selection; var selection = editor.selection;
var isMultiSelect = editor.inMultiSelectMode; var isMultiSelect = editor.inMultiSelectMode;
@ -62,38 +70,37 @@ function onMouseDown(e) {
var cursor = selection.getCursor(); var cursor = selection.getCursor();
var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor)); var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor));
var mouseX = e.x, mouseY = e.y; var mouseX = e.x, mouseY = e.y;
var onMouseSelection = function(e) { var onMouseSelection = function(e) {
mouseX = e.clientX; mouseX = e.clientX;
mouseY = e.clientY; mouseY = e.clientY;
}; };
var blockSelect = function() {
var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column);
if (isSamePoint(screenCursor, newCursor)
&& isSamePoint(cursor, selection.selectionLead))
return;
screenCursor = newCursor;
editor.selection.moveToPosition(cursor);
editor.renderer.scrollCursorIntoView();
editor.removeSelectionMarkers(rectSel);
rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
rectSel.forEach(editor.addSelectionMarker, editor);
editor.updateSelectionMarkers();
};
var session = editor.session; var session = editor.session;
var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY); var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
var screenCursor = screenAnchor; var screenCursor = screenAnchor;
var selectionMode;
if (editor.$mouseHandler.$enableJumpToDef) {
if (ctrl && alt || accel && alt)
selectionMode = "add";
else if (alt)
selectionMode = "block";
} else {
if (accel && !alt) {
selectionMode = "add";
if (!isMultiSelect && shift)
return;
} else if (alt) {
selectionMode = "block";
}
}
if (selectionMode && useragent.isMac && ev.ctrlKey) {
editor.$mouseHandler.cancelContextMenu();
}
if (ctrl && !alt && !shift && button === 0) { if (selectionMode == "add") {
if (!isMultiSelect && inSelection) if (!isMultiSelect && inSelection)
return; // dragging return; // dragging
@ -104,44 +111,86 @@ function onMouseDown(e) {
var oldRange = selection.rangeList.rangeAtPoint(pos); var oldRange = selection.rangeList.rangeAtPoint(pos);
editor.$blockScrolling++; editor.$blockScrolling++;
editor.inVirtualSelectionMode = true;
if (shift) {
oldRange = null;
range = selection.ranges[0];
editor.removeSelectionMarker(range);
}
editor.once("mouseup", function() { editor.once("mouseup", function() {
var tmpSel = selection.toOrientedRange(); var tmpSel = selection.toOrientedRange();
if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor)) if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor))
selection.substractPoint(tmpSel.cursor); selection.substractPoint(tmpSel.cursor);
else { else {
if (range) { if (shift) {
selection.substractPoint(range.cursor);
} else if (range) {
editor.removeSelectionMarker(range); editor.removeSelectionMarker(range);
selection.addRange(range); selection.addRange(range);
} }
selection.addRange(tmpSel); selection.addRange(tmpSel);
} }
editor.$blockScrolling--; editor.$blockScrolling--;
editor.inVirtualSelectionMode = false;
}); });
} else if (alt && button === 0) { } else if (selectionMode == "block") {
e.stop(); e.stop();
editor.inVirtualSelectionMode = true;
if (isMultiSelect && !ctrl) var initialRange;
selection.toSingleRange();
else if (!isMultiSelect && ctrl)
selection.addRange();
var rectSel = []; var rectSel = [];
if (shift) { var blockSelect = function() {
screenAnchor = session.documentToScreenPosition(selection.lead); var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY);
blockSelect(); var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column);
} else {
selection.moveToPosition(pos); if (isSamePoint(screenCursor, newCursor) && isSamePoint(cursor, selection.lead))
return;
screenCursor = newCursor;
editor.selection.moveToPosition(cursor);
editor.renderer.scrollCursorIntoView();
editor.removeSelectionMarkers(rectSel);
rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor);
if (editor.$mouseHandler.$clickSelection && rectSel.length == 1 && rectSel[0].isEmpty())
rectSel[0] = editor.$mouseHandler.$clickSelection.clone();
rectSel.forEach(editor.addSelectionMarker, editor);
editor.updateSelectionMarkers();
};
if (isMultiSelect && !accel) {
selection.toSingleRange();
} else if (!isMultiSelect && accel) {
initialRange = selection.toOrientedRange();
editor.addSelectionMarker(initialRange);
} }
if (shift)
screenAnchor = session.documentToScreenPosition(selection.lead);
else
selection.moveToPosition(pos);
screenCursor = {row: -1, column: -1};
var onMouseSelectionEnd = function(e) { var onMouseSelectionEnd = function(e) {
clearInterval(timerId); clearInterval(timerId);
editor.removeSelectionMarkers(rectSel); editor.removeSelectionMarkers(rectSel);
if (!rectSel.length)
rectSel = [selection.toOrientedRange()];
editor.$blockScrolling++;
if (initialRange) {
editor.removeSelectionMarker(initialRange);
selection.toSingleRange(initialRange);
}
for (var i = 0; i < rectSel.length; i++) for (var i = 0; i < rectSel.length; i++)
selection.addRange(rectSel[i]); selection.addRange(rectSel[i]);
editor.inVirtualSelectionMode = false;
editor.$mouseHandler.$clickSelection = null;
editor.$blockScrolling--;
}; };
var onSelectionInterval = blockSelect; var onSelectionInterval = blockSelect;

View file

@ -76,7 +76,7 @@ var EditSession = require("./edit_session").EditSession;
if (!range) if (!range)
return; return;
if (!this.inMultiSelectMode && this.rangeCount == 0) { if (!this.inMultiSelectMode && this.rangeCount === 0) {
var oldRange = this.toOrientedRange(); var oldRange = this.toOrientedRange();
this.rangeList.add(oldRange); this.rangeList.add(oldRange);
this.rangeList.add(range); this.rangeList.add(range);
@ -168,7 +168,7 @@ var EditSession = require("./edit_session").EditSession;
this._signal("removeRange", {ranges: removed}); this._signal("removeRange", {ranges: removed});
if (this.rangeCount == 0 && this.inMultiSelectMode) { if (this.rangeCount === 0 && this.inMultiSelectMode) {
this.inMultiSelectMode = false; this.inMultiSelectMode = false;
this._signal("singleSelect"); this._signal("singleSelect");
this.session.$undoSelect = true; this.session.$undoSelect = true;
@ -544,6 +544,19 @@ var Editor = require("./editor").Editor;
return text; return text;
}; };
this.$checkMultiselectChange = function(e, anchor) {
if (this.inMultiSelectMode && !this.inVirtualSelectionMode) {
var range = this.multiSelect.ranges[0];
if (this.multiSelect.isEmpty() && anchor == this.multiSelect.anchor)
return;
var pos = anchor == this.multiSelect.anchor
? range.cursor == range.start ? range.end : range.start
: range.cursor;
if (!isSamePoint(pos, anchor))
this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange());
}
};
// todo this should change when paste becomes a command // todo this should change when paste becomes a command
this.onPaste = function(text) { this.onPaste = function(text) {
if (this.$readOnly) if (this.$readOnly)
@ -742,8 +755,15 @@ var Editor = require("./editor").Editor;
var session = this.session; var session = this.session;
var sel = session.multiSelect; var sel = session.multiSelect;
var ranges = sel.ranges; var ranges = sel.ranges;
// filter out ranges on same row
var row = -1;
var sameRowRanges = ranges.filter(function(r) {
if (r.cursor.row == row)
return true;
row = r.cursor.row;
});
if (!ranges.length) { if (!ranges.length || sameRowRanges.length == ranges.length - 1) {
var range = this.selection.getRange(); var range = this.selection.getRange();
var fr = range.start.row, lr = range.end.row; var fr = range.start.row, lr = range.end.row;
var guessRange = fr == lr; var guessRange = fr == lr;
@ -769,14 +789,9 @@ var Editor = require("./editor").Editor;
} }
this.selection.setRange(range); this.selection.setRange(range);
} else { } else {
// filter out ranges on same row sameRowRanges.forEach(function(r) {
var row = -1; sel.substractPoint(r.cursor);
var sameRowRanges = ranges.filter(function(r) {
if (r.cursor.row == row)
return true;
row = r.cursor.row;
}); });
sel.$onRemoveRange(sameRowRanges);
var maxCol = 0; var maxCol = 0;
var minSpace = Infinity; var minSpace = Infinity;
@ -851,19 +866,19 @@ var Editor = require("./editor").Editor;
function alignLeft(m) { function alignLeft(m) {
return !m[2] ? m[0] : spaces(startW) + m[2] return !m[2] ? m[0] : spaces(startW) + m[2]
+ spaces(textW - m[2].length + endW) + spaces(textW - m[2].length + endW)
+ m[4].replace(/^([=:])\s+/, "$1 ") + m[4].replace(/^([=:])\s+/, "$1 ");
} }
function alignRight(m) { function alignRight(m) {
return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2] return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2]
+ spaces(endW, " ") + spaces(endW, " ")
+ m[4].replace(/^([=:])\s+/, "$1 ") + m[4].replace(/^([=:])\s+/, "$1 ");
} }
function unAlign(m) { function unAlign(m) {
return !m[2] ? m[0] : spaces(startW) + m[2] return !m[2] ? m[0] : spaces(startW) + m[2]
+ spaces(endW) + spaces(endW)
+ m[4].replace(/^([=:])\s+/, "$1 ") + m[4].replace(/^([=:])\s+/, "$1 ");
}
} }
};
}).call(Editor.prototype); }).call(Editor.prototype);
@ -884,16 +899,20 @@ exports.onSessionChange = function(e) {
var oldSession = e.oldSession; var oldSession = e.oldSession;
if (oldSession) { if (oldSession) {
oldSession.multiSelect.removeEventListener("addRange", this.$onAddRange); oldSession.multiSelect.off("addRange", this.$onAddRange);
oldSession.multiSelect.removeEventListener("removeRange", this.$onRemoveRange); oldSession.multiSelect.off("removeRange", this.$onRemoveRange);
oldSession.multiSelect.removeEventListener("multiSelect", this.$onMultiSelect); oldSession.multiSelect.off("multiSelect", this.$onMultiSelect);
oldSession.multiSelect.removeEventListener("singleSelect", this.$onSingleSelect); oldSession.multiSelect.off("singleSelect", this.$onSingleSelect);
oldSession.multiSelect.lead.off("change", this.$checkMultiselectChange);
oldSession.multiSelect.anchor.off("change", this.$checkMultiselectChange);
} }
session.multiSelect.on("addRange", this.$onAddRange); session.multiSelect.on("addRange", this.$onAddRange);
session.multiSelect.on("removeRange", this.$onRemoveRange); session.multiSelect.on("removeRange", this.$onRemoveRange);
session.multiSelect.on("multiSelect", this.$onMultiSelect); session.multiSelect.on("multiSelect", this.$onMultiSelect);
session.multiSelect.on("singleSelect", this.$onSingleSelect); session.multiSelect.on("singleSelect", this.$onSingleSelect);
session.multiSelect.lead.on("change", this.$checkMultiselectChange);
session.multiSelect.anchor.on("change", this.$checkMultiselectChange);
// this.$onSelectionChange = this.onSelectionChange.bind(this); // this.$onSelectionChange = this.onSelectionChange.bind(this);
@ -916,6 +935,7 @@ function MultiSelect(editor) {
editor.$onMultiSelect = editor.$onMultiSelect.bind(editor); editor.$onMultiSelect = editor.$onMultiSelect.bind(editor);
editor.$onSingleSelect = editor.$onSingleSelect.bind(editor); editor.$onSingleSelect = editor.$onSingleSelect.bind(editor);
editor.$multiselectOnSessionChange = exports.onSessionChange.bind(editor); editor.$multiselectOnSessionChange = exports.onSessionChange.bind(editor);
editor.$checkMultiselectChange = editor.$checkMultiselectChange.bind(editor);
editor.$multiselectOnSessionChange(editor); editor.$multiselectOnSessionChange(editor);
editor.on("changeSession", editor.$multiselectOnSessionChange); editor.on("changeSession", editor.$multiselectOnSessionChange);
@ -969,7 +989,7 @@ require("./config").defineOptions(Editor.prototype, "editor", {
}, },
value: true value: true
} }
}) });

View file

@ -37,7 +37,6 @@ var EventEmitter = require("./lib/event_emitter").EventEmitter;
var Range = require("./range").Range; var Range = require("./range").Range;
/** /**
*
* Contains the cursor position and the text selection of an edit session. * Contains the cursor position and the text selection of an edit session.
* *
* The row/columns used in the selection are in document coordinates representing ths coordinates as thez appear in the document before applying soft wrap and folding. * The row/columns used in the selection are in document coordinates representing ths coordinates as thez appear in the document before applying soft wrap and folding.
@ -49,22 +48,16 @@ var Range = require("./range").Range;
* Emitted when the cursor position changes. * Emitted when the cursor position changes.
* @event changeCursor * @event changeCursor
* *
*
*
**/ **/
/** /**
* Emitted when the cursor selection changes. * Emitted when the cursor selection changes.
*
* @event changeSelection * @event changeSelection
*
*
*
**/ **/
/** /**
* Creates a new `Selection` object. * Creates a new `Selection` object.
* @param {EditSession} session The session to use * @param {EditSession} session The session to use
* *
*
*
* @constructor * @constructor
**/ **/
var Selection = function(session) { var Selection = function(session) {

View file

@ -0,0 +1,7 @@
define(function(require, exports, module) {
"use strict";
exports.snippetText = require("../requirejs/text!./gitignore.snippets");
exports.scope = "gitignore";
});

View file

195
lib/ace/snippets/vala.js Normal file
View file

@ -0,0 +1,195 @@
define(function(require, exports, module) {
"use strict";
// exports.snippetText = require("../requirejs/text!./.snippets");
exports.snippets = [
{
"content": "case ${1:condition}:\n\t$0\n\tbreak;\n",
"name": "case",
"scope": "vala",
"tabTrigger": "case"
},
{
"content": "/**\n * ${6}\n */\n${1:public} class ${2:MethodName}${3: : GLib.Object} {\n\n\t/**\n\t * ${7}\n\t */\n\tpublic ${2}(${4}) {\n\t\t${5}\n\t}\n\n\t$0\n}",
"name": "class",
"scope": "vala",
"tabTrigger": "class"
},
{
"content": "(${1}) => {\n\t${0}\n}\n",
"name": "closure",
"scope": "vala",
"tabTrigger": "=>"
},
{
"content": "/*\n * $0\n */",
"name": "Comment (multiline)",
"scope": "vala",
"tabTrigger": "/*"
},
{
"content": "Console.WriteLine($1);\n$0",
"name": "Console.WriteLine (writeline)",
"scope": "vala",
"tabTrigger": "writeline"
},
{
"content": "[DBus(name = \"$0\")]",
"name": "DBus annotation",
"scope": "vala",
"tabTrigger": "[DBus"
},
{
"content": "delegate ${1:void} ${2:DelegateName}($0);",
"name": "delegate",
"scope": "vala",
"tabTrigger": "delegate"
},
{
"content": "do {\n\t$0\n} while ($1);\n",
"name": "do while",
"scope": "vala",
"tabTrigger": "dowhile"
},
{
"content": "/**\n * $0\n */",
"name": "DocBlock",
"scope": "vala",
"tabTrigger": "/**"
},
{
"content": "else if ($1) {\n\t$0\n}\n",
"name": "else if (elseif)",
"scope": "vala",
"tabTrigger": "elseif"
},
{
"content": "else {\n\t$0\n}",
"name": "else",
"scope": "vala",
"tabTrigger": "else"
},
{
"content": "enum {$1:EnumName} {\n\t$0\n}",
"name": "enum",
"scope": "vala",
"tabTrigger": "enum"
},
{
"content": "public errordomain ${1:Error} {\n\t$0\n}",
"name": "error domain",
"scope": "vala",
"tabTrigger": "errordomain"
},
{
"content": "for ($1;$2;$3) {\n\t$0\n}",
"name": "for",
"scope": "vala",
"tabTrigger": "for"
},
{
"content": "foreach ($1 in $2) {\n\t$0\n}",
"name": "foreach",
"scope": "vala",
"tabTrigger": "foreach"
},
{
"content": "Gee.ArrayList<${1:G}>($0);",
"name": "Gee.ArrayList",
"scope": "vala",
"tabTrigger": "ArrayList"
},
{
"content": "Gee.HashMap<${1:K},${2:V}>($0);",
"name": "Gee.HashMap",
"scope": "vala",
"tabTrigger": "HashMap"
},
{
"content": "Gee.HashSet<${1:G}>($0);",
"name": "Gee.HashSet",
"scope": "vala",
"tabTrigger": "HashSet"
},
{
"content": "if ($1) {\n\t$0\n}",
"name": "if",
"scope": "vala",
"tabTrigger": "if"
},
{
"content": "interface ${1:InterfaceName}{$2: : SuperInterface} {\n\t$0\n}",
"name": "interface",
"scope": "vala",
"tabTrigger": "interface"
},
{
"content": "public static int main(string [] argv) {\n\t${0}\n\treturn 0;\n}",
"name": "Main function",
"scope": "vala",
"tabTrigger": "main"
},
{
"content": "namespace $1 {\n\t$0\n}\n",
"name": "namespace (ns)",
"scope": "vala",
"tabTrigger": "ns"
},
{
"content": "stdout.printf($0);",
"name": "printf",
"scope": "vala",
"tabTrigger": "printf"
},
{
"content": "${1:public} ${2:Type} ${3:Name} {\n\tset {\n\t\t$0\n\t}\n\tget {\n\n\t}\n}",
"name": "property (prop)",
"scope": "vala",
"tabTrigger": "prop"
},
{
"content": "${1:public} ${2:Type} ${3:Name} {\n\tget {\n\t\t$0\n\t}\n}",
"name": "read-only property (roprop)",
"scope": "vala",
"tabTrigger": "roprop"
},
{
"content": "@\"${1:\\$var}\"",
"name": "String template (@)",
"scope": "vala",
"tabTrigger": "@"
},
{
"content": "struct ${1:StructName} {\n\t$0\n}",
"name": "struct",
"scope": "vala",
"tabTrigger": "struct"
},
{
"content": "switch ($1) {\n\t$0\n}",
"name": "switch",
"scope": "vala",
"tabTrigger": "switch"
},
{
"content": "try {\n\t$2\n} catch (${1:Error} e) {\n\t$0\n}",
"name": "try/catch",
"scope": "vala",
"tabTrigger": "try"
},
{
"content": "\"\"\"$0\"\"\";",
"name": "Verbatim string (\"\"\")",
"scope": "vala",
"tabTrigger": "verbatim"
},
{
"content": "while ($1) {\n\t$0\n}",
"name": "while",
"scope": "vala",
"tabTrigger": "while"
}
];
exports.scope = "";
});

View file

@ -44,6 +44,7 @@ var testNames = [
"ace/mode/folding/xml_test", "ace/mode/folding/xml_test",
"ace/mode/folding/coffee_test", "ace/mode/folding/coffee_test",
"ace/multi_select_test", "ace/multi_select_test",
"ace/mouse/mouse_handler_test",
"ace/occur_test", "ace/occur_test",
"ace/range_test", "ace/range_test",
"ace/range_list_test", "ace/range_list_test",

View file

@ -116,6 +116,11 @@ var Tokenizer = function(rules) {
rule.onMatch = null; rule.onMatch = null;
} }
if (!ruleRegExps.length) {
mapping[0] = 0;
ruleRegExps.push("$");
}
splitterRurles.forEach(function(rule) { splitterRurles.forEach(function(rule) {
rule.splitRegex = this.createSplitterRegexp(rule.regex, flag); rule.splitRegex = this.createSplitterRegexp(rule.regex, flag);
}, this); }, this);

View file

@ -17,7 +17,8 @@
"asyncjs": "0.0.x", "asyncjs": "0.0.x",
"jsdom": "0.2.x", "jsdom": "0.2.x",
"amd-loader": "~0.0.4", "amd-loader": "~0.0.4",
"dryice": "0.4.10" "dryice": "0.4.11",
"architect-build": "https://github.com/c9/architect-build/tarball/42723e152bb"
}, },
"mappings": { "mappings": {
"ace": "." "ace": "."
@ -30,6 +31,7 @@
"lib": "lib/ace" "lib": "lib/ace"
}, },
"scripts": { "scripts": {
"start": "node static.js",
"test": "node lib/ace/test/all.js" "test": "node lib/ace/test/all.js"
} }
} }

View file

@ -85,7 +85,7 @@ var deps = {
jshint: { jshint: {
path: "mode/javascript/jshint.js", path: "mode/javascript/jshint.js",
browserify: { browserify: {
npmModule: "git+https://github.com/nightwing/jshint.git#master", npmModule: "git+https://github.com/ajaxorg/jshint.git#master",
path: "jshint/src/jshint.js", path: "jshint/src/jshint.js",
exports: "jshint" exports: "jshint"
}, },