commit
5fc3bbbe09
7 changed files with 328 additions and 114 deletions
|
|
@ -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";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
|
||||||
|
|
@ -1655,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);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1666,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);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1692,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;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1705,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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1762,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),
|
||||||
|
|
|
||||||
|
|
@ -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(), '("")');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
|
var stringBefore = token && /string/.test(token.type);
|
||||||
|
var stringAfter = !rightToken || /string/.test(rightToken.type);
|
||||||
|
|
||||||
|
var pair;
|
||||||
|
if (rightChar == quote) {
|
||||||
|
pair = stringBefore !== stringAfter;
|
||||||
|
} else {
|
||||||
|
if (stringBefore && !stringAfter)
|
||||||
|
return null; // wrap string with different quote
|
||||||
|
if (stringBefore && stringAfter)
|
||||||
|
return null; // do not pair quotes inside strings
|
||||||
|
var wordRe = session.$mode.tokenRe;
|
||||||
|
wordRe.lastIndex = 0;
|
||||||
|
var isWordBefore = wordRe.test(leftChar);
|
||||||
|
wordRe.lastIndex = 0;
|
||||||
|
var isWordAfter = wordRe.test(leftChar);
|
||||||
|
if (isWordBefore || isWordAfter)
|
||||||
|
return null; // before or after alphanumeric
|
||||||
|
if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
|
||||||
|
return null; // there is rightChar and it isn't closing
|
||||||
|
pair = true;
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
// Find what token we're inside.
|
text: pair ? quote + quote : "",
|
||||||
var tokens = session.getTokens(selection.start.row);
|
selection: [1,1]
|
||||||
var col = 0, token;
|
};
|
||||||
var quotepos = -1; // Track whether we're inside an open quote.
|
|
||||||
|
|
||||||
for (var x = 0; x < tokens.length; x++) {
|
|
||||||
token = tokens[x];
|
|
||||||
if (token.type == "string") {
|
|
||||||
quotepos = -1;
|
|
||||||
} else if (quotepos < 0) {
|
|
||||||
quotepos = token.value.indexOf(quote);
|
|
||||||
}
|
|
||||||
if ((token.value.length + col) > selection.start.column) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
col += tokens[x].value.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try and be smart about when we auto insert.
|
|
||||||
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)))) {
|
|
||||||
if (!CstyleBehaviour.isSaneInsertion(editor, session))
|
|
||||||
return;
|
|
||||||
return {
|
|
||||||
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]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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());
|
||||||
|
|
|
||||||
|
|
@ -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 = {
|
||||||
|
|
||||||
|
|
@ -167,6 +206,37 @@ module.exports = {
|
||||||
editor.execCommand('insertfoo');
|
editor.execCommand('insertfoo');
|
||||||
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"]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue