Merge branch 'master' of https://github.com/ajaxorg/ace into feature/ace_language_definition

# By nightwing (7) and others
# Via Harutyun Amirjanyan (4) and others
* 'master' of https://github.com/ajaxorg/ace:
  do not pair quotes inside strings
  fix toggleComment command in php mode
  fix copyLines* for multiple selections
  fix pairing of quotes in cstyle behavior
  add helper for creating tests
  Autocomplete exactMatch option
  add *~ (backup files created by various editors) to .gitignore
  Remove unneeded regex groups for Eiffel
  Update Eiffel programming language definition.
  add config.warn and refactor config to allow sharing with ace_tree
  do not use automatic scroll into view
  Teach tmlanguage.js to process multiple .tmLanguage files at once
This commit is contained in:
Bernhard Weichel 2014-12-14 23:11:35 +01:00
commit 18b3c57de9
21 changed files with 643 additions and 340 deletions

1
.gitignore vendored
View file

@ -2,6 +2,7 @@
.DS_Store .DS_Store
*.swp *.swp
*.tmp *.tmp
*~
# Project files that should not be in the repo # Project files that should not be in the repo
.* .*

View file

@ -29,6 +29,8 @@
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) { define(function(require, exports, module) {
var dom = require("ace/lib/dom");
var Range = require("ace/range").Range;
// allow easy access to ace in console, but not in ace code which uses strict // allow easy access to ace in console, but not in ace code which uses strict
function isStrict() { function isStrict() {
try { return !arguments.callee.caller.caller.caller} try { return !arguments.callee.caller.caller.caller}
@ -59,21 +61,155 @@ def(window, "session", function(){ warn(); return window.env.editor.session });
def(window, "split", function(){ warn(); return window.env.split }); def(window, "split", function(){ warn(); return window.env.split });
/* for textinput debuggging def(window, "devUtil", function(){ warn(); return exports });
dom.importCssString("\ exports.showTextArea = function(argument) {
.ace_text-input {\ dom.importCssString("\
position: absolute;\ .ace_text-input {\
z-index: 10!important;\ position: absolute;\
width: 6em!important;\ z-index: 10!important;\
height: 1em;\ width: 6em!important;\
opacity: 1!important;\ height: 1em;\
background: rgba(0, 92, 255, 0.11);\ opacity: 1!important;\
border: none;\ background: rgba(0, 92, 255, 0.11);\
font: inherit;\ border: none;\
padding: 0 1px;\ font: inherit;\
margin: 0 -1px;\ padding: 0 1px;\
text-indent: 0em;\ margin: 0 -1px;\
}\ text-indent: 0em;\
")*/ }\
");
};
exports.addGlobals = function() {
window.oop = require("ace/lib/oop");
window.dom = require("ace/lib/dom");
window.Range = require("ace/range").Range;
window.Editor = require("ace/editor").Editor;
window.assert = require("ace/test/asyncjs/assert");
window.asyncjs = require("ace/test/asyncjs/async");
window.UndoManager = require("ace/undomanager").UndoManager;
window.EditSession = require("ace/edit_session").EditSession;
window.MockRenderer = require("ace/test/mockrenderer").MockRenderer;
window.EventEmitter = require("ace/lib/event_emitter").EventEmitter;
window.getSelection = getSelection;
window.setSelection = setSelection;
window.testSelection = testSelection;
};
function getSelection(editor) {
var data = editor.multiSelect.toJSON();
if (!data.length) data = [data];
data = data.map(function(x) {
var a, c;
if (x.isBackwards) {
a = x.end;
c = x.start;
} else {
c = x.end;
a = x.start;
}
return Range.comparePoints(a, c)
? [a.row, a.column, c.row, c.column]
: [a.row, a.column];
});
return data.length > 1 ? data : data[0];
}
function setSelection(editor, data) {
if (typeof data[0] == "number")
data = [data];
editor.selection.fromJSON(data.map(function(x) {
var start = {row: x[0], column: x[1]};
var end = x.length == 2 ? start : {row: x[2], column: x[3]};
var isBackwards = Range.comparePoints(start, end) > 0;
return isBackwards ? {
start: end,
end: start,
isBackwards: true
} : {
start: start,
end: end,
isBackwards: true
};
}));
}
function testSelection(editor, data) {
assert.equal(getSelection(editor) + "", data + "");
}
exports.recordTestCase = function() {
exports.addGlobals();
var editor = window.editor;
var testcase = window.testcase = [];
var assert;
testcase.push({
type: "setValue",
data: editor.getValue()
}, {
type: "setSelection",
data: getSelection(editor)
});
editor.commands.on("afterExec", function(e) {
testcase.push({
type: "exec",
data: e
});
testcase.push({
type: "value",
data: editor.getValue()
});
testcase.push({
type: "selection",
data: getSelection(editor)
});
});
editor.on("mouseup", function() {
testcase.push({
type: "setSelection",
data: getSelection(editor)
});
});
testcase.toString = function() {
var lastValue = "";
// var lastSelection = ""
var str = this.map(function(x) {
var data = x.data;
switch (x.type) {
case "exec":
return 'editor.execCommand("'
+ data.command.name
+ (data.args ? '", ' + JSON.stringify(data.args) : '"')
+ ')';
case "setSelection":
return 'setSelection(editor, ' + JSON.stringify(data) + ')';
case "setValue":
if (lastValue != data) {
lastValue = data;
return 'editor.setValue(' + JSON.stringify(data) + ', -1)';
}
return;
case "selection":
return 'testSelection(editor, ' + JSON.stringify(data) + ')';
case "value":
if (lastValue != data) {
lastValue = data;
return 'assert.equal('
+ 'editor.getValue(),'
+ JSON.stringify(data)
+ ')';
}
return;
}
}).filter(Boolean).join("\n");
return getSelection + "\n"
+ testSelection + "\n"
+ setSelection + "\n"
+ "\n" + str + "\n";
};
};
}); });

View file

@ -257,7 +257,9 @@
<a href="http://ace.c9.io"> <a href="http://ace.c9.io">
<img id="ace-logo" src="doc/site/images/ace-logo.png" style="width: 134px;margin: 46px 0px 4px 66px;"> <img id="ace-logo" src="doc/site/images/ace-logo.png" style="width: 134px;margin: 46px 0px 4px 66px;">
</a> </a>
<div><a target="_test" href="./lib/ace/test/tests.html"
style="color: whitesmoke; text-align: left; padding: 1em;">tests</a>
</div>
</div> </div>
</div> </div>
</div> </div>

View file

@ -42,6 +42,7 @@ var snippetManager = require("./snippets").snippetManager;
var Autocomplete = function() { var Autocomplete = function() {
this.autoInsert = true; this.autoInsert = true;
this.autoSelect = true; this.autoSelect = true;
this.exactMatch = false;
this.keyboardHandler = new HashHandler(); this.keyboardHandler = new HashHandler();
this.keyboardHandler.bindKeys(this.commands); this.keyboardHandler.bindKeys(this.commands);
@ -306,6 +307,10 @@ var Autocomplete = function() {
return; return;
this.completions = new FilteredList(matches); this.completions = new FilteredList(matches);
if (this.exactMatch)
this.completions.exactMatch = true;
this.completions.setFilter(prefix); this.completions.setFilter(prefix);
var filtered = this.completions.filtered; var filtered = this.completions.filtered;
@ -416,6 +421,7 @@ var FilteredList = function(array, filterText, mutateData) {
this.all = array; this.all = array;
this.filtered = array; this.filtered = array;
this.filterText = filterText || ""; this.filterText = filterText || "";
this.exactMatch = false;
}; };
(function(){ (function(){
this.setFilter = function(str) { this.setFilter = function(str) {
@ -452,23 +458,29 @@ var FilteredList = function(array, filterText, mutateData) {
var matchMask = 0; var matchMask = 0;
var penalty = 0; var penalty = 0;
var index, distance; var index, distance;
// caption char iteration is faster in Chrome but slower in Firefox, so lets use indexOf
for (var j = 0; j < needle.length; j++) { if (this.exactMatch) {
// TODO add penalty on case mismatch if (needle !== caption.substr(0, needle.length))
var i1 = caption.indexOf(lower[j], lastIndex + 1);
var i2 = caption.indexOf(upper[j], lastIndex + 1);
index = (i1 >= 0) ? ((i2 < 0 || i1 < i2) ? i1 : i2) : i2;
if (index < 0)
continue loop; continue loop;
distance = index - lastIndex - 1; }else{
if (distance > 0) { // caption char iteration is faster in Chrome but slower in Firefox, so lets use indexOf
// first char mismatch should be more sensitive for (var j = 0; j < needle.length; j++) {
if (lastIndex === -1) // TODO add penalty on case mismatch
penalty += 10; var i1 = caption.indexOf(lower[j], lastIndex + 1);
penalty += distance; var i2 = caption.indexOf(upper[j], lastIndex + 1);
index = (i1 >= 0) ? ((i2 < 0 || i1 < i2) ? i1 : i2) : i2;
if (index < 0)
continue loop;
distance = index - lastIndex - 1;
if (distance > 0) {
// first char mismatch should be more sensitive
if (lastIndex === -1)
penalty += 10;
penalty += distance;
}
matchMask = matchMask | (1 << index);
lastIndex = index;
} }
matchMask = matchMask | (1 << index);
lastIndex = index;
} }
item.matchMask = matchMask; item.matchMask = matchMask;
item.exactMatch = penalty ? 0 : 1; item.exactMatch = penalty ? 0 : 1;

View file

@ -209,6 +209,8 @@ var AcePopup = function(parentNode) {
return this.screenWidth = 0; return this.screenWidth = 0;
}; };
popup.$blockScrolling = Infinity;
// public // public
popup.isOpen = false; popup.isOpen = false;
popup.isTopdown = false; popup.isTopdown = false;
@ -241,6 +243,7 @@ var AcePopup = function(parentNode) {
popup.on("changeSelection", function() { popup.on("changeSelection", function() {
if (popup.isOpen) if (popup.isOpen)
popup.setRow(popup.selection.lead.row); popup.setRow(popup.selection.lead.row);
popup.renderer.scrollCursorIntoView();
}); });
popup.hide = function() { popup.hide = function() {

View file

@ -205,12 +205,14 @@ exports.commands = [{
bindKey: bindKey("Shift-Up", "Shift-Up"), bindKey: bindKey("Shift-Up", "Shift-Up"),
exec: function(editor) { editor.getSelection().selectUp(); }, exec: function(editor) { editor.getSelection().selectUp(); },
multiSelectAction: "forEach", multiSelectAction: "forEach",
scrollIntoView: "cursor",
readOnly: true readOnly: true
}, { }, {
name: "golineup", name: "golineup",
bindKey: bindKey("Up", "Up|Ctrl-P"), bindKey: bindKey("Up", "Up|Ctrl-P"),
exec: function(editor, args) { editor.navigateUp(args.times); }, exec: function(editor, args) { editor.navigateUp(args.times); },
multiSelectAction: "forEach", multiSelectAction: "forEach",
scrollIntoView: "cursor",
readOnly: true readOnly: true
}, { }, {
name: "selecttoend", name: "selecttoend",
@ -395,12 +397,21 @@ exports.commands = [{
bindKey: bindKey("Ctrl-P", "Ctrl-P"), bindKey: bindKey("Ctrl-P", "Ctrl-P"),
exec: function(editor) { editor.jumpToMatching(); }, exec: function(editor) { editor.jumpToMatching(); },
multiSelectAction: "forEach", multiSelectAction: "forEach",
scrollIntoView: "animate",
readOnly: true readOnly: true
}, { }, {
name: "selecttomatching", name: "selecttomatching",
bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"), bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
exec: function(editor) { editor.jumpToMatching(true); }, exec: function(editor) { editor.jumpToMatching(true); },
multiSelectAction: "forEach", multiSelectAction: "forEach",
scrollIntoView: "animate",
readOnly: true
}, {
name: "expandToMatching",
bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"),
exec: function(editor) { editor.jumpToMatching(true, true); },
multiSelectAction: "forEach",
scrollIntoView: "animate",
readOnly: true readOnly: true
}, { }, {
name: "passKeysToBrowser", name: "passKeysToBrowser",
@ -458,11 +469,13 @@ exports.commands = [{
name: "modifyNumberUp", name: "modifyNumberUp",
bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"), bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
exec: function(editor) { editor.modifyNumber(1); }, exec: function(editor) { editor.modifyNumber(1); },
scrollIntoView: "cursor",
multiSelectAction: "forEach" multiSelectAction: "forEach"
}, { }, {
name: "modifyNumberDown", name: "modifyNumberDown",
bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"), bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
exec: function(editor) { editor.modifyNumber(-1); }, exec: function(editor) { editor.modifyNumber(-1); },
scrollIntoView: "cursor",
multiSelectAction: "forEach" multiSelectAction: "forEach"
}, { }, {
name: "replace", name: "replace",
@ -629,7 +642,7 @@ exports.commands = [{
var isBackwards = editor.selection.isBackwards(); var isBackwards = editor.selection.isBackwards();
var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor(); var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead(); var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length;
var selectedText = editor.session.doc.getTextRange(editor.selection.getRange()); var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
var selectedCount = selectedText.replace(/\n\s*/, " ").length; var selectedCount = selectedText.replace(/\n\s*/, " ").length;
var insertLine = editor.session.doc.getLine(selectionStart.row); var insertLine = editor.session.doc.getLine(selectionStart.row);
@ -640,7 +653,7 @@ exports.commands = [{
curLine = " " + curLine; curLine = " " + curLine;
} }
insertLine += curLine; insertLine += curLine;
}; }
if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) { if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
// Don't insert a newline at the end of the document // Don't insert a newline at the end of the document

View file

@ -35,41 +35,49 @@ exports.defaultCommands = [{
name: "addCursorAbove", name: "addCursorAbove",
exec: function(editor) { editor.selectMoreLines(-1); }, exec: function(editor) { editor.selectMoreLines(-1); },
bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"}, bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "addCursorBelow", name: "addCursorBelow",
exec: function(editor) { editor.selectMoreLines(1); }, exec: function(editor) { editor.selectMoreLines(1); },
bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"}, bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "addCursorAboveSkipCurrent", name: "addCursorAboveSkipCurrent",
exec: function(editor) { editor.selectMoreLines(-1, true); }, exec: function(editor) { editor.selectMoreLines(-1, true); },
bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"}, bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "addCursorBelowSkipCurrent", name: "addCursorBelowSkipCurrent",
exec: function(editor) { editor.selectMoreLines(1, true); }, exec: function(editor) { editor.selectMoreLines(1, true); },
bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"}, bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "selectMoreBefore", name: "selectMoreBefore",
exec: function(editor) { editor.selectMore(-1); }, exec: function(editor) { editor.selectMore(-1); },
bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"}, bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "selectMoreAfter", name: "selectMoreAfter",
exec: function(editor) { editor.selectMore(1); }, exec: function(editor) { editor.selectMore(1); },
bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"}, bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "selectNextBefore", name: "selectNextBefore",
exec: function(editor) { editor.selectMore(-1, true); }, exec: function(editor) { editor.selectMore(-1, true); },
bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"}, bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "selectNextAfter", name: "selectNextAfter",
exec: function(editor) { editor.selectMore(1, true); }, exec: function(editor) { editor.selectMore(1, true); },
bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"}, bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"},
scrollIntoView: "cursor",
readonly: true readonly: true
}, { }, {
name: "splitIntoLines", name: "splitIntoLines",
@ -79,11 +87,13 @@ exports.defaultCommands = [{
}, { }, {
name: "alignCursors", name: "alignCursors",
exec: function(editor) { editor.alignCursors(); }, exec: function(editor) { editor.alignCursors(); },
bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"} bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"},
scrollIntoView: "cursor"
}, { }, {
name: "findAll", name: "findAll",
exec: function(editor) { editor.findAll(); }, exec: function(editor) { editor.findAll(); },
bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"}, bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"},
scrollIntoView: "cursor",
readonly: true readonly: true
}]; }];
@ -92,6 +102,7 @@ exports.multiSelectCommands = [{
name: "singleSelection", name: "singleSelection",
bindKey: "esc", bindKey: "esc",
exec: function(editor) { editor.exitMultiSelectMode(); }, exec: function(editor) { editor.exitMultiSelectMode(); },
scrollIntoView: "cursor",
readonly: true, readonly: true,
isAvailable: function(editor) {return editor && editor.inMultiSelectMode} isAvailable: function(editor) {return editor && editor.inMultiSelectMode}
}]; }];

View file

@ -34,7 +34,9 @@ define(function(require, exports, module) {
var lang = require("./lib/lang"); var lang = require("./lib/lang");
var oop = require("./lib/oop"); var oop = require("./lib/oop");
var net = require("./lib/net"); var net = require("./lib/net");
var EventEmitter = require("./lib/event_emitter").EventEmitter; var AppConfig = require("./lib/app_config").AppConfig;
module.exports = exports = new AppConfig();
var global = (function() { var global = (function() {
return this; return this;
@ -69,8 +71,6 @@ exports.all = function() {
}; };
// module loading // module loading
oop.implement(exports, EventEmitter);
exports.moduleUrl = function(name, component) { exports.moduleUrl = function(name, component) {
if (options.$moduleUrls[name]) if (options.$moduleUrls[name])
return options.$moduleUrls[name]; return options.$moduleUrls[name];
@ -142,7 +142,6 @@ exports.loadModule = function(moduleName, onLoad) {
net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad); net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad);
}; };
// initialization // initialization
function init(packaged) { function init(packaged) {
options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged); options.packaged = packaged || require.packaged || module.packaged || (global.define && define.packaged);
@ -200,102 +199,4 @@ function deHyphenate(str) {
return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); }); return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); });
} }
var optionsProvider = {
setOptions: function(optList) {
Object.keys(optList).forEach(function(key) {
this.setOption(key, optList[key]);
}, this);
},
getOptions: function(optionNames) {
var result = {};
if (!optionNames) {
optionNames = Object.keys(this.$options);
} else if (!Array.isArray(optionNames)) {
result = optionNames;
optionNames = Object.keys(result);
}
optionNames.forEach(function(key) {
result[key] = this.getOption(key);
}, this);
return result;
},
setOption: function(name, value) {
if (this["$" + name] === value)
return;
var opt = this.$options[name];
if (!opt) {
if (typeof console != "undefined" && console.warn)
console.warn('misspelled option "' + name + '"');
return undefined;
}
if (opt.forwardTo)
return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
if (!opt.handlesSet)
this["$" + name] = value;
if (opt && opt.set)
opt.set.call(this, value);
},
getOption: function(name) {
var opt = this.$options[name];
if (!opt) {
if (typeof console != "undefined" && console.warn)
console.warn('misspelled option "' + name + '"');
return undefined;
}
if (opt.forwardTo)
return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
return opt && opt.get ? opt.get.call(this) : this["$" + name];
}
};
var defaultOptions = {};
/*
* option {name, value, initialValue, setterName, set, get }
*/
exports.defineOptions = function(obj, path, options) {
if (!obj.$options)
defaultOptions[path] = obj.$options = {};
Object.keys(options).forEach(function(key) {
var opt = options[key];
if (typeof opt == "string")
opt = {forwardTo: opt};
opt.name || (opt.name = key);
obj.$options[opt.name] = opt;
if ("initialValue" in opt)
obj["$" + opt.name] = opt.initialValue;
});
// implement option provider interface
oop.implement(obj, optionsProvider);
return this;
};
exports.resetOptions = function(obj) {
Object.keys(obj.$options).forEach(function(key) {
var opt = obj.$options[key];
if ("value" in opt)
obj.setOption(key, opt.value);
});
};
exports.setDefaultValue = function(path, name, value) {
var opts = defaultOptions[path] || (defaultOptions[path] = {});
if (opts[name]) {
if (opts.forwardTo)
exports.setDefaultValue(opts.forwardTo, name, value);
else
opts[name].value = value;
}
};
exports.setDefaultValues = function(path, optionHash) {
Object.keys(optionHash).forEach(function(key) {
exports.setDefaultValue(path, key, optionHash[key]);
});
};
}); });

View file

@ -969,8 +969,7 @@ var EditSession = function(text, mode) {
try { try {
this.$worker = this.$mode.createWorker(this); this.$worker = this.$mode.createWorker(this);
} catch (e) { } catch (e) {
if (typeof console == "object" && console.error) config.warn("Could not load worker", e);
console.log("Could not load worker", e);
this.$worker = null; this.$worker = null;
} }
}; };

View file

@ -150,7 +150,8 @@ var Editor = function(renderer, session) {
args: commadEvent.args, args: commadEvent.args,
scrollTop: this.renderer.scrollTop scrollTop: this.renderer.scrollTop
}; };
if (this.curOp.command.name)
this.$blockScrolling++;
// this.selections.push(this.selection.toJSON()); // this.selections.push(this.selection.toJSON());
}; };
@ -160,6 +161,8 @@ var Editor = function(renderer, session) {
return this.curOp = null; return this.curOp = null;
this._signal("beforeEndOperation"); this._signal("beforeEndOperation");
var command = this.curOp.command; var command = this.curOp.command;
if (command.name && this.$blockScrolling)
this.$blockScrolling--;
if (command && command.scrollIntoView) { if (command && command.scrollIntoView) {
switch (command.scrollIntoView) { switch (command.scrollIntoView) {
case "center": case "center":
@ -714,6 +717,10 @@ var Editor = function(renderer, session) {
this.$cursorChange(); this.$cursorChange();
if (!this.$blockScrolling) { if (!this.$blockScrolling) {
config.warn("Automatically scrolling cursor into view after selection change",
"this will be disabled in the next version",
"set editor.$blockScrolling = Infinity to disable this message"
);
this.renderer.scrollCursorIntoView(); this.renderer.scrollCursorIntoView();
} }
@ -902,9 +909,28 @@ var Editor = function(renderer, session) {
// todo this should change when paste becomes a command // todo this should change when paste becomes a command
if (this.$readOnly) if (this.$readOnly)
return; return;
var e = {text: text}; var e = {text: text};
this._signal("paste", e); this._signal("paste", e);
this.insert(e.text, true); text = e.text;
if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
this.insert(text);
} else {
var lines = text.split(/\r\n|\r|\n/);
var ranges = this.selection.rangeList.ranges;
if (lines.length > ranges.length || lines.length < 2 || !lines[1])
return this.commands.exec("insertstring", this, text);
for (var i = ranges.length; i--;) {
var range = ranges[i];
if (!range.isEmpty())
this.session.remove(range);
this.session.insert(range.start, lines[i]);
}
}
this.renderer.scrollCursorIntoView();
}; };
this.execCommand = function(command, args) { this.execCommand = function(command, args) {
@ -1629,9 +1655,7 @@ var Editor = function(renderer, session) {
* @related EditSession.moveLinesUp * @related EditSession.moveLinesUp
**/ **/
this.moveLinesDown = function() { this.moveLinesDown = function() {
this.$moveLines(function(firstRow, lastRow) { this.$moveLines(1, false);
return this.session.moveLinesDown(firstRow, lastRow);
});
}; };
/** /**
@ -1640,9 +1664,7 @@ var Editor = function(renderer, session) {
* @related EditSession.moveLinesDown * @related EditSession.moveLinesDown
**/ **/
this.moveLinesUp = function() { this.moveLinesUp = function() {
this.$moveLines(function(firstRow, lastRow) { this.$moveLines(-1, false);
return this.session.moveLinesUp(firstRow, lastRow);
});
}; };
/** /**
@ -1666,10 +1688,7 @@ var Editor = function(renderer, session) {
* *
**/ **/
this.copyLinesUp = function() { this.copyLinesUp = function() {
this.$moveLines(function(firstRow, lastRow) { this.$moveLines(-1, true);
this.session.duplicateLines(firstRow, lastRow);
return 0;
});
}; };
/** /**
@ -1679,51 +1698,61 @@ var Editor = function(renderer, session) {
* *
**/ **/
this.copyLinesDown = function() { this.copyLinesDown = function() {
this.$moveLines(function(firstRow, lastRow) { this.$moveLines(1, true);
return this.session.duplicateLines(firstRow, lastRow);
});
}; };
/** /**
* Executes a specific function, which can be anything that manipulates selected lines, such as copying them, duplicating them, or shifting them. * for internal use
* @param {Function} mover A method to call on each selected row * @ignore
*
* *
**/ **/
this.$moveLines = function(mover) { this.$moveLines = function(dir, copy) {
var rows, moved;
var selection = this.selection; var selection = this.selection;
if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) { if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) {
var range = selection.toOrientedRange(); var range = selection.toOrientedRange();
var rows = this.$getSelectedRows(range); rows = this.$getSelectedRows(range);
var linesMoved = mover.call(this, rows.first, rows.last); moved = this.session.$moveLines(rows.first, rows.last, copy ? 0 : dir);
range.moveBy(linesMoved, 0); if (copy && dir == -1) moved = 0;
range.moveBy(moved, 0);
selection.fromOrientedRange(range); selection.fromOrientedRange(range);
} else { } else {
var ranges = selection.rangeList.ranges; var ranges = selection.rangeList.ranges;
selection.rangeList.detach(this.session); selection.rangeList.detach(this.session);
this.inVirtualSelectionMode = true;
for (var i = ranges.length; i--; ) { var diff = 0;
var totalDiff = 0;
var l = ranges.length;
for (var i = 0; i < l; i++) {
var rangeIndex = i; var rangeIndex = i;
var rows = ranges[i].collapseRows(); ranges[i].moveBy(diff, 0);
var last = rows.end.row; rows = this.$getSelectedRows(ranges[i]);
var first = rows.start.row; var first = rows.first;
while (i--) { var last = rows.last;
rows = ranges[i].collapseRows(); while (++i < l) {
if (first - rows.end.row <= 1) if (totalDiff) ranges[i].moveBy(totalDiff, 0);
first = rows.end.row; var subRows = this.$getSelectedRows(ranges[i]);
else if (copy && subRows.first != last)
break; break;
else if (!copy && subRows.first > last + 1)
break;
last = subRows.last;
} }
i++; i--;
diff = this.session.$moveLines(first, last, copy ? 0 : dir);
var linesMoved = mover.call(this, first, last); if (copy && dir == -1) rangeIndex = i + 1;
while (rangeIndex >= i) { while (rangeIndex <= i) {
ranges[rangeIndex].moveBy(linesMoved, 0); ranges[rangeIndex].moveBy(diff, 0);
rangeIndex--; rangeIndex++;
} }
if (!copy) diff = 0;
totalDiff += diff;
} }
selection.fromOrientedRange(selection.ranges[0]); selection.fromOrientedRange(selection.ranges[0]);
selection.rangeList.attach(this.session); selection.rangeList.attach(this.session);
this.inVirtualSelectionMode = false;
} }
}; };
@ -1736,8 +1765,8 @@ var Editor = function(renderer, session) {
* *
* @returns {Object} * @returns {Object}
**/ **/
this.$getSelectedRows = function() { this.$getSelectedRows = function(range) {
var range = this.getSelectionRange().collapseRows(); range = (range || this.getSelectionRange()).collapseRows();
return { return {
first: this.session.getRowFoldStart(range.start.row), first: this.session.getRowFoldStart(range.start.row),

158
lib/ace/lib/app_config.js Normal file
View file

@ -0,0 +1,158 @@
/* ***** 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) {
"no use strict";
var lang = require("./lang");
var oop = require("./oop");
var EventEmitter = require("./event_emitter").EventEmitter;
var optionsProvider = {
setOptions: function(optList) {
Object.keys(optList).forEach(function(key) {
this.setOption(key, optList[key]);
}, this);
},
getOptions: function(optionNames) {
var result = {};
if (!optionNames) {
optionNames = Object.keys(this.$options);
} else if (!Array.isArray(optionNames)) {
result = optionNames;
optionNames = Object.keys(result);
}
optionNames.forEach(function(key) {
result[key] = this.getOption(key);
}, this);
return result;
},
setOption: function(name, value) {
if (this["$" + name] === value)
return;
var opt = this.$options[name];
if (!opt) {
return warn('misspelled option "' + name + '"');
}
if (opt.forwardTo)
return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value);
if (!opt.handlesSet)
this["$" + name] = value;
if (opt && opt.set)
opt.set.call(this, value);
},
getOption: function(name) {
var opt = this.$options[name];
if (!opt) {
return warn('misspelled option "' + name + '"');
}
if (opt.forwardTo)
return this[opt.forwardTo] && this[opt.forwardTo].getOption(name);
return opt && opt.get ? opt.get.call(this) : this["$" + name];
}
};
function warn(message) {
if (typeof console != "undefined" && console.warn)
console.warn.apply(console, arguments);
}
function reportError(msg, data) {
var e = new Error(msg);
e.data = data;
if (typeof console == "object" && console.error)
console.error(e);
setTimeout(function() { throw e; });
};
var AppConfig = function() {
this.$defaultOptions = {};
};
(function() {
// module loading
oop.implement(this, EventEmitter);
/*
* option {name, value, initialValue, setterName, set, get }
*/
this.defineOptions = function(obj, path, options) {
if (!obj.$options)
this.$defaultOptions[path] = obj.$options = {};
Object.keys(options).forEach(function(key) {
var opt = options[key];
if (typeof opt == "string")
opt = {forwardTo: opt};
opt.name || (opt.name = key);
obj.$options[opt.name] = opt;
if ("initialValue" in opt)
obj["$" + opt.name] = opt.initialValue;
});
// implement option provider interface
oop.implement(obj, optionsProvider);
return this;
};
this.resetOptions = function(obj) {
Object.keys(obj.$options).forEach(function(key) {
var opt = obj.$options[key];
if ("value" in opt)
obj.setOption(key, opt.value);
});
};
this.setDefaultValue = function(path, name, value) {
var opts = this.$defaultOptions[path] || (this.$defaultOptions[path] = {});
if (opts[name]) {
if (opts.forwardTo)
this.setDefaultValue(opts.forwardTo, name, value);
else
opts[name].value = value;
}
};
this.setDefaultValues = function(path, optionHash) {
Object.keys(optionHash).forEach(function(key) {
this.setDefaultValue(path, key, optionHash[key]);
});
};
this.warn = warn;
this.reportError = reportError;
}).call(AppConfig.prototype);
exports.AppConfig = AppConfig;
});

View file

@ -31,9 +31,6 @@
define(function(require, exports, module) { define(function(require, exports, module) {
"use strict"; "use strict";
if (typeof document == "undefined")
return;
var XHTML_NS = "http://www.w3.org/1999/xhtml"; var XHTML_NS = "http://www.w3.org/1999/xhtml";
exports.getDocumentHead = function(doc) { exports.getDocumentHead = function(doc) {
@ -175,6 +172,10 @@ exports.getInnerHeight = function(element) {
); );
}; };
if (typeof document == "undefined")
return;
if (window.pageYOffset !== undefined) { if (window.pageYOffset !== undefined) {
exports.getPageScrollTop = function() { exports.getPageScrollTop = function() {
return window.pageYOffset; return window.pageYOffset;

View file

@ -120,6 +120,15 @@ module.exports = {
assert.equal(editor.getValue(), "{") assert.equal(editor.getValue(), "{")
exec("insertstring", 1, "\n"); exec("insertstring", 1, "\n");
assert.equal(editor.getValue(), "{\n \n}") assert.equal(editor.getValue(), "{\n \n}")
editor.setValue("");
exec("insertstring", 1, "(");
exec("insertstring", 1, '"');
exec("insertstring", 1, '"');
assert.equal(editor.getValue(), '("")');
exec("backspace", 1);
exec("insertstring", 1, '"');
assert.equal(editor.getValue(), '("")');
} }
}; };

View file

@ -260,48 +260,40 @@ var CstyleBehaviour = function() {
var cursor = editor.getCursorPosition(); var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row); var line = session.doc.getLine(cursor.row);
var leftChar = line.substring(cursor.column-1, cursor.column); var leftChar = line.substring(cursor.column-1, cursor.column);
var rightChar = line.substring(cursor.column, cursor.column + 1);
var token = session.getTokenAt(cursor.row, cursor.column);
var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
// We're escaped. // We're escaped.
if (leftChar == '\\') { if (leftChar == "\\" && token && /escape/.test(token.type))
return null; return null;
}
// Find what token we're inside. var stringBefore = token && /string/.test(token.type);
var tokens = session.getTokens(selection.start.row); var stringAfter = !rightToken || /string/.test(rightToken.type);
var col = 0, token;
var quotepos = -1; // Track whether we're inside an open quote.
for (var x = 0; x < tokens.length; x++) { var pair;
token = tokens[x]; if (rightChar == quote) {
if (token.type == "string") { pair = stringBefore !== stringAfter;
quotepos = -1; } else {
} else if (quotepos < 0) { if (stringBefore && !stringAfter)
quotepos = token.value.indexOf(quote); return null; // wrap string with different quote
} if (stringBefore && stringAfter)
if ((token.value.length + col) > selection.start.column) { return null; // do not pair quotes inside strings
break; var wordRe = session.$mode.tokenRe;
} wordRe.lastIndex = 0;
col += tokens[x].value.length; var isWordBefore = wordRe.test(leftChar);
} wordRe.lastIndex = 0;
var isWordAfter = wordRe.test(leftChar);
// Try and be smart about when we auto insert. if (isWordBefore || isWordAfter)
if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { return null; // before or after alphanumeric
if (!CstyleBehaviour.isSaneInsertion(editor, session)) if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
return; return null; // there is rightChar and it isn't closing
return { pair = true;
text: quote + quote,
selection: [1,1]
};
} else if (token && token.type === "string") {
// Ignore input and move right one if we're typing over the closing quote.
var rightChar = line.substring(cursor.column, cursor.column + 1);
if (rightChar == quote) {
return {
text: '',
selection: [1, 1]
};
}
} }
return {
text: pair ? quote + quote : "",
selection: [1,1]
};
} }
} }
}); });

View file

@ -58,45 +58,44 @@ var EiffelHighlightRules = function() {
"keyword": keywords "keyword": keywords
}, "identifier", true); }, "identifier", true);
var simpleString = /(?:[^"%\b\f\v]|%[A-DFHLNQR-V%'"()<>]|%\/(?:0[xX][\da-fA-F](?:_*[\da-fA-F])*|0[cC][0-7](?:_*[0-7])*|0[bB][01](?:_*[01])*|\d(?:_*\d)*)\/)+?/;
this.$rules = { this.$rules = {
"start": [{ "start": [{
token : "comment.line.double-dash", token : "string.quoted.other", // Aligned-verbatim-strings (verbatim option not supported)
regex : /--.*$/
}, {
token : "string.quoted.double",
regex : /"(?:%"|[^%])*?"/
}, {
token : "string.quoted.other", // "[ ]" aligned verbatim string
regex : /"\[/, regex : /"\[/,
next: "aligned_verbatim_string" next: "aligned_verbatim_string"
}, { }, {
token : "string.quoted.other", // "{ }" non-aligned verbatim string token : "string.quoted.other", // Non-aligned-verbatim-strings (verbatim option not supported)
regex : /"\{/, regex : /"\{/,
next: "non-aligned_verbatim_string" next: "non-aligned_verbatim_string"
}, {
token : "string.quoted.double",
regex : /"(?:[^%\b\f\n\r\v]|%[A-DFHLNQR-V%'"()<>]|%\/(?:0[xX][\da-fA-F](?:_*[\da-fA-F])*|0[cC][0-7](?:_*[0-7])*|0[bB][01](?:_*[01])*|\d(?:_*\d)*)\/)*?"/
}, {
token : "comment.line.double-dash",
regex : /--.*/
}, { }, {
token : "constant.character", token : "constant.character",
regex : /'(?:%%|%T|%R|%N|%F|%'|[^%])'/ regex : /'(?:[^%\b\f\n\r\t\v]|%[A-DFHLNQR-V%'"()<>]|%\/(?:0[xX][\da-fA-F](?:_*[\da-fA-F])*|0[cC][0-7](?:_*[0-7])*|0[bB][01](?:_*[01])*|\d(?:_*\d)*)\/)'/
}, { }, {
token : "constant.numeric", // real token : "constant.numeric", // hexa | octal | bin
regex : /(?:\d(?:_?\d)*\.|\.\d)(?:\d*[eE][+-]?\d+)?\b/ regex : /\b0(?:[xX][\da-fA-F](?:_*[\da-fA-F])*|[cC][0-7](?:_*[0-7])*|[bB][01](?:_*[01])*)\b/
}, { }, {
token : "constant.numeric", // integer token : "constant.numeric",
regex : /\d(?:_?\d)*\b/ regex : /(?:\d(?:_*\d)*)?\.(?:(?:\d(?:_*\d)*)?[eE][+-]?)?\d(?:_*\d)*|\d(?:_*\d)*\.?/
}, { }, {
token : "constant.numeric", // hex token : "paren.lparen",
regex : /0[xX][a-fA-F\d](?:_?[a-fA-F\d])*\b/ regex : /[\[({]|<<|\|\(/
}, { }, {
token : "constant.numeric", // octal token : "paren.rparen",
regex : /0[cC][0-7](?:_?[0-7])*\b/ regex : /[\])}]|>>|\|\)/
},{
token : "constant.numeric", // bin
regex : /0[bB][01](?:_?[01])*\b/
}, {
token : "keyword.operator",
regex : /\+|\-|\*|\/|\\\\|\/\/|\^|~|\/~|<|>|<=|>=|\/=|=|:=|\|\.\.\||\.\./
}, { }, {
token : "keyword.operator", // punctuation token : "keyword.operator", // punctuation
regex : /\.|:|,|;\b/ regex : /:=|->|\.(?=\w)|[;,:?]/
}, {
token : "keyword.operator",
regex : /\\\\|\|\.\.\||\.\.|\/[~\/]?|[><\/]=?|[-+*^=~]/
}, { }, {
token : function (v) { token : function (v) {
var result = keywordMapper (v); var result = keywordMapper (v);
@ -106,33 +105,27 @@ var EiffelHighlightRules = function() {
return result; return result;
}, },
regex : /[a-zA-Z][a-zA-Z\d_]*\b/ regex : /[a-zA-Z][a-zA-Z\d_]*\b/
}, {
token : "paren.lparen",
regex : /[\[({]/
}, {
token : "paren.rparen",
regex : /[\])}]/
}, { }, {
token : "text", token : "text",
regex : /\s+/ regex : /\s+/
} }
], ],
"aligned_verbatim_string" : [{ "aligned_verbatim_string" : [{
token : "string", // closing multi-line comment token : "string",
regex : /]"/, regex : /]"/,
next : "start" next : "start"
}, { }, {
token : "string", // comment spanning whole line token : "string",
regex : /[^(?:\]")]+/ regex : simpleString
} }
], ],
"non-aligned_verbatim_string" : [{ "non-aligned_verbatim_string" : [{
token : "string.quoted.other", // closing multi-line comment token : "string.quoted.other",
regex : /}"/, regex : /}"/,
next : "start" next : "start"
}, { }, {
token : "string.quoted.other", // comment spanning whole line token : "string.quoted.other",
regex : /[^(?:\}")]+/ regex : simpleString
} }
]}; ]};
}; };

View file

@ -55,6 +55,24 @@ oop.inherits(PhpMode, TextMode);
(function() { (function() {
this.tokenRe = new RegExp("^["
+ unicode.packages.L
+ unicode.packages.Mn + unicode.packages.Mc
+ unicode.packages.Nd
+ unicode.packages.Pc + "\_]+", "g"
);
this.nonTokenRe = new RegExp("^(?:[^"
+ unicode.packages.L
+ unicode.packages.Mn + unicode.packages.Mc
+ unicode.packages.Nd
+ unicode.packages.Pc + "\_]|\s])+", "g"
);
this.lineCommentStart = ["//", "#"];
this.blockComment = {start: "/*", end: "*/"};
this.getNextLineIndent = function(state, line, tab) { this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line); var indent = this.$getIndent(line);
@ -100,8 +118,10 @@ oop.inherits(PhpMode, TextMode);
var Mode = function(opts) { var Mode = function(opts) {
if (opts && opts.inline) { if (opts && opts.inline) {
PhpMode.call(this); var mode = new PhpMode();
return; mode.createWorker = this.createWorker;
mode.inlinePhp = true;
return mode;
} }
HtmlMode.call(this); HtmlMode.call(this);
this.HighlightRules = PhpHighlightRules; this.HighlightRules = PhpHighlightRules;
@ -116,24 +136,6 @@ oop.inherits(Mode, HtmlMode);
(function() { (function() {
this.tokenRe = new RegExp("^["
+ unicode.packages.L
+ unicode.packages.Mn + unicode.packages.Mc
+ unicode.packages.Nd
+ unicode.packages.Pc + "\_]+", "g"
);
this.nonTokenRe = new RegExp("^(?:[^"
+ unicode.packages.L
+ unicode.packages.Mn + unicode.packages.Mc
+ unicode.packages.Nd
+ unicode.packages.Pc + "\_]|\s])+", "g"
);
this.lineCommentStart = ["//", "#"];
this.blockComment = {start: "/*", end: "*/"};
this.createWorker = function(session) { this.createWorker = function(session) {
var worker = new WorkerClient(["ace"], "ace/mode/php_worker", "PhpWorker"); var worker = new WorkerClient(["ace"], "ace/mode/php_worker", "PhpWorker");
worker.attachToDocument(session.getDocument()); worker.attachToDocument(session.getDocument());

View file

@ -70,10 +70,10 @@ function DefaultHandlers(mouseHandler) {
if (button !== 0) { if (button !== 0) {
var selectionRange = editor.getSelectionRange(); var selectionRange = editor.getSelectionRange();
var selectionEmpty = selectionRange.isEmpty(); var selectionEmpty = selectionRange.isEmpty();
editor.$blockScrolling++;
if (selectionEmpty) if (selectionEmpty)
editor.selection.moveToPosition(pos); editor.selection.moveToPosition(pos);
editor.$blockScrolling--;
// 2: contextmenu, 1: linux paste // 2: contextmenu, 1: linux paste
editor.textInput.onContextMenu(ev.domEvent); editor.textInput.onContextMenu(ev.domEvent);
return; // stopping event here breaks contextmenu on ff mac return; // stopping event here breaks contextmenu on ff mac
@ -100,7 +100,7 @@ function DefaultHandlers(mouseHandler) {
pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y); pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);
var editor = this.editor; var editor = this.editor;
// allow double/triple click handlers to change selection // allow double/triple click handlers to change selection
editor.$blockScrolling++;
if (this.mousedownEvent.getShiftKey()) if (this.mousedownEvent.getShiftKey())
editor.selection.selectToPosition(pos); editor.selection.selectToPosition(pos);
else if (!waitForClickSelection) else if (!waitForClickSelection)
@ -112,12 +112,13 @@ function DefaultHandlers(mouseHandler) {
} }
editor.setStyle("ace_selecting"); editor.setStyle("ace_selecting");
this.setState("select"); this.setState("select");
editor.$blockScrolling--;
}; };
this.select = function() { this.select = function() {
var anchor, editor = this.editor; var anchor, editor = this.editor;
var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y); var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
editor.$blockScrolling++;
if (this.$clickSelection) { if (this.$clickSelection) {
var cmp = this.$clickSelection.comparePoint(cursor); var cmp = this.$clickSelection.comparePoint(cursor);
@ -133,7 +134,7 @@ function DefaultHandlers(mouseHandler) {
editor.selection.setSelectionAnchor(anchor.row, anchor.column); editor.selection.setSelectionAnchor(anchor.row, anchor.column);
} }
editor.selection.selectToPosition(cursor); editor.selection.selectToPosition(cursor);
editor.$blockScrolling--;
editor.renderer.scrollCursorIntoView(); editor.renderer.scrollCursorIntoView();
}; };
@ -141,7 +142,7 @@ function DefaultHandlers(mouseHandler) {
var anchor, editor = this.editor; var anchor, editor = this.editor;
var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y); var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);
var range = editor.selection[unitName](cursor.row, cursor.column); var range = editor.selection[unitName](cursor.row, cursor.column);
editor.$blockScrolling++;
if (this.$clickSelection) { if (this.$clickSelection) {
var cmpStart = this.$clickSelection.comparePoint(range.start); var cmpStart = this.$clickSelection.comparePoint(range.start);
var cmpEnd = this.$clickSelection.comparePoint(range.end); var cmpEnd = this.$clickSelection.comparePoint(range.end);
@ -165,7 +166,7 @@ function DefaultHandlers(mouseHandler) {
editor.selection.setSelectionAnchor(anchor.row, anchor.column); editor.selection.setSelectionAnchor(anchor.row, anchor.column);
} }
editor.selection.selectToPosition(cursor); editor.selection.selectToPosition(cursor);
editor.$blockScrolling--;
editor.renderer.scrollCursorIntoView(); editor.renderer.scrollCursorIntoView();
}; };

View file

@ -558,33 +558,6 @@ var Editor = require("./editor").Editor;
} }
}; };
// todo this should change when paste becomes a command
this.onPaste = function(text) {
if (this.$readOnly)
return;
var e = {text: text};
this._signal("paste", e);
text = e.text;
if (!this.inMultiSelectMode || this.inVirtualSelectionMode)
return this.insert(text);
var lines = text.split(/\r\n|\r|\n/);
var ranges = this.selection.rangeList.ranges;
if (lines.length > ranges.length || lines.length < 2 || !lines[1])
return this.commands.exec("insertstring", this, text);
for (var i = ranges.length; i--;) {
var range = ranges[i];
if (!range.isEmpty())
this.session.remove(range);
this.session.insert(range.start, lines[i]);
}
};
/** /**
* Finds and selects all the occurences of `needle`. * Finds and selects all the occurences of `needle`.
* @param {String} The text to find * @param {String} The text to find

View file

@ -51,6 +51,45 @@ var exec = function(name, times, args) {
var testRanges = function(str) { var testRanges = function(str) {
assert.equal(editor.selection.getAllRanges() + "", str + ""); assert.equal(editor.selection.getAllRanges() + "", str + "");
}; };
function getSelection(editor) {
var data = editor.multiSelect.toJSON();
if (!data.length) data = [data];
data = data.map(function(x) {
var a, c;
if (x.isBackwards) {
a = x.end;
c = x.start;
} else {
c = x.end;
a = x.start;
}
return Range.comparePoints(a, c)
? [a.row, a.column, c.row, c.column]
: [a.row, a.column];
});
return data.length > 1 ? data : data[0];
}
function testSelection(editor, data) {
assert.equal(getSelection(editor) + "", data + "");
}
function setSelection(editor, data) {
if (typeof data[0] == "number")
data = [data];
editor.selection.fromJSON(data.map(function(x) {
var start = {row: x[0], column: x[1]};
var end = x.length == 2 ? start : {row: x[2], column: x[3]};
var isBackwards = Range.comparePoints(start, end) > 0;
return isBackwards ? {
start: end,
end: start,
isBackwards: true
} : {
start: start,
end: end,
isBackwards: true
};
}));
}
module.exports = { module.exports = {
@ -168,6 +207,37 @@ module.exports = {
assert.equal('l1foo\nl2foo', editor.getValue()); assert.equal('l1foo\nl2foo', editor.getValue());
}, },
"test multiselect move lines": function() {
editor = new Editor(new MockRenderer());
editor.setValue("l1\nl2\nl3\nl4", -1);
setSelection(editor, [[0,2],[1,2],[2,2],[3,2]]);
exec("copylinesdown");
assert.equal(editor.getValue(),"l1\nl1\nl2\nl2\nl3\nl3\nl4\nl4");
testSelection(editor, [[1,2],[3,2],[5,2],[7,2]]);
exec("copylinesup");
assert.equal(editor.getValue(),"l1\nl1\nl1\nl2\nl2\nl2\nl3\nl3\nl3\nl4\nl4\nl4");
testSelection(editor, [[1,2],[4,2],[7,2],[10,2]]);
exec("removeline");
assert.equal(editor.getValue(),"l1\nl1\nl2\nl2\nl3\nl3\nl4\nl4");
testSelection(editor, [[1,0],[3,0],[5,0],[7,0]]);
setSelection(editor, [[1,2],[1,0,1,1],[3,0,3,1],[5,0,5,1],[7,0,7,1]]);
exec("copylinesdown");
exec("copylinesup");
assert.equal(editor.getValue(),"l1\nl1\nl1\nl1\nl2\nl2\nl2\nl2\nl3\nl3\nl3\nl3\nl4\nl4\nl4\nl4");
testSelection(editor, [[2,2],[2,0,2,1],[6,0,6,1],[10,0,10,1],[14,0,14,1]]);
exec("movelinesdown", 12);
assert.equal(editor.getValue(),"l1\nl1\nl1\nl2\nl2\nl2\nl3\nl3\nl3\nl4\nl4\nl4\nl1\nl2\nl3\nl4");
testSelection(editor, [[12,2],[12,0,12,1],[13,0,13,1],[14,0,14,1],[15,0,15,1]]);
exec("movelinesup", 12);
assert.equal(editor.getValue(),"l1\nl2\nl3\nl4\nl1\nl1\nl1\nl2\nl2\nl2\nl3\nl3\nl3\nl4\nl4\nl4");
testSelection(editor, [[0,2],[0,0,0,1],[1,0,1,1],[2,0,2,1],[3,0,3,1]]);
},
"test multiselect fromJSON/toJSON": function() { "test multiselect fromJSON/toJSON": function() {
var doc = new EditSession(["l1", "l2"]); var doc = new EditSession(["l1", "l2"]);
editor = new Editor(new MockRenderer(), doc); editor = new Editor(new MockRenderer(), doc);

View file

@ -31,6 +31,7 @@
define(function(require, exports, module) { define(function(require, exports, module) {
"use strict"; "use strict";
var config = require("./config");
// tokenizing lines longer than this makes editor very slow // tokenizing lines longer than this makes editor very slow
var MAX_TOKEN_COUNT = 2000; var MAX_TOKEN_COUNT = 2000;
/** /**
@ -353,13 +354,8 @@ var Tokenizer = function(rules) {
}; };
}; };
this.reportError = function(msg, data) { this.reportError = config.reportError;
var e = new Error(msg);
e.data = data;
if (typeof console == "object" && console.error)
console.error(e);
setTimeout(function() { throw e; });
};
}).call(Tokenizer.prototype); }).call(Tokenizer.prototype);
exports.Tokenizer = Tokenizer; exports.Tokenizer = Tokenizer;

View file

@ -684,13 +684,14 @@ function convertTmLanguage(name, langStr) {
if (!module.parent) { if (!module.parent) {
var args = process.argv.splice(2); var args = process.argv.splice(2);
var tmLanguageFile = args[0]; var devMode = args[0] == "--dev";
var devMode = args[1]; if (devMode)
if (tmLanguageFile === undefined) { args.shift();
console.error("Usage: node tmlanguage.js path/or/url/to/syntax.file"); if (args.length < 1) {
console.error("Usage: node tmlanguage.js [--dev] path/or/url/to/syntax.file ...");
process.exit(1); process.exit(1);
} }
fetchAndConvert(tmLanguageFile); args.forEach(fetchAndConvert);
} else { } else {
exports.fetchAndConvert = fetchAndConvert; exports.fetchAndConvert = fetchAndConvert;
} }