mirror of
https://github.com/adobe/brackets.git
synced 2024-11-20 18:02:54 +01:00
Merge pull request #13116 from adobe/cm-5.24.0
update codemirror to 5.24.0
This commit is contained in:
commit
7dd7a75f80
@ -114,10 +114,16 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
// Helper function for testing cursor position
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
function expectCursorAt(pos) {
|
||||
var selection = testEditor.getSelection();
|
||||
expect(selection.start).toEqual(selection.end);
|
||||
expect(selection.start).toEqual(pos);
|
||||
expect(fixPos(selection.start)).toEqual(fixPos(selection.end));
|
||||
expect(fixPos(selection.start)).toEqual(fixPos(pos));
|
||||
}
|
||||
|
||||
// Helper function to
|
||||
|
@ -494,10 +494,16 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
// Helper function for testing cursor position
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
function expectCursorAt(pos) {
|
||||
var selection = testEditor.getSelection();
|
||||
expect(selection.start).toEqual(selection.end);
|
||||
expect(selection.start).toEqual(pos);
|
||||
expect(fixPos(selection.start)).toEqual(fixPos(selection.end));
|
||||
expect(fixPos(selection.start)).toEqual(fixPos(pos));
|
||||
}
|
||||
|
||||
it("should insert =\"\" after attribute", function () {
|
||||
|
@ -31,6 +31,14 @@ define(function (require, exports, module) {
|
||||
HTMLEntityHints = require("main").SpecialCharHints,
|
||||
defaultContent = require("text!unittest-files/default.html");
|
||||
|
||||
// Helper function for testing cursor position
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
describe("HTML Entity Hinting", function () {
|
||||
|
||||
var testEditorAndDoc,
|
||||
@ -150,7 +158,7 @@ define(function (require, exports, module) {
|
||||
|
||||
var hints = expectHints(hintProvider);
|
||||
hintProvider.insertHint(hints[0]);
|
||||
expect(testEditorAndDoc.editor.getCursorPos()).toEqual({line: 17, ch: 23});
|
||||
expect(fixPos(testEditorAndDoc.editor.getCursorPos())).toEqual(fixPos({line: 17, ch: 23}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -37,6 +37,28 @@ define(function (require, exports, module) {
|
||||
ColorEditor = require("ColorEditor").ColorEditor,
|
||||
tinycolor = require("thirdparty/tinycolor-min");
|
||||
|
||||
// Helper functions for testing cursor position / selection range
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
function fixSel(sel) {
|
||||
fixPos(sel.start);
|
||||
fixPos(sel.end);
|
||||
if (!("reversed" in sel)) {
|
||||
sel.reversed = false;
|
||||
}
|
||||
return sel;
|
||||
}
|
||||
function fixSels(sels) {
|
||||
sels.forEach(function (sel) {
|
||||
fixSel(sel);
|
||||
});
|
||||
return sels;
|
||||
}
|
||||
|
||||
describe("Inline Color Editor - unit", function () {
|
||||
|
||||
var testDocument, testEditor, inline;
|
||||
@ -217,7 +239,7 @@ define(function (require, exports, module) {
|
||||
runs(function () {
|
||||
testDocument.replaceRange("", {line: 1, ch: 22}, {line: 1, ch: 24});
|
||||
inline.colorEditor.setColorFromString("#c0c0c0");
|
||||
expect(inline.getCurrentRange()).toEqual({start: {line: 1, ch: 16}, end: {line: 1, ch: 23}});
|
||||
expect(fixSel(inline.getCurrentRange())).toEqual(fixSel({start: {line: 1, ch: 16}, end: {line: 1, ch: 23}}));
|
||||
expect(testDocument.getRange({line: 1, ch: 16}, {line: 1, ch: 23})).toBe("#c0c0c0");
|
||||
});
|
||||
});
|
||||
@ -236,7 +258,7 @@ define(function (require, exports, module) {
|
||||
// TODO (#2201): this assumes getColor() is a tinycolor, but sometimes it's a string
|
||||
expect(inline.colorEditor.getColor().toHexString().toLowerCase()).toBe("#a0cdef");
|
||||
expect(inline.close).not.toHaveBeenCalled();
|
||||
expect(inline.getCurrentRange()).toEqual({start: {line: 1, ch: 16}, end: {line: 1, ch: 23}});
|
||||
expect(fixSel(inline.getCurrentRange())).toEqual(fixSel({start: {line: 1, ch: 16}, end: {line: 1, ch: 23}}));
|
||||
});
|
||||
});
|
||||
|
||||
@ -260,7 +282,7 @@ define(function (require, exports, module) {
|
||||
testDocument.replaceRange("0", {line: 1, ch: 22}, {line: 1, ch: 22});
|
||||
expect(inline._color).toBe("#abcde0");
|
||||
expect(inline.close).not.toHaveBeenCalled();
|
||||
expect(inline.getCurrentRange()).toEqual({start: {line: 1, ch: 16}, end: {line: 1, ch: 23}});
|
||||
expect(fixSel(inline.getCurrentRange())).toEqual(fixSel({start: {line: 1, ch: 16}, end: {line: 1, ch: 23}}));
|
||||
});
|
||||
});
|
||||
|
||||
@ -269,7 +291,7 @@ define(function (require, exports, module) {
|
||||
runs(function () {
|
||||
testDocument.replaceRange("", {line: 1, ch: 22}, {line: 1, ch: 23});
|
||||
expect(inline._color).toBe("#abcdef");
|
||||
expect(inline.getCurrentRange()).toEqual({start: {line: 1, ch: 16}, end: {line: 1, ch: 22}});
|
||||
expect(fixSel(inline.getCurrentRange())).toEqual(fixSel({start: {line: 1, ch: 16}, end: {line: 1, ch: 22}}));
|
||||
});
|
||||
});
|
||||
|
||||
@ -278,7 +300,7 @@ define(function (require, exports, module) {
|
||||
runs(function () {
|
||||
testDocument.replaceRange("", {line: 1, ch: 22}, {line: 1, ch: 24});
|
||||
expect(inline._color).toBe("#abcdef");
|
||||
expect(inline.getCurrentRange()).toEqual({start: {line: 1, ch: 16}, end: {line: 1, ch: 22}});
|
||||
expect(fixSel(inline.getCurrentRange())).toEqual(fixSel({start: {line: 1, ch: 16}, end: {line: 1, ch: 22}}));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1169,65 +1169,68 @@ define(function (require, exports, module) {
|
||||
|
||||
ensurePreferences();
|
||||
deferredPreferences.done(function () {
|
||||
if (!file instanceof InMemoryFile) {
|
||||
FileSystem.resolve(dir, function (err, directory) {
|
||||
if (file instanceof InMemoryFile) {
|
||||
initTernServer(pr, []);
|
||||
var hintsPromise = primePump(path);
|
||||
hintsPromise.done(function () {
|
||||
addFilesDeferred.resolveWith(null, [_ternWorker]);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
FileSystem.resolve(dir, function (err, directory) {
|
||||
if (err) {
|
||||
console.error("Error resolving", dir);
|
||||
addFilesDeferred.resolveWith(null);
|
||||
return;
|
||||
}
|
||||
|
||||
directory.getContents(function (err, contents) {
|
||||
if (err) {
|
||||
console.error("Error resolving", dir);
|
||||
console.error("Error getting contents for", directory);
|
||||
addFilesDeferred.resolveWith(null);
|
||||
return;
|
||||
}
|
||||
|
||||
directory.getContents(function (err, contents) {
|
||||
if (err) {
|
||||
console.error("Error getting contents for", directory);
|
||||
addFilesDeferred.resolveWith(null);
|
||||
return;
|
||||
}
|
||||
|
||||
var files = contents
|
||||
.filter(function (entry) {
|
||||
return entry.isFile && !isFileExcluded(entry);
|
||||
})
|
||||
.map(function (entry) {
|
||||
return entry.fullPath;
|
||||
});
|
||||
|
||||
initTernServer(dir, files);
|
||||
|
||||
var hintsPromise = primePump(path);
|
||||
hintsPromise.done(function () {
|
||||
if (!usingModules()) {
|
||||
// Read the subdirectories of the new file's directory.
|
||||
// Read them first in case there are too many files to
|
||||
// read in the project.
|
||||
addAllFilesAndSubdirectories(dir, function () {
|
||||
// If the file is in the project root, then read
|
||||
// all the files under the project root.
|
||||
var currentDir = (dir + "/");
|
||||
if (projectRoot && currentDir !== projectRoot &&
|
||||
currentDir.indexOf(projectRoot) === 0) {
|
||||
addAllFilesAndSubdirectories(projectRoot, function () {
|
||||
// prime the pump again but this time don't wait
|
||||
// for completion.
|
||||
primePump(path);
|
||||
|
||||
addFilesDeferred.resolveWith(null, [_ternWorker]);
|
||||
});
|
||||
} else {
|
||||
addFilesDeferred.resolveWith(null, [_ternWorker]);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
addFilesDeferred.resolveWith(null, [_ternWorker]);
|
||||
}
|
||||
var files = contents
|
||||
.filter(function (entry) {
|
||||
return entry.isFile && !isFileExcluded(entry);
|
||||
})
|
||||
.map(function (entry) {
|
||||
return entry.fullPath;
|
||||
});
|
||||
|
||||
initTernServer(dir, files);
|
||||
|
||||
var hintsPromise = primePump(path);
|
||||
hintsPromise.done(function () {
|
||||
if (!usingModules()) {
|
||||
// Read the subdirectories of the new file's directory.
|
||||
// Read them first in case there are too many files to
|
||||
// read in the project.
|
||||
addAllFilesAndSubdirectories(dir, function () {
|
||||
// If the file is in the project root, then read
|
||||
// all the files under the project root.
|
||||
var currentDir = (dir + "/");
|
||||
if (projectRoot && currentDir !== projectRoot &&
|
||||
currentDir.indexOf(projectRoot) === 0) {
|
||||
addAllFilesAndSubdirectories(projectRoot, function () {
|
||||
// prime the pump again but this time don't wait
|
||||
// for completion.
|
||||
primePump(path);
|
||||
|
||||
addFilesDeferred.resolveWith(null, [_ternWorker]);
|
||||
});
|
||||
} else {
|
||||
addFilesDeferred.resolveWith(null, [_ternWorker]);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
addFilesDeferred.resolveWith(null, [_ternWorker]);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
initTernServer(pr, []);
|
||||
primePump(path);
|
||||
addFilesDeferred.resolveWith(null, [_ternWorker]);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,15 @@ define(function (require, exports, module) {
|
||||
});
|
||||
|
||||
describe("JavaScript Code Hinting", function () {
|
||||
|
||||
// Helper function for testing cursor position
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
/*
|
||||
* Ask provider for hints at current cursor position; expect it to
|
||||
* return some
|
||||
@ -718,7 +727,7 @@ define(function (require, exports, module) {
|
||||
selectHint(JSCodeHints.jsHintProvider, hintObj, "propA");
|
||||
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
|
||||
expect(testDoc.getRange(start, end)).toEqual("A1.propA");
|
||||
expect(testDoc.getLine(end.line).length).toEqual(8);
|
||||
});
|
||||
@ -736,7 +745,7 @@ define(function (require, exports, module) {
|
||||
selectHint(JSCodeHints.jsHintProvider, hintObj, "propA");
|
||||
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
|
||||
expect(testDoc.getRange(start, endplus)).toEqual("A1.propAprop");
|
||||
expect(testDoc.getLine(end.line).length).toEqual(12);
|
||||
});
|
||||
@ -752,7 +761,7 @@ define(function (require, exports, module) {
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
selectHint(JSCodeHints.jsHintProvider, hintObj, "propA");
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
|
||||
expect(testDoc.getRange(start, end)).toEqual("A1.propA");
|
||||
expect(testDoc.getLine(end.line).length).toEqual(8);
|
||||
});
|
||||
@ -769,7 +778,7 @@ define(function (require, exports, module) {
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
selectHint(JSCodeHints.jsHintProvider, hintObj, "propA");
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
|
||||
expect(testDoc.getRange(start, endplus)).toEqual("A1.propApB");
|
||||
expect(testDoc.getLine(end.line).length).toEqual(10);
|
||||
});
|
||||
@ -787,7 +796,7 @@ define(function (require, exports, module) {
|
||||
selectHint(JSCodeHints.jsHintProvider, hintObj, "propA");
|
||||
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
|
||||
expect(testDoc.getRange(start, endplus)).toEqual("(A1.propAprop)");
|
||||
expect(testDoc.getLine(endplus.line).length).toEqual(14);
|
||||
});
|
||||
@ -1005,7 +1014,7 @@ define(function (require, exports, module) {
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
selectHint(JSCodeHints.jsHintProvider, hintObj, "my-key");
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
|
||||
expect(testDoc.getRange(start, end)).toEqual("arr[\"my-key\"]");
|
||||
expect(testDoc.getLine(end.line).length).toEqual(13);
|
||||
});
|
||||
@ -1021,7 +1030,7 @@ define(function (require, exports, module) {
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
selectHint(JSCodeHints.jsHintProvider, hintObj, "my-key");
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
|
||||
expect(testDoc.getRange(start, end)).toEqual("arr[\"my-key\"]");
|
||||
expect(testDoc.getLine(end.line).length).toEqual(13);
|
||||
});
|
||||
@ -1037,7 +1046,7 @@ define(function (require, exports, module) {
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
selectHint(JSCodeHints.jsHintProvider, hintObj, "for");
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
|
||||
expect(testDoc.getRange(start, end)).toEqual("arr.for");
|
||||
expect(testDoc.getLine(end.line).length).toEqual(7);
|
||||
});
|
||||
|
@ -61,6 +61,14 @@ define(function (require, exports, module) {
|
||||
return result.promise();
|
||||
}
|
||||
|
||||
// Helper function for testing cursor position
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs setup for an inline editor test. Parses offsets (saved to Spec.offsets) for all files in
|
||||
* the test project (testPath) and saves files back to disk without offset markup.
|
||||
@ -237,7 +245,7 @@ define(function (require, exports, module) {
|
||||
var inlinePos = inlineWidget.editor.getCursorPos();
|
||||
|
||||
// verify cursor position in inline editor
|
||||
expect(inlinePos).toEqual(this.infos["test1inline.js"].offsets[0]);
|
||||
expect(fixPos(inlinePos)).toEqual(fixPos(this.infos["test1inline.js"].offsets[0]));
|
||||
});
|
||||
});
|
||||
|
||||
@ -249,7 +257,7 @@ define(function (require, exports, module) {
|
||||
var inlinePos = inlineWidget.editor.getCursorPos();
|
||||
|
||||
// verify cursor position in inline editor
|
||||
expect(inlinePos).toEqual(this.infos["test1inline.js"].offsets[1]);
|
||||
expect(fixPos(inlinePos)).toEqual(fixPos(this.infos["test1inline.js"].offsets[1]));
|
||||
});
|
||||
});
|
||||
|
||||
@ -261,7 +269,7 @@ define(function (require, exports, module) {
|
||||
var inlinePos = inlineWidget.editor.getCursorPos();
|
||||
|
||||
// verify cursor position in inline editor
|
||||
expect(inlinePos).toEqual(this.infos["test1inline.js"].offsets[2]);
|
||||
expect(fixPos(inlinePos)).toEqual(fixPos(this.infos["test1inline.js"].offsets[2]));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -138,11 +138,19 @@ define(function (require, exports, module) {
|
||||
expect(token.type).toBe(type);
|
||||
}
|
||||
|
||||
// Helper functions for testing cursor position / selection range
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
// Determines the position of the cursor.
|
||||
function expectCursorAt(pos) {
|
||||
var selection = testEditor.getSelection();
|
||||
expect(selection.start).toEqual(selection.end);
|
||||
expect(selection.start).toEqual(pos);
|
||||
expect(fixPos(selection.start)).toEqual(fixPos(selection.end));
|
||||
expect(fixPos(selection.start)).toEqual(fixPos(pos));
|
||||
}
|
||||
|
||||
describe("File name based hinting", function () {
|
||||
|
@ -107,11 +107,19 @@ define(function (require, exports, module) {
|
||||
expect(token.type).toBe(type);
|
||||
}
|
||||
|
||||
// Helper functions for testing cursor position / selection range
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
// Used to test cursor position.
|
||||
function expectCursorAt(pos) {
|
||||
var selection = testEditor.getSelection();
|
||||
expect(selection.start).toEqual(selection.end);
|
||||
expect(selection.start).toEqual(pos);
|
||||
expect(fixPos(selection.start)).toEqual(fixPos(selection.end));
|
||||
expect(fixPos(selection.start)).toEqual(fixPos(pos));
|
||||
}
|
||||
|
||||
describe("Tag Hinting", function () {
|
||||
|
@ -129,6 +129,14 @@ define(function (require, exports, module) {
|
||||
expect(hintList).toEqual(expectedHints);
|
||||
}
|
||||
|
||||
// Helper functions for testing cursor position / selection range
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
describe("HTML Url Code Hints", function () {
|
||||
|
||||
beforeFirst(function () {
|
||||
@ -428,7 +436,7 @@ define(function (require, exports, module) {
|
||||
expect(testDocument.getRange(pos1, pos3)).toEqual("url(test.html)");
|
||||
|
||||
// Cursor was moved past closing paren
|
||||
expect(testEditor.getCursorPos()).toEqual(pos3);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(pos3));
|
||||
});
|
||||
});
|
||||
|
||||
@ -458,7 +466,7 @@ define(function (require, exports, module) {
|
||||
expect(testDocument.getRange(pos1, pos3)).toEqual("url('test.html')");
|
||||
|
||||
// Cursor was moved past closing single-quote and closing paren
|
||||
expect(testEditor.getCursorPos()).toEqual(pos3);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(pos3));
|
||||
});
|
||||
});
|
||||
|
||||
@ -488,7 +496,7 @@ define(function (require, exports, module) {
|
||||
expect(testDocument.getRange(pos1, pos2)).toEqual("subfolder/");
|
||||
|
||||
// Cursor remains inside quote
|
||||
expect(testEditor.getCursorPos()).toEqual(pos2);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(pos2));
|
||||
|
||||
// Get hints of inserted folder
|
||||
hintsObj = null;
|
||||
@ -510,7 +518,7 @@ define(function (require, exports, module) {
|
||||
expect(testDocument.getRange(pos1, pos3)).toEqual("subfolder/chevron.png");
|
||||
|
||||
// Cursor was moved past closing double-quote and closing paren
|
||||
expect(testEditor.getCursorPos()).toEqual(pos4);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(pos4));
|
||||
});
|
||||
});
|
||||
|
||||
@ -543,7 +551,7 @@ define(function (require, exports, module) {
|
||||
expect(testDocument.getRange(pos1, pos4)).toEqual('url("subfolder/")');
|
||||
|
||||
// Cursor remains inside double-quote and closing paren
|
||||
expect(testEditor.getCursorPos()).toEqual(pos3);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(pos3));
|
||||
|
||||
// Get hints of inserted folder
|
||||
hintsObj = null;
|
||||
@ -565,7 +573,7 @@ define(function (require, exports, module) {
|
||||
expect(testDocument.getRange(pos1, pos5)).toEqual('url("subfolder/chevron.png")');
|
||||
|
||||
// Cursor was moved past closing double-quote and closing paren
|
||||
expect(testEditor.getCursorPos()).toEqual(pos5);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(pos5));
|
||||
});
|
||||
});
|
||||
|
||||
@ -595,7 +603,7 @@ define(function (require, exports, module) {
|
||||
expect(testDocument.getRange(pos1, pos3)).toEqual("subfolder/test2.html");
|
||||
|
||||
// Cursor is at end of inserted folder
|
||||
expect(testEditor.getCursorPos()).toEqual(pos2);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(pos2));
|
||||
|
||||
// Get hints of inserted folder
|
||||
hintsObj = null;
|
||||
@ -642,7 +650,7 @@ define(function (require, exports, module) {
|
||||
expect(testDocument.getRange(pos1, pos3)).toEqual("'subfolder/chevron.png'");
|
||||
|
||||
// Cursor was moved past closing single-quote
|
||||
expect(testEditor.getCursorPos()).toEqual(pos3);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(pos3));
|
||||
});
|
||||
});
|
||||
|
||||
@ -720,7 +728,7 @@ define(function (require, exports, module) {
|
||||
expect(testDocument.getRange(pos1, pos3)).toEqual("subfolder/dummy.jpg");
|
||||
|
||||
// Cursor is at end of inserted folder
|
||||
expect(testEditor.getCursorPos()).toEqual(pos2);
|
||||
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(pos2));
|
||||
|
||||
// Get hints of inserted folder
|
||||
hintsObj = null;
|
||||
|
42
src/npm-shrinkwrap.json
generated
42
src/npm-shrinkwrap.json
generated
@ -2,9 +2,9 @@
|
||||
"name": "brackets-src",
|
||||
"dependencies": {
|
||||
"ansi-regex": {
|
||||
"version": "2.0.0",
|
||||
"version": "2.1.1",
|
||||
"from": "ansi-regex@>=2.0.0 <3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.0.0.tgz"
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz"
|
||||
},
|
||||
"ansi-styles": {
|
||||
"version": "2.2.1",
|
||||
@ -43,15 +43,15 @@
|
||||
"optional": true
|
||||
},
|
||||
"aws4": {
|
||||
"version": "1.5.0",
|
||||
"version": "1.6.0",
|
||||
"from": "aws4@>=1.2.1 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.5.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.6.0.tgz",
|
||||
"optional": true
|
||||
},
|
||||
"bcrypt-pbkdf": {
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"from": "bcrypt-pbkdf@>=1.0.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz",
|
||||
"optional": true
|
||||
},
|
||||
"boom": {
|
||||
@ -72,9 +72,9 @@
|
||||
"optional": true
|
||||
},
|
||||
"codemirror": {
|
||||
"version": "5.21.0",
|
||||
"from": "codemirror@5.21.0",
|
||||
"resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.21.0.tgz"
|
||||
"version": "5.24.2",
|
||||
"from": "codemirror@5.24.2",
|
||||
"resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.24.2.tgz"
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.5",
|
||||
@ -257,9 +257,9 @@
|
||||
"optional": true
|
||||
},
|
||||
"jsbn": {
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"from": "jsbn@>=0.1.0 <0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
|
||||
"optional": true
|
||||
},
|
||||
"json-schema": {
|
||||
@ -288,7 +288,7 @@
|
||||
},
|
||||
"less": {
|
||||
"version": "2.7.2",
|
||||
"from": "less@latest",
|
||||
"from": "less@2.7.2",
|
||||
"resolved": "https://registry.npmjs.org/less/-/less-2.7.2.tgz"
|
||||
},
|
||||
"mime": {
|
||||
@ -298,14 +298,14 @@
|
||||
"optional": true
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.25.0",
|
||||
"from": "mime-db@>=1.25.0 <1.26.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.25.0.tgz"
|
||||
"version": "1.26.0",
|
||||
"from": "mime-db@>=1.26.0 <1.27.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.26.0.tgz"
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.13",
|
||||
"version": "2.1.14",
|
||||
"from": "mime-types@>=2.1.7 <2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.13.tgz"
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.14.tgz"
|
||||
},
|
||||
"minimist": {
|
||||
"version": "0.0.8",
|
||||
@ -356,9 +356,9 @@
|
||||
"optional": true
|
||||
},
|
||||
"qs": {
|
||||
"version": "6.3.0",
|
||||
"version": "6.3.1",
|
||||
"from": "qs@>=6.3.0 <6.4.0",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.3.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.3.1.tgz",
|
||||
"optional": true
|
||||
},
|
||||
"request": {
|
||||
@ -380,9 +380,9 @@
|
||||
"optional": true
|
||||
},
|
||||
"sshpk": {
|
||||
"version": "1.10.1",
|
||||
"version": "1.10.2",
|
||||
"from": "sshpk@>=1.7.0 <2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.10.1.tgz",
|
||||
"resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.10.2.tgz",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"assert-plus": {
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "brackets-src",
|
||||
"dependencies": {
|
||||
"codemirror": "5.21.0",
|
||||
"codemirror": "5.24.2",
|
||||
"less": "2.7.2"
|
||||
}
|
||||
}
|
||||
|
@ -104,6 +104,13 @@ define(function (require, exports, module) {
|
||||
};
|
||||
}
|
||||
|
||||
// Helper functions for testing cursor position / selection range
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
}
|
||||
|
||||
beforeFirst(function () {
|
||||
runs(function () {
|
||||
SpecRunnerUtils.createTestWindowAndRun(this, function (w) {
|
||||
@ -925,8 +932,7 @@ define(function (require, exports, module) {
|
||||
|
||||
runs(function () {
|
||||
CommandManager.execute(Commands.NAVIGATE_GOTO_FIRST_PROBLEM);
|
||||
|
||||
expect(EditorManager.getActiveEditor().getCursorPos()).toEqual({line: 1, ch: 3});
|
||||
expect(fixPos(EditorManager.getActiveEditor().getCursorPos())).toEqual(fixPos({line: 1, ch: 3}));
|
||||
});
|
||||
});
|
||||
|
||||
@ -956,9 +962,8 @@ define(function (require, exports, module) {
|
||||
|
||||
runs(function () {
|
||||
CommandManager.execute(Commands.NAVIGATE_GOTO_FIRST_PROBLEM);
|
||||
|
||||
// 'first' error is in order of linter registration, not in line number order
|
||||
expect(EditorManager.getActiveEditor().getCursorPos()).toEqual({line: 1, ch: 3});
|
||||
expect(fixPos(EditorManager.getActiveEditor().getCursorPos())).toEqual(fixPos({line: 1, ch: 3}));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -72,8 +72,10 @@ define(function (require, exports, module) {
|
||||
initialContentLines[2] = "new content";
|
||||
expect(myDocument.getText()).toEqual(initialContentLines.join("\n"));
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].start).toEqual({line: 2, ch: 11}); // end of "new content"
|
||||
expect(result[0].end).toEqual({line: 2, ch: 11});
|
||||
expect(result[0].start.line).toEqual(2);
|
||||
expect(result[0].start.ch).toEqual(11); // end of "new content"
|
||||
expect(result[0].end.line).toEqual(2);
|
||||
expect(result[0].end.ch).toEqual(11);
|
||||
expect(result[0].reversed).toBe(true);
|
||||
});
|
||||
|
||||
@ -83,8 +85,10 @@ define(function (require, exports, module) {
|
||||
initialContentLines[2] = "new content";
|
||||
expect(myDocument.getText()).toEqual(initialContentLines.join("\n"));
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].start).toEqual({line: 2, ch: 4});
|
||||
expect(result[0].end).toEqual({line: 2, ch: 4});
|
||||
expect(result[0].start.line).toEqual(2);
|
||||
expect(result[0].start.ch).toEqual(4);
|
||||
expect(result[0].end.line).toEqual(2);
|
||||
expect(result[0].end.ch).toEqual(4);
|
||||
expect(result[0].reversed).toBe(true);
|
||||
});
|
||||
|
||||
@ -101,11 +105,15 @@ define(function (require, exports, module) {
|
||||
initialContentLines.splice(3, 0, "");
|
||||
expect(myDocument.getText()).toEqual(initialContentLines.join("\n"));
|
||||
expect(result.length).toBe(2);
|
||||
expect(result[0].start).toEqual({line: 3, ch: 0}); // pushed to end of modified text
|
||||
expect(result[0].end).toEqual({line: 3, ch: 0});
|
||||
expect(result[0].start.line).toEqual(3);
|
||||
expect(result[0].start.ch).toEqual(0); // pushed to end of modified text
|
||||
expect(result[0].end.line).toEqual(3);
|
||||
expect(result[0].end.ch).toEqual(0);
|
||||
expect(result[0].primary).toBe(true);
|
||||
expect(result[1].start).toEqual({line: 6, ch: 0}); // pushed to end of modified text and updated for both edits
|
||||
expect(result[1].end).toEqual({line: 6, ch: 0});
|
||||
expect(result[1].start.line).toEqual(6);
|
||||
expect(result[1].start.ch).toEqual(0); // pushed to end of modified text and updated for both edits
|
||||
expect(result[1].end.line).toEqual(6);
|
||||
expect(result[1].end.ch).toEqual(0);
|
||||
expect(result[1].reversed).toBe(true);
|
||||
});
|
||||
|
||||
@ -122,11 +130,15 @@ define(function (require, exports, module) {
|
||||
initialContentLines.splice(3, 0, "");
|
||||
expect(myDocument.getText()).toEqual(initialContentLines.join("\n"));
|
||||
expect(result.length).toBe(2);
|
||||
expect(result[0].start).toEqual({line: 2, ch: 4}); // not modified since it's above the other edit
|
||||
expect(result[0].end).toEqual({line: 2, ch: 4});
|
||||
expect(result[0].start.line).toEqual(2);
|
||||
expect(result[0].start.ch).toEqual(4); // not modified since it's above the other edit
|
||||
expect(result[0].end.line).toEqual(2);
|
||||
expect(result[0].end.ch).toEqual(4);
|
||||
expect(result[0].primary).toBe(true);
|
||||
expect(result[1].start).toEqual({line: 5, ch: 4}); // not pushed to end of modified text, but updated for previous edit
|
||||
expect(result[1].end).toEqual({line: 5, ch: 4});
|
||||
expect(result[1].start.line).toEqual(5);
|
||||
expect(result[1].start.ch).toEqual(4); // not pushed to end of modified text, but updated for previous edit
|
||||
expect(result[1].end.line).toEqual(5);
|
||||
expect(result[1].end.ch).toEqual(4);
|
||||
expect(result[1].reversed).toBe(true);
|
||||
});
|
||||
|
||||
@ -146,14 +158,20 @@ define(function (require, exports, module) {
|
||||
initialContentLines.splice(3, 0, "");
|
||||
expect(myDocument.getText()).toEqual(initialContentLines.join("\n"));
|
||||
expect(result.length).toBe(3);
|
||||
expect(result[0].start).toEqual({line: 1, ch: 15}); // pushed to end of first modified text
|
||||
expect(result[0].end).toEqual({line: 1, ch: 15});
|
||||
expect(result[0].start.line).toEqual(1);
|
||||
expect(result[0].start.ch).toEqual(15); // pushed to end of first modified text
|
||||
expect(result[0].end.line).toEqual(1);
|
||||
expect(result[0].end.ch).toEqual(15);
|
||||
expect(result[0].primary).toBeFalsy();
|
||||
expect(result[1].start).toEqual({line: 3, ch: 0}); // pushed to end of second modified text
|
||||
expect(result[1].end).toEqual({line: 3, ch: 0});
|
||||
expect(result[1].start.line).toEqual(3);
|
||||
expect(result[1].start.ch).toEqual(0); // pushed to end of second modified text
|
||||
expect(result[1].end.line).toEqual(3);
|
||||
expect(result[1].end.ch).toEqual(0);
|
||||
expect(result[1].primary).toBe(true);
|
||||
expect(result[2].start).toEqual({line: 6, ch: 0}); // pushed to end of third modified text and updated for both edits
|
||||
expect(result[2].end).toEqual({line: 6, ch: 0});
|
||||
expect(result[2].start.line).toEqual(6);
|
||||
expect(result[2].start.ch).toEqual(0); // pushed to end of third modified text and updated for both edits
|
||||
expect(result[2].end.line).toEqual(6);
|
||||
expect(result[2].end.ch).toEqual(0);
|
||||
expect(result[2].reversed).toBe(true);
|
||||
});
|
||||
|
||||
@ -173,14 +191,20 @@ define(function (require, exports, module) {
|
||||
initialContentLines.splice(3, 0, "");
|
||||
expect(myDocument.getText()).toEqual(initialContentLines.join("\n"));
|
||||
expect(result.length).toBe(3);
|
||||
expect(result[0].start).toEqual({line: 1, ch: 4}); // not fixed up
|
||||
expect(result[0].end).toEqual({line: 1, ch: 4});
|
||||
expect(result[0].start.line).toEqual(1);
|
||||
expect(result[0].start.ch).toEqual(4); // not fixed up
|
||||
expect(result[0].end.line).toEqual(1);
|
||||
expect(result[0].end.ch).toEqual(4);
|
||||
expect(result[0].primary).toBeFalsy();
|
||||
expect(result[1].start).toEqual({line: 2, ch: 4}); // not fixed up, no need to adjust for first edit
|
||||
expect(result[1].end).toEqual({line: 2, ch: 4});
|
||||
expect(result[1].start.line).toEqual(2);
|
||||
expect(result[1].start.ch).toEqual(4); // not fixed up, no need to adjust for first edit
|
||||
expect(result[1].end.line).toEqual(2);
|
||||
expect(result[1].end.ch).toEqual(4);
|
||||
expect(result[1].primary).toBe(true);
|
||||
expect(result[2].start).toEqual({line: 5, ch: 4}); // not pushed to end of modified text, but updated for previous edit
|
||||
expect(result[2].end).toEqual({line: 5, ch: 4});
|
||||
expect(result[2].start.line).toEqual(5);
|
||||
expect(result[2].start.ch).toEqual(4); // not pushed to end of modified text, but updated for previous edit
|
||||
expect(result[2].end.line).toEqual(5);
|
||||
expect(result[2].end.ch).toEqual(4);
|
||||
expect(result[2].reversed).toBe(true);
|
||||
});
|
||||
|
||||
|
@ -102,6 +102,27 @@ define(function (require, exports, module) {
|
||||
});
|
||||
});
|
||||
|
||||
// Helper functions for testing cursor position / selection range
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
function fixSel(sel) {
|
||||
fixPos(sel.start);
|
||||
fixPos(sel.end);
|
||||
if (!("reversed" in sel)) {
|
||||
sel.reversed = false;
|
||||
}
|
||||
return sel;
|
||||
}
|
||||
function fixSels(sels) {
|
||||
sels.forEach(function (sel) {
|
||||
fixSel(sel);
|
||||
});
|
||||
return sels;
|
||||
}
|
||||
|
||||
/** Expect a file to exist (failing test if not) and then delete it */
|
||||
function expectAndDelete(fullPath) {
|
||||
@ -974,7 +995,7 @@ define(function (require, exports, module) {
|
||||
var currentDocument = DocumentManager.getCurrentDocument(),
|
||||
currentEditor = EditorManager.getActiveEditor();
|
||||
expect(currentDocument.file.fullPath).toEqual(newFilePath);
|
||||
expect(currentEditor.getSelections()).toEqual(selections);
|
||||
expect(fixSels(currentEditor.getSelections())).toEqual(fixSels(selections));
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
|
@ -80,6 +80,39 @@ define(function (require, exports, module) {
|
||||
}
|
||||
});
|
||||
|
||||
// Helper functions for testing cursor position / selection range
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
function fixSel(sel) {
|
||||
fixPos(sel.start);
|
||||
fixPos(sel.end);
|
||||
if (!("reversed" in sel)) {
|
||||
sel.reversed = false;
|
||||
}
|
||||
return sel;
|
||||
}
|
||||
function fixSels(sels) {
|
||||
sels.forEach(function (sel) {
|
||||
fixSel(sel);
|
||||
});
|
||||
return sels;
|
||||
}
|
||||
function expectCursorAt(pos) {
|
||||
var selection = myEditor.getSelection();
|
||||
expect(selection.start).toEqual(selection.end);
|
||||
expect(fixPos(selection.start)).toEqual(fixPos(pos));
|
||||
}
|
||||
function expectSelection(sel) {
|
||||
expect(fixSel(myEditor.getSelection())).toEqual(fixSel(sel));
|
||||
}
|
||||
function expectSelections(sels) {
|
||||
expect(fixSels(myEditor.getSelections())).toEqual(fixSels(sels));
|
||||
}
|
||||
|
||||
describe("Editor wrapper", function () {
|
||||
beforeEach(function () {
|
||||
createTestEditor(defaultContent, "");
|
||||
@ -100,8 +133,10 @@ define(function (require, exports, module) {
|
||||
changeFired = true;
|
||||
expect(doc).toBe(myDocument);
|
||||
expect(changeList.length).toBe(1);
|
||||
expect(changeList[0].from).toEqual({line: 0, ch: 0});
|
||||
expect(changeList[0].to).toEqual({line: 1, ch: 0});
|
||||
expect(changeList[0].from.line).toEqual(0);
|
||||
expect(changeList[0].from.ch).toEqual(0);
|
||||
expect(changeList[0].to.line).toEqual(1);
|
||||
expect(changeList[0].to.ch).toEqual(0);
|
||||
expect(changeList[0].text).toEqual(["new content"]);
|
||||
}
|
||||
myDocument.on("change", changeHandler);
|
||||
@ -123,11 +158,15 @@ define(function (require, exports, module) {
|
||||
var args = changeHandler.mostRecentCall.args;
|
||||
expect(args[1]).toBe(myDocument);
|
||||
expect(args[2][0].text).toEqual(["inserted"]);
|
||||
expect(args[2][0].from).toEqual({line: 1, ch: 0});
|
||||
expect(args[2][0].to).toEqual({line: 1, ch: 0});
|
||||
expect(args[2][0].from.line).toEqual(1);
|
||||
expect(args[2][0].from.ch).toEqual(0);
|
||||
expect(args[2][0].to.line).toEqual(1);
|
||||
expect(args[2][0].to.ch).toEqual(0);
|
||||
expect(args[2][1].text).toEqual([""]);
|
||||
expect(args[2][1].from).toEqual({line: 0, ch: 0});
|
||||
expect(args[2][1].to).toEqual({line: 0, ch: 4});
|
||||
expect(args[2][1].from.line).toEqual(0);
|
||||
expect(args[2][1].from.ch).toEqual(0);
|
||||
expect(args[2][1].to.line).toEqual(0);
|
||||
expect(args[2][1].to.ch).toEqual(4);
|
||||
});
|
||||
|
||||
it("should set mode based on Document language", function () {
|
||||
@ -382,20 +421,30 @@ define(function (require, exports, module) {
|
||||
describe("getCursorPos", function () {
|
||||
it("should return a single cursor", function () {
|
||||
myEditor._codeMirror.setCursor(0, 2);
|
||||
expect(myEditor.getCursorPos()).toEqual({line: 0, ch: 2});
|
||||
expect(myEditor.getCursorPos(false, "start")).toEqual({line: 0, ch: 2});
|
||||
expect(myEditor.getCursorPos(false, "anchor")).toEqual({line: 0, ch: 2});
|
||||
expect(myEditor.getCursorPos(false, "end")).toEqual({line: 0, ch: 2});
|
||||
expect(myEditor.getCursorPos(false, "head")).toEqual({line: 0, ch: 2});
|
||||
expect(myEditor.getCursorPos().line).toEqual(0);
|
||||
expect(myEditor.getCursorPos().ch).toEqual(2);
|
||||
expect(myEditor.getCursorPos(false, "start").line).toEqual(0);
|
||||
expect(myEditor.getCursorPos(false, "start").ch).toEqual(2);
|
||||
expect(myEditor.getCursorPos(false, "anchor").line).toEqual(0);
|
||||
expect(myEditor.getCursorPos(false, "anchor").ch).toEqual(2);
|
||||
expect(myEditor.getCursorPos(false, "end").line).toEqual(0);
|
||||
expect(myEditor.getCursorPos(false, "end").ch).toEqual(2);
|
||||
expect(myEditor.getCursorPos(false, "head").line).toEqual(0);
|
||||
expect(myEditor.getCursorPos(false, "head").ch).toEqual(2);
|
||||
});
|
||||
|
||||
it("should return the correct ends of a single selection", function () {
|
||||
myEditor._codeMirror.setSelection({line: 0, ch: 1}, {line: 0, ch: 5});
|
||||
expect(myEditor.getCursorPos()).toEqual({line: 0, ch: 5});
|
||||
expect(myEditor.getCursorPos(false, "start")).toEqual({line: 0, ch: 1});
|
||||
expect(myEditor.getCursorPos(false, "anchor")).toEqual({line: 0, ch: 1});
|
||||
expect(myEditor.getCursorPos(false, "end")).toEqual({line: 0, ch: 5});
|
||||
expect(myEditor.getCursorPos(false, "head")).toEqual({line: 0, ch: 5});
|
||||
expect(myEditor.getCursorPos().line).toEqual(0);
|
||||
expect(myEditor.getCursorPos().ch).toEqual(5);
|
||||
expect(myEditor.getCursorPos(false, "start").line).toEqual(0);
|
||||
expect(myEditor.getCursorPos(false, "start").ch).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "anchor").line).toEqual(0);
|
||||
expect(myEditor.getCursorPos(false, "anchor").ch).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "end").line).toEqual(0);
|
||||
expect(myEditor.getCursorPos(false, "end").ch).toEqual(5);
|
||||
expect(myEditor.getCursorPos(false, "head").line).toEqual(0);
|
||||
expect(myEditor.getCursorPos(false, "head").ch).toEqual(5);
|
||||
});
|
||||
|
||||
it("should return the default primary cursor in a multiple cursor selection", function () {
|
||||
@ -403,11 +452,16 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
|
||||
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
|
||||
], 2);
|
||||
expect(myEditor.getCursorPos()).toEqual({line: 2, ch: 1});
|
||||
expect(myEditor.getCursorPos(false, "start")).toEqual({line: 2, ch: 1});
|
||||
expect(myEditor.getCursorPos(false, "anchor")).toEqual({line: 2, ch: 1});
|
||||
expect(myEditor.getCursorPos(false, "end")).toEqual({line: 2, ch: 1});
|
||||
expect(myEditor.getCursorPos(false, "head")).toEqual({line: 2, ch: 1});
|
||||
expect(myEditor.getCursorPos().line).toEqual(2);
|
||||
expect(myEditor.getCursorPos().ch).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "start").line).toEqual(2);
|
||||
expect(myEditor.getCursorPos(false, "start").ch).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "anchor").line).toEqual(2);
|
||||
expect(myEditor.getCursorPos(false, "anchor").ch).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "end").line).toEqual(2);
|
||||
expect(myEditor.getCursorPos(false, "end").ch).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "head").line).toEqual(2);
|
||||
expect(myEditor.getCursorPos(false, "head").ch).toEqual(1);
|
||||
});
|
||||
|
||||
it("should return the specific primary cursor in a multiple cursor selection", function () {
|
||||
@ -415,11 +469,16 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
|
||||
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
|
||||
], 1);
|
||||
expect(myEditor.getCursorPos()).toEqual({line: 1, ch: 1});
|
||||
expect(myEditor.getCursorPos(false, "start")).toEqual({line: 1, ch: 1});
|
||||
expect(myEditor.getCursorPos(false, "anchor")).toEqual({line: 1, ch: 1});
|
||||
expect(myEditor.getCursorPos(false, "end")).toEqual({line: 1, ch: 1});
|
||||
expect(myEditor.getCursorPos(false, "head")).toEqual({line: 1, ch: 1});
|
||||
expect(myEditor.getCursorPos().line).toEqual(1);
|
||||
expect(myEditor.getCursorPos().ch).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "start").line).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "start").ch).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "anchor").line).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "anchor").ch).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "end").line).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "end").ch).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "head").line).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "head").ch).toEqual(1);
|
||||
});
|
||||
|
||||
it("should return the correct ends of the default primary selection in a multiple selection", function () {
|
||||
@ -427,11 +486,16 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
|
||||
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
|
||||
], 2);
|
||||
expect(myEditor.getCursorPos()).toEqual({line: 2, ch: 4});
|
||||
expect(myEditor.getCursorPos(false, "start")).toEqual({line: 2, ch: 1});
|
||||
expect(myEditor.getCursorPos(false, "anchor")).toEqual({line: 2, ch: 1});
|
||||
expect(myEditor.getCursorPos(false, "end")).toEqual({line: 2, ch: 4});
|
||||
expect(myEditor.getCursorPos(false, "head")).toEqual({line: 2, ch: 4});
|
||||
expect(myEditor.getCursorPos().line).toEqual(2);
|
||||
expect(myEditor.getCursorPos().ch).toEqual(4);
|
||||
expect(myEditor.getCursorPos(false, "start").line).toEqual(2);
|
||||
expect(myEditor.getCursorPos(false, "start").ch).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "anchor").line).toEqual(2);
|
||||
expect(myEditor.getCursorPos(false, "anchor").ch).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "end").line).toEqual(2);
|
||||
expect(myEditor.getCursorPos(false, "end").ch).toEqual(4);
|
||||
expect(myEditor.getCursorPos(false, "head").line).toEqual(2);
|
||||
expect(myEditor.getCursorPos(false, "head").ch).toEqual(4);
|
||||
});
|
||||
|
||||
it("should return the correct ends of a specific primary selection in a multiple selection", function () {
|
||||
@ -439,11 +503,16 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
|
||||
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
|
||||
], 1);
|
||||
expect(myEditor.getCursorPos()).toEqual({line: 1, ch: 4});
|
||||
expect(myEditor.getCursorPos(false, "start")).toEqual({line: 1, ch: 1});
|
||||
expect(myEditor.getCursorPos(false, "anchor")).toEqual({line: 1, ch: 1});
|
||||
expect(myEditor.getCursorPos(false, "end")).toEqual({line: 1, ch: 4});
|
||||
expect(myEditor.getCursorPos(false, "head")).toEqual({line: 1, ch: 4});
|
||||
expect(myEditor.getCursorPos().line).toEqual(1);
|
||||
expect(myEditor.getCursorPos().ch).toEqual(4);
|
||||
expect(myEditor.getCursorPos(false, "start").line).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "start").ch).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "anchor").line).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "anchor").ch).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "end").line).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "end").ch).toEqual(4);
|
||||
expect(myEditor.getCursorPos(false, "head").line).toEqual(1);
|
||||
expect(myEditor.getCursorPos(false, "head").ch).toEqual(4);
|
||||
});
|
||||
});
|
||||
|
||||
@ -451,13 +520,15 @@ define(function (require, exports, module) {
|
||||
it("should replace an existing single cursor", function () {
|
||||
myEditor._codeMirror.setCursor(0, 2);
|
||||
myEditor.setCursorPos(1, 3);
|
||||
expect(myEditor.getCursorPos()).toEqual({line: 1, ch: 3});
|
||||
expect(myEditor.getCursorPos().line).toEqual(1);
|
||||
expect(myEditor.getCursorPos().ch).toEqual(3);
|
||||
});
|
||||
|
||||
it("should replace an existing single selection", function () {
|
||||
myEditor._codeMirror.setSelection({line: 0, ch: 1}, {line: 0, ch: 5});
|
||||
myEditor.setCursorPos(1, 3);
|
||||
expect(myEditor.getCursorPos()).toEqual({line: 1, ch: 3});
|
||||
expect(myEditor.getCursorPos().line).toEqual(1);
|
||||
expect(myEditor.getCursorPos().ch).toEqual(3);
|
||||
});
|
||||
|
||||
it("should replace existing multiple cursors", function () {
|
||||
@ -466,7 +537,8 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
|
||||
], 2);
|
||||
myEditor.setCursorPos(1, 3);
|
||||
expect(myEditor.getCursorPos()).toEqual({line: 1, ch: 3});
|
||||
expect(myEditor.getCursorPos().line).toEqual(1);
|
||||
expect(myEditor.getCursorPos().ch).toEqual(3);
|
||||
});
|
||||
|
||||
it("should replace existing multiple selections", function () {
|
||||
@ -475,34 +547,35 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
|
||||
], 2);
|
||||
myEditor.setCursorPos(1, 3);
|
||||
expect(myEditor.getCursorPos()).toEqual({line: 1, ch: 3});
|
||||
expect(myEditor.getCursorPos().line).toEqual(1);
|
||||
expect(myEditor.getCursorPos().ch).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getSelection", function () {
|
||||
it("should return a single cursor", function () {
|
||||
myEditor._codeMirror.setCursor(0, 2);
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 0, ch: 2}, end: {line: 0, ch: 2}, reversed: false});
|
||||
expectSelection({start: {line: 0, ch: 2}, end: {line: 0, ch: 2}, reversed: false});
|
||||
});
|
||||
|
||||
it("should return a single selection", function () {
|
||||
myEditor._codeMirror.setSelection({line: 0, ch: 1}, {line: 0, ch: 5});
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 0, ch: 1}, end: {line: 0, ch: 5}, reversed: false});
|
||||
expectSelection({start: {line: 0, ch: 1}, end: {line: 0, ch: 5}, reversed: false});
|
||||
});
|
||||
|
||||
it("should return a multiline selection", function () {
|
||||
myEditor._codeMirror.setSelection({line: 0, ch: 5}, {line: 1, ch: 3});
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 0, ch: 5}, end: {line: 1, ch: 3}, reversed: false});
|
||||
expectSelection({start: {line: 0, ch: 5}, end: {line: 1, ch: 3}, reversed: false});
|
||||
});
|
||||
|
||||
it("should return a single selection in the proper order when reversed", function () {
|
||||
myEditor._codeMirror.setSelection({line: 0, ch: 5}, {line: 0, ch: 1});
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 0, ch: 1}, end: {line: 0, ch: 5}, reversed: true});
|
||||
expectSelection({start: {line: 0, ch: 1}, end: {line: 0, ch: 5}, reversed: true});
|
||||
});
|
||||
|
||||
it("should return a multiline selection in the proper order when reversed", function () {
|
||||
myEditor._codeMirror.setSelection({line: 1, ch: 3}, {line: 0, ch: 5});
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 0, ch: 5}, end: {line: 1, ch: 3}, reversed: true});
|
||||
expectSelection({start: {line: 0, ch: 5}, end: {line: 1, ch: 3}, reversed: true});
|
||||
});
|
||||
|
||||
it("should return the default primary cursor in a multiple cursor selection", function () {
|
||||
@ -510,7 +583,7 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
|
||||
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
|
||||
], 2);
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 1}, end: {line: 2, ch: 1}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 1}, end: {line: 2, ch: 1}, reversed: false});
|
||||
});
|
||||
|
||||
it("should return the specific primary cursor in a multiple cursor selection", function () {
|
||||
@ -518,7 +591,7 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
|
||||
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
|
||||
], 1);
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 1}, end: {line: 1, ch: 1}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 1}, end: {line: 1, ch: 1}, reversed: false});
|
||||
});
|
||||
|
||||
it("should return the default primary selection in a multiple selection", function () {
|
||||
@ -526,7 +599,7 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
|
||||
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
|
||||
], 2);
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 1}, end: {line: 2, ch: 4}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 1}, end: {line: 2, ch: 4}, reversed: false});
|
||||
});
|
||||
|
||||
it("should return the default primary selection in the proper order when reversed", function () {
|
||||
@ -534,7 +607,7 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
|
||||
{anchor: {line: 2, ch: 4}, head: {line: 2, ch: 1}}
|
||||
], 2);
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 1}, end: {line: 2, ch: 4}, reversed: true});
|
||||
expectSelection({start: {line: 2, ch: 1}, end: {line: 2, ch: 4}, reversed: true});
|
||||
});
|
||||
|
||||
it("should return the specific primary selection in a multiple selection", function () {
|
||||
@ -542,7 +615,7 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
|
||||
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
|
||||
], 1);
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 1}, end: {line: 1, ch: 4}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 1}, end: {line: 1, ch: 4}, reversed: false});
|
||||
});
|
||||
|
||||
it("should return the specific primary selection in the proper order when reversed", function () {
|
||||
@ -550,7 +623,7 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 1, ch: 4}, head: {line: 1, ch: 1}},
|
||||
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
|
||||
], 1);
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 1}, end: {line: 1, ch: 4}, reversed: true});
|
||||
expectSelection({start: {line: 1, ch: 1}, end: {line: 1, ch: 4}, reversed: true});
|
||||
});
|
||||
|
||||
});
|
||||
@ -558,17 +631,17 @@ define(function (require, exports, module) {
|
||||
describe("getSelections", function () {
|
||||
it("should return a single cursor", function () {
|
||||
myEditor._codeMirror.setCursor(0, 2);
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 2}, end: {line: 0, ch: 2}, reversed: false, primary: true}]);
|
||||
expectSelections([{start: {line: 0, ch: 2}, end: {line: 0, ch: 2}, reversed: false, primary: true}]);
|
||||
});
|
||||
|
||||
it("should return a single selection", function () {
|
||||
myEditor._codeMirror.setSelection({line: 0, ch: 1}, {line: 0, ch: 5});
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 0, ch: 5}, reversed: false, primary: true}]);
|
||||
expectSelections([{start: {line: 0, ch: 1}, end: {line: 0, ch: 5}, reversed: false, primary: true}]);
|
||||
});
|
||||
|
||||
it("should properly reverse a single selection whose head is before its anchor", function () {
|
||||
myEditor._codeMirror.setSelection({line: 0, ch: 5}, {line: 0, ch: 1});
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 0, ch: 5}, reversed: true, primary: true}]);
|
||||
expectSelections([{start: {line: 0, ch: 1}, end: {line: 0, ch: 5}, reversed: true, primary: true}]);
|
||||
});
|
||||
|
||||
it("should return multiple cursors", function () {
|
||||
@ -576,7 +649,7 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
|
||||
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
|
||||
], 2);
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 0, ch: 1}, reversed: false, primary: false},
|
||||
expectSelections([{start: {line: 0, ch: 1}, end: {line: 0, ch: 1}, reversed: false, primary: false},
|
||||
{start: {line: 1, ch: 1}, end: {line: 1, ch: 1}, reversed: false, primary: false},
|
||||
{start: {line: 2, ch: 1}, end: {line: 2, ch: 1}, reversed: false, primary: true}
|
||||
]);
|
||||
@ -587,7 +660,7 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
|
||||
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
|
||||
], 2);
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 0, ch: 4}, reversed: false, primary: false},
|
||||
expectSelections([{start: {line: 0, ch: 1}, end: {line: 0, ch: 4}, reversed: false, primary: false},
|
||||
{start: {line: 1, ch: 1}, end: {line: 1, ch: 4}, reversed: false, primary: false},
|
||||
{start: {line: 2, ch: 1}, end: {line: 2, ch: 4}, reversed: false, primary: true}
|
||||
]);
|
||||
@ -598,7 +671,7 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
|
||||
{anchor: {line: 2, ch: 4}, head: {line: 2, ch: 1}}
|
||||
], 2);
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 0, ch: 4}, reversed: true, primary: false},
|
||||
expectSelections([{start: {line: 0, ch: 1}, end: {line: 0, ch: 4}, reversed: true, primary: false},
|
||||
{start: {line: 1, ch: 1}, end: {line: 1, ch: 4}, reversed: false, primary: false},
|
||||
{start: {line: 2, ch: 1}, end: {line: 2, ch: 4}, reversed: true, primary: true}
|
||||
]);
|
||||
@ -608,7 +681,7 @@ define(function (require, exports, module) {
|
||||
myEditor._codeMirror.setSelections([{anchor: {line: 1, ch: 3}, head: {line: 0, ch: 5}},
|
||||
{anchor: {line: 4, ch: 4}, head: {line: 3, ch: 1}}
|
||||
], 1);
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 5}, end: {line: 1, ch: 3}, reversed: true, primary: false},
|
||||
expectSelections([{start: {line: 0, ch: 5}, end: {line: 1, ch: 3}, reversed: true, primary: false},
|
||||
{start: {line: 3, ch: 1}, end: {line: 4, ch: 4}, reversed: true, primary: true}
|
||||
]);
|
||||
});
|
||||
@ -659,18 +732,18 @@ define(function (require, exports, module) {
|
||||
it("should replace an existing single cursor", function () {
|
||||
myEditor._codeMirror.setCursor(0, 2);
|
||||
myEditor.setSelection({line: 1, ch: 3}, {line: 2, ch: 5});
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 3}, end: {line: 2, ch: 5}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 3}, end: {line: 2, ch: 5}, reversed: false});
|
||||
});
|
||||
|
||||
it("should replace an existing single selection", function () {
|
||||
myEditor._codeMirror.setSelection({line: 0, ch: 1}, {line: 0, ch: 5});
|
||||
myEditor.setSelection({line: 1, ch: 3}, {line: 2, ch: 5});
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 3}, end: {line: 2, ch: 5}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 3}, end: {line: 2, ch: 5}, reversed: false});
|
||||
});
|
||||
|
||||
it("should allow implicit end", function () {
|
||||
myEditor.setSelection({line: 1, ch: 3});
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 3}, end: {line: 1, ch: 3}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 3}, end: {line: 1, ch: 3}, reversed: false});
|
||||
});
|
||||
|
||||
it("should replace existing multiple cursors", function () {
|
||||
@ -679,7 +752,7 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
|
||||
], 2);
|
||||
myEditor.setSelection({line: 1, ch: 3}, {line: 2, ch: 5});
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 3}, end: {line: 2, ch: 5}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 3}, end: {line: 2, ch: 5}, reversed: false});
|
||||
});
|
||||
|
||||
it("should replace existing multiple selections", function () {
|
||||
@ -688,7 +761,7 @@ define(function (require, exports, module) {
|
||||
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
|
||||
], 2);
|
||||
myEditor.setSelection({line: 1, ch: 3}, {line: 2, ch: 5});
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 3}, end: {line: 2, ch: 5}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 3}, end: {line: 2, ch: 5}, reversed: false});
|
||||
});
|
||||
});
|
||||
|
||||
@ -697,18 +770,18 @@ define(function (require, exports, module) {
|
||||
myEditor._codeMirror.setCursor(0, 2);
|
||||
myEditor.setSelections([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}},
|
||||
{start: {line: 1, ch: 8}, end: {line: 2, ch: 5}}]);
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: false, primary: false},
|
||||
expectSelections([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: false, primary: false},
|
||||
{start: {line: 1, ch: 8}, end: {line: 2, ch: 5}, reversed: false, primary: true}]);
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 8}, end: {line: 2, ch: 5}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 8}, end: {line: 2, ch: 5}, reversed: false});
|
||||
});
|
||||
|
||||
it("should replace an existing single selection", function () {
|
||||
myEditor._codeMirror.setSelection({line: 0, ch: 1}, {line: 0, ch: 5});
|
||||
myEditor.setSelections([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}},
|
||||
{start: {line: 1, ch: 8}, end: {line: 2, ch: 5}}]);
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: false, primary: false},
|
||||
expectSelections([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: false, primary: false},
|
||||
{start: {line: 1, ch: 8}, end: {line: 2, ch: 5}, reversed: false, primary: true}]);
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 8}, end: {line: 2, ch: 5}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 8}, end: {line: 2, ch: 5}, reversed: false});
|
||||
});
|
||||
|
||||
it("should replace existing multiple cursors", function () {
|
||||
@ -718,9 +791,9 @@ define(function (require, exports, module) {
|
||||
], 2);
|
||||
myEditor.setSelections([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}},
|
||||
{start: {line: 1, ch: 8}, end: {line: 2, ch: 5}}]);
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: false, primary: false},
|
||||
expectSelections([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: false, primary: false},
|
||||
{start: {line: 1, ch: 8}, end: {line: 2, ch: 5}, reversed: false, primary: true}]);
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 8}, end: {line: 2, ch: 5}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 8}, end: {line: 2, ch: 5}, reversed: false});
|
||||
});
|
||||
|
||||
it("should replace existing multiple selections", function () {
|
||||
@ -730,32 +803,32 @@ define(function (require, exports, module) {
|
||||
], 2);
|
||||
myEditor.setSelections([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}},
|
||||
{start: {line: 1, ch: 8}, end: {line: 2, ch: 5}}]);
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: false, primary: false},
|
||||
expectSelections([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: false, primary: false},
|
||||
{start: {line: 1, ch: 8}, end: {line: 2, ch: 5}, reversed: false, primary: true}]);
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 8}, end: {line: 2, ch: 5}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 8}, end: {line: 2, ch: 5}, reversed: false});
|
||||
});
|
||||
|
||||
it("should specify non-default primary selection", function () {
|
||||
myEditor.setSelections([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, primary: true},
|
||||
{start: {line: 1, ch: 8}, end: {line: 2, ch: 5}}]);
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: false, primary: true},
|
||||
expectSelections([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: false, primary: true},
|
||||
{start: {line: 1, ch: 8}, end: {line: 2, ch: 5}, reversed: false, primary: false}]);
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: false});
|
||||
expectSelection({start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: false});
|
||||
});
|
||||
|
||||
it("should sort and merge overlapping selections", function () {
|
||||
myEditor.setSelections([{start: {line: 2, ch: 4}, end: {line: 3, ch: 0}},
|
||||
{start: {line: 2, ch: 3}, end: {line: 2, ch: 6}},
|
||||
{start: {line: 1, ch: 1}, end: {line: 1, ch: 4}}]);
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 1, ch: 1}, end: {line: 1, ch: 4}, reversed: false, primary: true},
|
||||
expectSelections([{start: {line: 1, ch: 1}, end: {line: 1, ch: 4}, reversed: false, primary: true},
|
||||
{start: {line: 2, ch: 3}, end: {line: 3, ch: 0}, reversed: false, primary: false}]);
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 1}, end: {line: 1, ch: 4}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 1}, end: {line: 1, ch: 4}, reversed: false});
|
||||
});
|
||||
|
||||
it("should properly set reversed selections", function () {
|
||||
myEditor.setSelections([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: true},
|
||||
{start: {line: 1, ch: 8}, end: {line: 2, ch: 5}}]);
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: true, primary: false},
|
||||
expectSelections([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: true, primary: false},
|
||||
{start: {line: 1, ch: 8}, end: {line: 2, ch: 5}, reversed: false, primary: true}]);
|
||||
|
||||
});
|
||||
@ -766,8 +839,10 @@ define(function (require, exports, module) {
|
||||
var origSelections = [{start: {line: 0, ch: 4}, end: {line: 0, ch: 4}}],
|
||||
result = myEditor.convertToLineSelections(origSelections);
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].selectionForEdit.start).toEqual({line: 0, ch: 0});
|
||||
expect(result[0].selectionForEdit.end).toEqual({line: 1, ch: 0});
|
||||
expect(result[0].selectionForEdit.start.line).toEqual(0);
|
||||
expect(result[0].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[0].selectionForEdit.end.line).toEqual(1);
|
||||
expect(result[0].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[0].selectionsToTrack.length).toBe(1);
|
||||
expect(result[0].selectionsToTrack[0]).toEqual(origSelections[0]);
|
||||
});
|
||||
@ -776,8 +851,10 @@ define(function (require, exports, module) {
|
||||
var origSelections = [{start: {line: 0, ch: 4}, end: {line: 0, ch: 8}}],
|
||||
result = myEditor.convertToLineSelections(origSelections);
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].selectionForEdit.start).toEqual({line: 0, ch: 0});
|
||||
expect(result[0].selectionForEdit.end).toEqual({line: 1, ch: 0});
|
||||
expect(result[0].selectionForEdit.start.line).toEqual(0);
|
||||
expect(result[0].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[0].selectionForEdit.end.line).toEqual(1);
|
||||
expect(result[0].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[0].selectionsToTrack.length).toBe(1);
|
||||
expect(result[0].selectionsToTrack[0]).toEqual(origSelections[0]);
|
||||
});
|
||||
@ -786,8 +863,10 @@ define(function (require, exports, module) {
|
||||
var origSelections = [{start: {line: 0, ch: 4}, end: {line: 1, ch: 8}}],
|
||||
result = myEditor.convertToLineSelections(origSelections);
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].selectionForEdit.start).toEqual({line: 0, ch: 0});
|
||||
expect(result[0].selectionForEdit.end).toEqual({line: 2, ch: 0});
|
||||
expect(result[0].selectionForEdit.start.line).toEqual(0);
|
||||
expect(result[0].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[0].selectionForEdit.end.line).toEqual(2);
|
||||
expect(result[0].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[0].selectionsToTrack.length).toBe(1);
|
||||
expect(result[0].selectionsToTrack[0]).toEqual(origSelections[0]);
|
||||
});
|
||||
@ -796,8 +875,10 @@ define(function (require, exports, module) {
|
||||
var origSelections = [{start: {line: 0, ch: 4}, end: {line: 0, ch: 8}, reversed: true}],
|
||||
result = myEditor.convertToLineSelections(origSelections);
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].selectionForEdit.start).toEqual({line: 0, ch: 0});
|
||||
expect(result[0].selectionForEdit.end).toEqual({line: 1, ch: 0});
|
||||
expect(result[0].selectionForEdit.start.line).toEqual(0);
|
||||
expect(result[0].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[0].selectionForEdit.end.line).toEqual(1);
|
||||
expect(result[0].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[0].selectionsToTrack.length).toBe(1);
|
||||
expect(result[0].selectionsToTrack[0]).toEqual(origSelections[0]);
|
||||
});
|
||||
@ -806,8 +887,10 @@ define(function (require, exports, module) {
|
||||
var origSelections = [{start: {line: 0, ch: 0}, end: {line: 1, ch: 0}}],
|
||||
result = myEditor.convertToLineSelections(origSelections);
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].selectionForEdit.start).toEqual({line: 0, ch: 0});
|
||||
expect(result[0].selectionForEdit.end).toEqual({line: 1, ch: 0});
|
||||
expect(result[0].selectionForEdit.start.line).toEqual(0);
|
||||
expect(result[0].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[0].selectionForEdit.end.line).toEqual(1);
|
||||
expect(result[0].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[0].selectionsToTrack.length).toBe(1);
|
||||
expect(result[0].selectionsToTrack[0]).toEqual(origSelections[0]);
|
||||
});
|
||||
@ -816,8 +899,10 @@ define(function (require, exports, module) {
|
||||
var origSelections = [{start: {line: 0, ch: 0}, end: {line: 1, ch: 0}}],
|
||||
result = myEditor.convertToLineSelections(origSelections, {expandEndAtStartOfLine: true});
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].selectionForEdit.start).toEqual({line: 0, ch: 0});
|
||||
expect(result[0].selectionForEdit.end).toEqual({line: 2, ch: 0});
|
||||
expect(result[0].selectionForEdit.start.line).toEqual(0);
|
||||
expect(result[0].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[0].selectionForEdit.end.line).toEqual(2);
|
||||
expect(result[0].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[0].selectionsToTrack.length).toBe(1);
|
||||
expect(result[0].selectionsToTrack[0]).toEqual(origSelections[0]);
|
||||
});
|
||||
@ -829,20 +914,28 @@ define(function (require, exports, module) {
|
||||
{start: {line: 7, ch: 0}, end: {line: 8, ch: 0}}],
|
||||
result = myEditor.convertToLineSelections(origSelections);
|
||||
expect(result.length).toBe(4);
|
||||
expect(result[0].selectionForEdit.start).toEqual({line: 0, ch: 0});
|
||||
expect(result[0].selectionForEdit.end).toEqual({line: 1, ch: 0});
|
||||
expect(result[0].selectionForEdit.start.line).toEqual(0);
|
||||
expect(result[0].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[0].selectionForEdit.end.line).toEqual(1);
|
||||
expect(result[0].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[0].selectionsToTrack.length).toBe(1);
|
||||
expect(result[0].selectionsToTrack[0]).toEqual(origSelections[0]);
|
||||
expect(result[1].selectionForEdit.start).toEqual({line: 2, ch: 0});
|
||||
expect(result[1].selectionForEdit.end).toEqual({line: 3, ch: 0});
|
||||
expect(result[1].selectionForEdit.start.line).toEqual(2);
|
||||
expect(result[1].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[1].selectionForEdit.end.line).toEqual(3);
|
||||
expect(result[1].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[1].selectionsToTrack.length).toBe(1);
|
||||
expect(result[1].selectionsToTrack[0]).toEqual(origSelections[1]);
|
||||
expect(result[2].selectionForEdit.start).toEqual({line: 4, ch: 0});
|
||||
expect(result[2].selectionForEdit.end).toEqual({line: 6, ch: 0});
|
||||
expect(result[2].selectionForEdit.start.line).toEqual(4);
|
||||
expect(result[2].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[2].selectionForEdit.end.line).toEqual(6);
|
||||
expect(result[2].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[2].selectionsToTrack.length).toBe(1);
|
||||
expect(result[2].selectionsToTrack[0]).toEqual(origSelections[2]);
|
||||
expect(result[3].selectionForEdit.start).toEqual({line: 7, ch: 0});
|
||||
expect(result[3].selectionForEdit.end).toEqual({line: 8, ch: 0}); // not expanded since expandEndAtStartOfLine is false
|
||||
expect(result[3].selectionForEdit.start.line).toEqual(7);
|
||||
expect(result[3].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[3].selectionForEdit.end.line).toEqual(8);
|
||||
expect(result[3].selectionForEdit.end.ch).toEqual(0); // not expanded since expandEndAtStartOfLine is false
|
||||
expect(result[3].selectionsToTrack.length).toBe(1);
|
||||
expect(result[3].selectionsToTrack[0]).toEqual(origSelections[3]);
|
||||
});
|
||||
@ -853,13 +946,17 @@ define(function (require, exports, module) {
|
||||
{start: {line: 4, ch: 0}, end: {line: 5, ch: 0}}],
|
||||
result = myEditor.convertToLineSelections(origSelections);
|
||||
expect(result.length).toBe(2);
|
||||
expect(result[0].selectionForEdit.start).toEqual({line: 0, ch: 0});
|
||||
expect(result[0].selectionForEdit.end).toEqual({line: 2, ch: 0});
|
||||
expect(result[0].selectionForEdit.start.line).toEqual(0);
|
||||
expect(result[0].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[0].selectionForEdit.end.line).toEqual(2);
|
||||
expect(result[0].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[0].selectionsToTrack.length).toBe(2);
|
||||
expect(result[0].selectionsToTrack[0]).toEqual(origSelections[0]);
|
||||
expect(result[0].selectionsToTrack[1]).toEqual(origSelections[1]);
|
||||
expect(result[1].selectionForEdit.start).toEqual({line: 4, ch: 0});
|
||||
expect(result[1].selectionForEdit.end).toEqual({line: 5, ch: 0});
|
||||
expect(result[1].selectionForEdit.start.line).toEqual(4);
|
||||
expect(result[1].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[1].selectionForEdit.end.line).toEqual(5);
|
||||
expect(result[1].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[1].selectionsToTrack.length).toBe(1);
|
||||
expect(result[1].selectionsToTrack[0]).toEqual(origSelections[2]);
|
||||
});
|
||||
@ -870,13 +967,17 @@ define(function (require, exports, module) {
|
||||
{start: {line: 4, ch: 0}, end: {line: 5, ch: 0}}],
|
||||
result = myEditor.convertToLineSelections(origSelections);
|
||||
expect(result.length).toBe(2);
|
||||
expect(result[0].selectionForEdit.start).toEqual({line: 0, ch: 0});
|
||||
expect(result[0].selectionForEdit.end).toEqual({line: 2, ch: 0});
|
||||
expect(result[0].selectionForEdit.start.line).toEqual(0);
|
||||
expect(result[0].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[0].selectionForEdit.end.line).toEqual(2);
|
||||
expect(result[0].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[0].selectionsToTrack.length).toBe(2);
|
||||
expect(result[0].selectionsToTrack[0]).toEqual(origSelections[0]);
|
||||
expect(result[0].selectionsToTrack[1]).toEqual(origSelections[1]);
|
||||
expect(result[1].selectionForEdit.start).toEqual({line: 4, ch: 0});
|
||||
expect(result[1].selectionForEdit.end).toEqual({line: 5, ch: 0});
|
||||
expect(result[1].selectionForEdit.start.line).toEqual(4);
|
||||
expect(result[1].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[1].selectionForEdit.end.line).toEqual(5);
|
||||
expect(result[1].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[1].selectionsToTrack.length).toBe(1);
|
||||
expect(result[1].selectionsToTrack[0]).toEqual(origSelections[2]);
|
||||
});
|
||||
@ -886,8 +987,10 @@ define(function (require, exports, module) {
|
||||
{start: {line: 1, ch: 8}, end: {line: 2, ch: 8}}],
|
||||
result = myEditor.convertToLineSelections(origSelections);
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].selectionForEdit.start).toEqual({line: 0, ch: 0});
|
||||
expect(result[0].selectionForEdit.end).toEqual({line: 3, ch: 0});
|
||||
expect(result[0].selectionForEdit.start.line).toEqual(0);
|
||||
expect(result[0].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[0].selectionForEdit.end.line).toEqual(3);
|
||||
expect(result[0].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[0].selectionsToTrack.length).toBe(2);
|
||||
expect(result[0].selectionsToTrack[0]).toEqual(origSelections[0]);
|
||||
expect(result[0].selectionsToTrack[1]).toEqual(origSelections[1]);
|
||||
@ -899,16 +1002,22 @@ define(function (require, exports, module) {
|
||||
{start: {line: 4, ch: 0}, end: {line: 5, ch: 0}}],
|
||||
result = myEditor.convertToLineSelections(origSelections, {mergeAdjacent: false});
|
||||
expect(result.length).toBe(3);
|
||||
expect(result[0].selectionForEdit.start).toEqual({line: 0, ch: 0});
|
||||
expect(result[0].selectionForEdit.end).toEqual({line: 1, ch: 0});
|
||||
expect(result[0].selectionForEdit.start.line).toEqual(0);
|
||||
expect(result[0].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[0].selectionForEdit.end.line).toEqual(1);
|
||||
expect(result[0].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[0].selectionsToTrack.length).toBe(1);
|
||||
expect(result[0].selectionsToTrack[0]).toEqual(origSelections[0]);
|
||||
expect(result[1].selectionForEdit.start).toEqual({line: 1, ch: 0});
|
||||
expect(result[1].selectionForEdit.end).toEqual({line: 2, ch: 0});
|
||||
expect(result[1].selectionForEdit.start.line).toEqual(1);
|
||||
expect(result[1].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[1].selectionForEdit.end.line).toEqual(2);
|
||||
expect(result[1].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[1].selectionsToTrack.length).toBe(1);
|
||||
expect(result[1].selectionsToTrack[0]).toEqual(origSelections[1]);
|
||||
expect(result[2].selectionForEdit.start).toEqual({line: 4, ch: 0});
|
||||
expect(result[2].selectionForEdit.end).toEqual({line: 5, ch: 0}); // not expanded since expandEndAtStartOfLine not set
|
||||
expect(result[2].selectionForEdit.start.line).toEqual(4);
|
||||
expect(result[2].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[2].selectionForEdit.end.line).toEqual(5);
|
||||
expect(result[2].selectionForEdit.end.ch).toEqual(0); // not expanded since expandEndAtStartOfLine not set
|
||||
expect(result[2].selectionsToTrack.length).toBe(1);
|
||||
expect(result[2].selectionsToTrack[0]).toEqual(origSelections[2]);
|
||||
});
|
||||
@ -918,8 +1027,10 @@ define(function (require, exports, module) {
|
||||
{start: {line: 2, ch: 0}, end: {line: 3, ch: 0}}],
|
||||
result = myEditor.convertToLineSelections(origSelections, {expandEndAtStartOfLine: true});
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].selectionForEdit.start).toEqual({line: 0, ch: 0});
|
||||
expect(result[0].selectionForEdit.end).toEqual({line: 4, ch: 0});
|
||||
expect(result[0].selectionForEdit.start.line).toEqual(0);
|
||||
expect(result[0].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[0].selectionForEdit.end.line).toEqual(4);
|
||||
expect(result[0].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[0].selectionsToTrack.length).toBe(2);
|
||||
expect(result[0].selectionsToTrack[0]).toEqual(origSelections[0]);
|
||||
expect(result[0].selectionsToTrack[1]).toEqual(origSelections[1]);
|
||||
@ -932,12 +1043,16 @@ define(function (require, exports, module) {
|
||||
{start: {line: 2, ch: 0}, end: {line: 3, ch: 0}}],
|
||||
result = myEditor.convertToLineSelections(origSelections, {expandEndAtStartOfLine: true, mergeAdjacent: false});
|
||||
expect(result.length).toBe(2);
|
||||
expect(result[0].selectionForEdit.start).toEqual({line: 0, ch: 0});
|
||||
expect(result[0].selectionForEdit.end).toEqual({line: 2, ch: 0});
|
||||
expect(result[0].selectionForEdit.start.line).toEqual(0);
|
||||
expect(result[0].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[0].selectionForEdit.end.line).toEqual(2);
|
||||
expect(result[0].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[0].selectionsToTrack.length).toBe(1);
|
||||
expect(result[0].selectionsToTrack[0]).toEqual(origSelections[0]);
|
||||
expect(result[1].selectionForEdit.start).toEqual({line: 2, ch: 0});
|
||||
expect(result[1].selectionForEdit.end).toEqual({line: 4, ch: 0});
|
||||
expect(result[1].selectionForEdit.start.line).toEqual(2);
|
||||
expect(result[1].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[1].selectionForEdit.end.line).toEqual(4);
|
||||
expect(result[1].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[1].selectionsToTrack.length).toBe(1);
|
||||
expect(result[1].selectionsToTrack[0]).toEqual(origSelections[1]);
|
||||
});
|
||||
@ -948,8 +1063,10 @@ define(function (require, exports, module) {
|
||||
{start: {line: 2, ch: 8}, end: {line: 5, ch: 0}}],
|
||||
result = myEditor.convertToLineSelections(origSelections);
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].selectionForEdit.start).toEqual({line: 0, ch: 0});
|
||||
expect(result[0].selectionForEdit.end).toEqual({line: 5, ch: 0});
|
||||
expect(result[0].selectionForEdit.start.line).toEqual(0);
|
||||
expect(result[0].selectionForEdit.start.ch).toEqual(0);
|
||||
expect(result[0].selectionForEdit.end.line).toEqual(5);
|
||||
expect(result[0].selectionForEdit.end.ch).toEqual(0);
|
||||
expect(result[0].selectionsToTrack.length).toBe(3);
|
||||
expect(result[0].selectionsToTrack[0]).toEqual(origSelections[0]);
|
||||
expect(result[0].selectionsToTrack[1]).toEqual(origSelections[1]);
|
||||
@ -979,9 +1096,9 @@ define(function (require, exports, module) {
|
||||
myEditor._handleSoftTabNavigation(dir, command);
|
||||
|
||||
if (Array.isArray(expectedSel)) {
|
||||
expect(myEditor.getSelections()).toEqual(expectedSel);
|
||||
expectSelections(expectedSel);
|
||||
} else {
|
||||
expect(myEditor.getCursorPos()).toEqual(expectedSel);
|
||||
expectCursorAt(expectedSel);
|
||||
}
|
||||
expect(myEditor.document.getText()).toEqual(expectedText);
|
||||
}
|
||||
@ -1373,7 +1490,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content);
|
||||
myEditor.setCursorPos({line: 2, ch: 0});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 8}, end: {line: 2, ch: 8}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 8}, end: {line: 2, ch: 8}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
lines[2] = " ";
|
||||
@ -1389,7 +1506,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content, true);
|
||||
myEditor.setCursorPos({line: 2, ch: 0});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 2}, end: {line: 2, ch: 2}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 2}, end: {line: 2, ch: 2}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
lines[2] = "\t\t";
|
||||
@ -1405,7 +1522,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content);
|
||||
myEditor.setCursorPos({line: 2, ch: 0});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 8}, end: {line: 2, ch: 8}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 8}, end: {line: 2, ch: 8}, reversed: false});
|
||||
|
||||
expect(myEditor.document.getText()).toEqual(content);
|
||||
});
|
||||
@ -1419,7 +1536,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content, true);
|
||||
myEditor.setCursorPos({line: 2, ch: 0});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 2}, end: {line: 2, ch: 2}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 2}, end: {line: 2, ch: 2}, reversed: false});
|
||||
expect(myEditor.document.getText()).toEqual(content);
|
||||
});
|
||||
|
||||
@ -1432,7 +1549,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content);
|
||||
myEditor.setCursorPos({line: 2, ch: 12});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 16}, end: {line: 2, ch: 16}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 16}, end: {line: 2, ch: 16}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
lines[2] = " " + lines[2];
|
||||
@ -1449,7 +1566,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content, true);
|
||||
myEditor.setCursorPos({line: 2, ch: 3});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 4}, end: {line: 2, ch: 4}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 4}, end: {line: 2, ch: 4}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
lines[2] = "\t" + lines[2];
|
||||
@ -1466,7 +1583,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content);
|
||||
myEditor.setCursorPos({line: 2, ch: 2});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 8}, end: {line: 2, ch: 8}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 8}, end: {line: 2, ch: 8}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
lines[2] = " indentme();";
|
||||
@ -1482,7 +1599,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content, true);
|
||||
myEditor.setCursorPos({line: 2, ch: 0});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 2}, end: {line: 2, ch: 2}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 2}, end: {line: 2, ch: 2}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
lines[2] = "\t\tindentme();";
|
||||
@ -1498,7 +1615,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content);
|
||||
myEditor.setCursorPos({line: 1, ch: 8});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 12}, end: {line: 1, ch: 12}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 12}, end: {line: 1, ch: 12}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
lines[1] = " if (bar) {";
|
||||
@ -1514,7 +1631,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content, true);
|
||||
myEditor.setCursorPos({line: 1, ch: 2});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 3}, end: {line: 1, ch: 3}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 3}, end: {line: 1, ch: 3}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
lines[1] = "\t\t\tif (bar) {";
|
||||
@ -1530,7 +1647,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content);
|
||||
myEditor.setCursorPos({line: 2, ch: 4});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 8}, end: {line: 2, ch: 8}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 8}, end: {line: 2, ch: 8}, reversed: false});
|
||||
expect(myEditor.document.getText()).toEqual(content);
|
||||
});
|
||||
|
||||
@ -1543,7 +1660,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content, true);
|
||||
myEditor.setCursorPos({line: 2, ch: 1});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 2}, end: {line: 2, ch: 2}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 2}, end: {line: 2, ch: 2}, reversed: false});
|
||||
expect(myEditor.document.getText()).toEqual(content);
|
||||
});
|
||||
|
||||
@ -1556,7 +1673,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content);
|
||||
myEditor.setCursorPos({line: 2, ch: 8});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 12}, end: {line: 2, ch: 12}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 12}, end: {line: 2, ch: 12}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
lines[2] = " indentme();";
|
||||
@ -1572,7 +1689,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content, true);
|
||||
myEditor.setCursorPos({line: 2, ch: 2});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 3}, end: {line: 2, ch: 3}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 3}, end: {line: 2, ch: 3}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
lines[2] = "\t\t\tindentme();";
|
||||
@ -1589,7 +1706,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content);
|
||||
myEditor.setSelection({line: 1, ch: 6}, {line: 3, ch: 3});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 10}, end: {line: 3, ch: 8}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 10}, end: {line: 3, ch: 8}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
for (i = 1; i <= 3; i++) {
|
||||
@ -1608,7 +1725,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content, true);
|
||||
myEditor.setSelection({line: 1, ch: 0}, {line: 3, ch: 1});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 0}, end: {line: 3, ch: 2}, reversed: false});
|
||||
expectSelection({start: {line: 1, ch: 0}, end: {line: 3, ch: 2}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
for (i = 1; i <= 3; i++) {
|
||||
@ -1626,7 +1743,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content);
|
||||
myEditor.setSelection({line: 2, ch: 9}, {line: 2, ch: 9}); // should add three spaces to get to column 12
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 12}, end: {line: 2, ch: 12}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 12}, end: {line: 2, ch: 12}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
lines[2] = " inden tme();";
|
||||
@ -1642,7 +1759,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content, true);
|
||||
myEditor.setSelection({line: 2, ch: 5}, {line: 2, ch: 5});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 6}, end: {line: 2, ch: 6}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 6}, end: {line: 2, ch: 6}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
lines[2] = "\tinde\tntme();";
|
||||
@ -1658,7 +1775,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content);
|
||||
myEditor.setSelection({line: 2, ch: 9}, {line: 2, ch: 14}); // should add three spaces to get to column 12
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 12}, end: {line: 2, ch: 17}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 12}, end: {line: 2, ch: 17}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
lines[2] = " inden tme();";
|
||||
@ -1674,7 +1791,7 @@ define(function (require, exports, module) {
|
||||
makeEditor(content, true);
|
||||
myEditor.setSelection({line: 2, ch: 5}, {line: 2, ch: 8});
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 6}, end: {line: 2, ch: 9}, reversed: false});
|
||||
expectSelection({start: {line: 2, ch: 6}, end: {line: 2, ch: 9}, reversed: false});
|
||||
|
||||
var lines = content.split("\n");
|
||||
lines[2] = "\tinde\tntme();";
|
||||
@ -1700,7 +1817,7 @@ define(function (require, exports, module) {
|
||||
myEditor.setSelections([{start: {line: 0, ch: 9}, end: {line: 0, ch: 9}, primary: true},
|
||||
{start: {line: 2, ch: 6}, end: {line: 3, ch: 3}}]);
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 13}, end: {line: 0, ch: 13}, primary: true, reversed: false},
|
||||
expectSelections([{start: {line: 0, ch: 13}, end: {line: 0, ch: 13}, primary: true, reversed: false},
|
||||
{start: {line: 2, ch: 10}, end: {line: 3, ch: 8}, primary: false, reversed: false}]);
|
||||
|
||||
var lines = content.split("\n");
|
||||
@ -1720,7 +1837,7 @@ define(function (require, exports, module) {
|
||||
myEditor.setSelections([{start: {line: 0, ch: 6}, end: {line: 0, ch: 6}, primary: true},
|
||||
{start: {line: 2, ch: 3}, end: {line: 3, ch: 1}}]);
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 7}, end: {line: 0, ch: 7}, primary: true, reversed: false},
|
||||
expectSelections([{start: {line: 0, ch: 7}, end: {line: 0, ch: 7}, primary: true, reversed: false},
|
||||
{start: {line: 2, ch: 4}, end: {line: 3, ch: 2}, primary: false, reversed: false}]);
|
||||
|
||||
var lines = content.split("\n");
|
||||
@ -1741,7 +1858,7 @@ define(function (require, exports, module) {
|
||||
{start: {line: 2, ch: 6}, end: {line: 2, ch: 6}},
|
||||
{start: {line: 3, ch: 2}, end: {line: 3, ch: 2}}]);
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 4}, end: {line: 0, ch: 4}, primary: false, reversed: false},
|
||||
expectSelections([{start: {line: 0, ch: 4}, end: {line: 0, ch: 4}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 8}, end: {line: 2, ch: 8}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 4}, end: {line: 3, ch: 4}, primary: true, reversed: false}]);
|
||||
|
||||
@ -1763,7 +1880,7 @@ define(function (require, exports, module) {
|
||||
{start: {line: 2, ch: 6}, end: {line: 2, ch: 6}},
|
||||
{start: {line: 3, ch: 1}, end: {line: 3, ch: 1}}]);
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 4}, end: {line: 0, ch: 4}, primary: false, reversed: false},
|
||||
expectSelections([{start: {line: 0, ch: 4}, end: {line: 0, ch: 4}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 7}, end: {line: 2, ch: 7}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 2}, end: {line: 3, ch: 2}, primary: true, reversed: false}]);
|
||||
|
||||
@ -1785,7 +1902,7 @@ define(function (require, exports, module) {
|
||||
{start: {line: 2, ch: 6}, end: {line: 2, ch: 9}},
|
||||
{start: {line: 3, ch: 2}, end: {line: 3, ch: 4}}]);
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 4}, end: {line: 0, ch: 7}, primary: false, reversed: false},
|
||||
expectSelections([{start: {line: 0, ch: 4}, end: {line: 0, ch: 7}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 8}, end: {line: 2, ch: 11}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 4}, end: {line: 3, ch: 6}, primary: true, reversed: false}]);
|
||||
|
||||
@ -1807,7 +1924,7 @@ define(function (require, exports, module) {
|
||||
{start: {line: 2, ch: 6}, end: {line: 2, ch: 9}},
|
||||
{start: {line: 3, ch: 1}, end: {line: 3, ch: 2}}]);
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 4}, end: {line: 0, ch: 7}, primary: false, reversed: false},
|
||||
expectSelections([{start: {line: 0, ch: 4}, end: {line: 0, ch: 7}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 7}, end: {line: 2, ch: 10}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 2}, end: {line: 3, ch: 3}, primary: true, reversed: false}]);
|
||||
|
||||
@ -1828,7 +1945,7 @@ define(function (require, exports, module) {
|
||||
myEditor.setSelections([{start: {line: 1, ch: 4}, end: {line: 1, ch: 4}, primary: true}, // should not move
|
||||
{start: {line: 2, ch: 4}, end: {line: 2, ch: 4}}]); // should get indented and move
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 1, ch: 8}, end: {line: 1, ch: 8}, primary: true, reversed: false},
|
||||
expectSelections([{start: {line: 1, ch: 8}, end: {line: 1, ch: 8}, primary: true, reversed: false},
|
||||
{start: {line: 2, ch: 8}, end: {line: 2, ch: 8}, primary: false, reversed: false}]);
|
||||
|
||||
var lines = content.split("\n");
|
||||
@ -1847,7 +1964,7 @@ define(function (require, exports, module) {
|
||||
myEditor.setSelections([{start: {line: 1, ch: 1}, end: {line: 1, ch: 1}, primary: true}, // should not move
|
||||
{start: {line: 2, ch: 1}, end: {line: 2, ch: 1}}]); // should get indented and move
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 1, ch: 2}, end: {line: 1, ch: 2}, primary: true, reversed: false},
|
||||
expectSelections([{start: {line: 1, ch: 2}, end: {line: 1, ch: 2}, primary: true, reversed: false},
|
||||
{start: {line: 2, ch: 2}, end: {line: 2, ch: 2}, primary: false, reversed: false}]);
|
||||
|
||||
var lines = content.split("\n");
|
||||
@ -1866,7 +1983,7 @@ define(function (require, exports, module) {
|
||||
myEditor.setSelections([{start: {line: 1, ch: 2}, end: {line: 1, ch: 2}, primary: true}, // should not move
|
||||
{start: {line: 2, ch: 2}, end: {line: 2, ch: 2}}]); // should get indented and move
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 1, ch: 4}, end: {line: 1, ch: 4}, primary: true, reversed: false},
|
||||
expectSelections([{start: {line: 1, ch: 4}, end: {line: 1, ch: 4}, primary: true, reversed: false},
|
||||
{start: {line: 2, ch: 8}, end: {line: 2, ch: 8}, primary: false, reversed: false}]);
|
||||
|
||||
var lines = content.split("\n");
|
||||
@ -1884,7 +2001,7 @@ define(function (require, exports, module) {
|
||||
myEditor.setSelections([{start: {line: 1, ch: 0}, end: {line: 1, ch: 0}, primary: true}, // should not move
|
||||
{start: {line: 2, ch: 0}, end: {line: 2, ch: 0}}]); // should get indented and move
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 1, ch: 1}, end: {line: 1, ch: 1}, primary: true, reversed: false},
|
||||
expectSelections([{start: {line: 1, ch: 1}, end: {line: 1, ch: 1}, primary: true, reversed: false},
|
||||
{start: {line: 2, ch: 2}, end: {line: 2, ch: 2}, primary: false, reversed: false}]);
|
||||
|
||||
var lines = content.split("\n");
|
||||
@ -1902,7 +2019,7 @@ define(function (require, exports, module) {
|
||||
myEditor.setSelections([{start: {line: 1, ch: 4}, end: {line: 1, ch: 4}},
|
||||
{start: {line: 2, ch: 8}, end: {line: 2, ch: 8}}]);
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 1, ch: 8}, end: {line: 1, ch: 8}, primary: false, reversed: false},
|
||||
expectSelections([{start: {line: 1, ch: 8}, end: {line: 1, ch: 8}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 12}, end: {line: 2, ch: 12}, primary: true, reversed: false}]);
|
||||
|
||||
var lines = content.split("\n");
|
||||
@ -1921,7 +2038,7 @@ define(function (require, exports, module) {
|
||||
myEditor.setSelections([{start: {line: 1, ch: 1}, end: {line: 1, ch: 1}},
|
||||
{start: {line: 2, ch: 2}, end: {line: 2, ch: 2}}]);
|
||||
myEditor._handleTabKey();
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 1, ch: 2}, end: {line: 1, ch: 2}, primary: false, reversed: false},
|
||||
expectSelections([{start: {line: 1, ch: 2}, end: {line: 1, ch: 2}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 3}, end: {line: 2, ch: 3}, primary: true, reversed: false}]);
|
||||
|
||||
var lines = content.split("\n");
|
||||
|
@ -91,21 +91,37 @@ define(function (require, exports, module) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Helper functions for testing cursor position / selection range
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
function fixSel(sel) {
|
||||
fixPos(sel.start);
|
||||
fixPos(sel.end);
|
||||
if (!("reversed" in sel)) {
|
||||
sel.reversed = false;
|
||||
}
|
||||
return sel;
|
||||
}
|
||||
function fixSels(sels) {
|
||||
sels.forEach(function (sel) {
|
||||
fixSel(sel);
|
||||
});
|
||||
return sels;
|
||||
}
|
||||
function expectCursorAt(pos) {
|
||||
var selection = myEditor.getSelection();
|
||||
expect(selection.start).toEqual(selection.end);
|
||||
expect(selection.start).toEqual(pos);
|
||||
expect(fixPos(selection.start)).toEqual(fixPos(pos));
|
||||
}
|
||||
function expectSelection(sel) {
|
||||
if (!sel.reversed) {
|
||||
sel.reversed = false;
|
||||
}
|
||||
expect(myEditor.getSelection()).toEqual(sel);
|
||||
expect(fixSel(myEditor.getSelection())).toEqual(fixSel(sel));
|
||||
}
|
||||
function expectSelections(sels) {
|
||||
expect(myEditor.getSelections()).toEqual(sels);
|
||||
expect(fixSels(myEditor.getSelections())).toEqual(fixSels(sels));
|
||||
}
|
||||
function contentWithDeletedLines(lineNums) {
|
||||
var lines = defaultContent.split("\n");
|
||||
@ -1022,8 +1038,10 @@ define(function (require, exports, module) {
|
||||
CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);
|
||||
|
||||
expect(myDocument.getText()).toEqual(defaultContent);
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 1, ch: 4}, end: {line: 1, ch: 4}, reversed: false, primary: false},
|
||||
{start: {line: 3, ch: 4}, end: {line: 3, ch: 4}, reversed: false, primary: true}]);
|
||||
expectSelections([
|
||||
{start: {line: 1, ch: 4}, end: {line: 1, ch: 4}, reversed: false, primary: false},
|
||||
{start: {line: 3, ch: 4}, end: {line: 3, ch: 4}, reversed: false, primary: true}
|
||||
]);
|
||||
});
|
||||
|
||||
it("should properly restore the range selections", function () {
|
||||
@ -1033,8 +1051,10 @@ define(function (require, exports, module) {
|
||||
CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);
|
||||
|
||||
expect(myDocument.getText()).toEqual(defaultContent);
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 1, ch: 4}, end: {line: 1, ch: 6}, reversed: false, primary: false},
|
||||
{start: {line: 3, ch: 4}, end: {line: 3, ch: 6}, reversed: false, primary: true}]);
|
||||
expectSelections([
|
||||
{start: {line: 1, ch: 4}, end: {line: 1, ch: 6}, reversed: false, primary: false},
|
||||
{start: {line: 3, ch: 4}, end: {line: 3, ch: 6}, reversed: false, primary: true}
|
||||
]);
|
||||
});
|
||||
|
||||
it("should properly restore primary/reversed range selections", function () {
|
||||
@ -1044,8 +1064,10 @@ define(function (require, exports, module) {
|
||||
CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);
|
||||
|
||||
expect(myDocument.getText()).toEqual(defaultContent);
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 1, ch: 4}, end: {line: 1, ch: 4}, reversed: false, primary: true},
|
||||
{start: {line: 3, ch: 4}, end: {line: 3, ch: 12}, reversed: true, primary: false}]);
|
||||
expectSelections([
|
||||
{start: {line: 1, ch: 4}, end: {line: 1, ch: 4}, reversed: false, primary: true},
|
||||
{start: {line: 3, ch: 4}, end: {line: 3, ch: 12}, reversed: true, primary: false}
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1460,8 +1482,10 @@ define(function (require, exports, module) {
|
||||
lines.splice(1, 0, "*/");
|
||||
lines.splice(0, 0, "/*");
|
||||
expect(myDocument.getText()).toEqual(lines.join("\n"));
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 1, ch: 0}, end: {line: 2, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 6, ch: 0}, end: {line: 6, ch: 18}, primary: true, reversed: true}]);
|
||||
expectSelections([
|
||||
{start: {line: 1, ch: 0}, end: {line: 2, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 6, ch: 0}, end: {line: 6, ch: 18}, primary: true, reversed: true}
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -3381,9 +3405,11 @@ define(function (require, exports, module) {
|
||||
CommandManager.execute(Commands.EDIT_DELETE_LINES, myEditor);
|
||||
|
||||
expect(myDocument.getText()).toEqual(contentWithDeletedLines([0, 2, 6]));
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 0}, end: {line: 0, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 1, ch: 0}, end: {line: 1, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 0}, end: {line: 4, ch: 0}, primary: true, reversed: false}]);
|
||||
expectSelections([
|
||||
{start: {line: 0, ch: 0}, end: {line: 0, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 1, ch: 0}, end: {line: 1, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 0}, end: {line: 4, ch: 0}, primary: true, reversed: false}
|
||||
]);
|
||||
});
|
||||
|
||||
it("should delete lines containing any range in a multiple selection", function () {
|
||||
@ -3393,9 +3419,11 @@ define(function (require, exports, module) {
|
||||
CommandManager.execute(Commands.EDIT_DELETE_LINES, myEditor);
|
||||
|
||||
expect(myDocument.getText()).toEqual(contentWithDeletedLines([0, 2, 6]));
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 0}, end: {line: 0, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 1, ch: 0}, end: {line: 1, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 0}, end: {line: 4, ch: 0}, primary: true, reversed: false}]);
|
||||
expectSelections([
|
||||
{start: {line: 0, ch: 0}, end: {line: 0, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 1, ch: 0}, end: {line: 1, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 0}, end: {line: 4, ch: 0}, primary: true, reversed: false}
|
||||
]);
|
||||
});
|
||||
|
||||
it("should handle multiple cursors/selections on the same line (only deleting the line once)", function () {
|
||||
@ -3406,9 +3434,11 @@ define(function (require, exports, module) {
|
||||
CommandManager.execute(Commands.EDIT_DELETE_LINES, myEditor);
|
||||
|
||||
expect(myDocument.getText()).toEqual(contentWithDeletedLines([0, 2, 6]));
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 0}, end: {line: 0, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 1, ch: 0}, end: {line: 1, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 0}, end: {line: 4, ch: 0}, primary: true, reversed: false}]);
|
||||
expectSelections([
|
||||
{start: {line: 0, ch: 0}, end: {line: 0, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 1, ch: 0}, end: {line: 1, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 0}, end: {line: 4, ch: 0}, primary: true, reversed: false}
|
||||
]);
|
||||
});
|
||||
|
||||
it("should handle multiple selections that span multiple lines", function () {
|
||||
@ -3417,8 +3447,10 @@ define(function (require, exports, module) {
|
||||
CommandManager.execute(Commands.EDIT_DELETE_LINES, myEditor);
|
||||
|
||||
expect(myDocument.getText()).toEqual(contentWithDeletedLines([0, 1, 3, 4]));
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 0}, end: {line: 0, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 1, ch: 0}, end: {line: 1, ch: 0}, primary: true, reversed: false}]);
|
||||
expectSelections([
|
||||
{start: {line: 0, ch: 0}, end: {line: 0, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 1, ch: 0}, end: {line: 1, ch: 0}, primary: true, reversed: false}
|
||||
]);
|
||||
});
|
||||
|
||||
it("should delete the rest of a selection that starts on a line previously deleted", function () {
|
||||
@ -3427,7 +3459,9 @@ define(function (require, exports, module) {
|
||||
CommandManager.execute(Commands.EDIT_DELETE_LINES, myEditor);
|
||||
|
||||
expect(myDocument.getText()).toEqual(contentWithDeletedLines([0, 1, 2, 3]));
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 0}, end: {line: 0, ch: 0}, primary: true, reversed: false}]);
|
||||
expectSelections([
|
||||
{start: {line: 0, ch: 0}, end: {line: 0, ch: 0}, primary: true, reversed: false}
|
||||
]);
|
||||
});
|
||||
|
||||
it("should merge the primary selection into another selection on the same line", function () {
|
||||
@ -3438,9 +3472,11 @@ define(function (require, exports, module) {
|
||||
CommandManager.execute(Commands.EDIT_DELETE_LINES, myEditor);
|
||||
|
||||
expect(myDocument.getText()).toEqual(contentWithDeletedLines([0, 2, 6]));
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 0}, end: {line: 0, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 1, ch: 0}, end: {line: 1, ch: 0}, primary: true, reversed: false},
|
||||
{start: {line: 4, ch: 0}, end: {line: 4, ch: 0}, primary: false, reversed: false}]);
|
||||
expectSelections([
|
||||
{start: {line: 0, ch: 0}, end: {line: 0, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 1, ch: 0}, end: {line: 1, ch: 0}, primary: true, reversed: false},
|
||||
{start: {line: 4, ch: 0}, end: {line: 4, ch: 0}, primary: false, reversed: false}
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -3503,9 +3539,11 @@ define(function (require, exports, module) {
|
||||
CommandManager.execute(Commands.EDIT_DELETE_LINES, myEditor);
|
||||
|
||||
expect(myDocument.getText()).toEqual(contentWithDeletedLines([1, 3, 6]));
|
||||
expect(myEditor.getSelections()).toEqual([{start: {line: 1, ch: 0}, end: {line: 1, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 0}, end: {line: 2, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 5}, end: {line: 3, ch: 5}, primary: true, reversed: false}]);
|
||||
expectSelections([
|
||||
{start: {line: 1, ch: 0}, end: {line: 1, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 0}, end: {line: 2, ch: 0}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 5}, end: {line: 3, ch: 5}, primary: true, reversed: false}
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -4212,9 +4250,10 @@ define(function (require, exports, module) {
|
||||
});
|
||||
runs(function () {
|
||||
selection = myEditor.getSelection();
|
||||
expect(selection).toEqual({start: {line: 0, ch: 9},
|
||||
end: {line: 0, ch: 15},
|
||||
reversed: false});
|
||||
expect(fixSel(selection)).toEqual(fixSel({
|
||||
start: {line: 0, ch: 9},
|
||||
end: {line: 0, ch: 15}
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -82,6 +82,21 @@ define(function (require, exports, module) {
|
||||
testWindow.closeAllFiles();
|
||||
});
|
||||
|
||||
// Helper functions for testing cursor position / selection range
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
function fixSel(sel) {
|
||||
fixPos(sel.start);
|
||||
fixPos(sel.end);
|
||||
if (!("reversed" in sel)) {
|
||||
sel.reversed = false;
|
||||
}
|
||||
return sel;
|
||||
}
|
||||
|
||||
function checkLineWrapping(editor, firstPos, secondPos, shouldWrap) {
|
||||
runs(function () {
|
||||
@ -419,7 +434,7 @@ define(function (require, exports, module) {
|
||||
checkCloseBraces(editor, {line: 0, ch: 16}, null, CLOSE_BRACKET, "var myContent =[] \"This is awesome!\";");
|
||||
|
||||
runs(function () {
|
||||
expect(editor.getCursorPos()).toEqual({line: 0, ch: 17});
|
||||
expect(fixPos(editor.getCursorPos())).toEqual(fixPos({line: 0, ch: 17}));
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -432,7 +447,7 @@ define(function (require, exports, module) {
|
||||
checkCloseBraces(editor, {line: 0, ch: 16}, {line: 0, ch: 34}, OPEN_BRACKET, "var myContent = [\"This is awesome!\"];");
|
||||
|
||||
runs(function () {
|
||||
expect(editor.getSelection()).toEqual({start: {line: 0, ch: 17}, end: {line: 0, ch: 35}, reversed: false});
|
||||
expect(fixSel(editor.getSelection())).toEqual(fixSel({start: {line: 0, ch: 17}, end: {line: 0, ch: 35}}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -48,6 +48,28 @@ define(function (require, exports, module) {
|
||||
"\n" +
|
||||
"}";
|
||||
|
||||
// Helper functions for testing cursor position / selection range
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
function fixSel(sel) {
|
||||
fixPos(sel.start);
|
||||
fixPos(sel.end);
|
||||
if (!("reversed" in sel)) {
|
||||
sel.reversed = false;
|
||||
}
|
||||
return sel;
|
||||
}
|
||||
function fixSels(sels) {
|
||||
sels.forEach(function (sel) {
|
||||
fixSel(sel);
|
||||
});
|
||||
return sels;
|
||||
}
|
||||
|
||||
describe("FindReplace - Unit", function () {
|
||||
var editor, doc;
|
||||
|
||||
@ -104,59 +126,74 @@ define(function (require, exports, module) {
|
||||
it("should do nothing if the cursor is in non-word/whitespace", function () {
|
||||
editor.setSelection({line: 8, ch: 4});
|
||||
FindReplace._expandWordAndAddNextToSelection(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 8, ch: 4}, end: {line: 8, ch: 4}, primary: true, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 8, ch: 4}, end: {line: 8, ch: 4}, primary: true, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should expand a single cursor to the containing word without adding a new selection", function () {
|
||||
editor.setSelection({line: 2, ch: 26});
|
||||
FindReplace._expandWordAndAddNextToSelection(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 2, ch: 23}, end: {line: 2, ch: 30}, primary: true, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 2, ch: 23}, end: {line: 2, ch: 30}, primary: true, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should add the next match for a single word selection as a new primary selection", function () {
|
||||
editor.setSelection({line: 2, ch: 23}, {line: 2, ch: 30});
|
||||
FindReplace._expandWordAndAddNextToSelection(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 2, ch: 23}, end: {line: 2, ch: 30}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 23}, end: {line: 3, ch: 30}, primary: true, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 2, ch: 23}, end: {line: 2, ch: 30}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 23}, end: {line: 3, ch: 30}, primary: true, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should add the next match for an existing range that isn't actually a word", function () {
|
||||
editor.setSelection({line: 2, ch: 14}, {line: 2, ch: 22}); // "require("
|
||||
FindReplace._expandWordAndAddNextToSelection(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 2, ch: 14}, end: {line: 2, ch: 22}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 22}, primary: true, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 22}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 22}, primary: true, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should find the next match case-insensitively", function () {
|
||||
editor.setSelection({line: 6, ch: 17}, {line: 6, ch: 20}); // "Foo" in "callFoo" - should next find "foo" in "foo()"
|
||||
FindReplace._expandWordAndAddNextToSelection(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 6, ch: 17}, end: {line: 6, ch: 20}, primary: false, reversed: false},
|
||||
{start: {line: 8, ch: 8}, end: {line: 8, ch: 11}, primary: true, reversed: false}]);
|
||||
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 6, ch: 17}, end: {line: 6, ch: 20}, primary: false, reversed: false},
|
||||
{start: {line: 8, ch: 8}, end: {line: 8, ch: 11}, primary: true, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should expand two cursors without adding a new selection", function () {
|
||||
editor.setSelections([{start: {line: 2, ch: 26}, end: {line: 2, ch: 26}},
|
||||
{start: {line: 3, ch: 16}, end: {line: 3, ch: 16}}]);
|
||||
FindReplace._expandWordAndAddNextToSelection(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 2, ch: 23}, end: {line: 2, ch: 30}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: true, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 2, ch: 23}, end: {line: 2, ch: 30}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: true, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should, when one cursor and one range are selected, expand the cursor and add the next match for the range to the selection", function () {
|
||||
editor.setSelections([{start: {line: 2, ch: 26}, end: {line: 2, ch: 26}},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}}]); // "require"
|
||||
FindReplace._expandWordAndAddNextToSelection(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 2, ch: 23}, end: {line: 2, ch: 30}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: true, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 2, ch: 23}, end: {line: 2, ch: 30}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: true, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should wrap around the end of the document and add the next instance at the beginning of the document", function () {
|
||||
editor.setSelection({line: 4, ch: 14}, {line: 4, ch: 21}); // "require"
|
||||
FindReplace._expandWordAndAddNextToSelection(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: true, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: false, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: true, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: false, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should skip over matches that are already in the selection", function () {
|
||||
@ -165,10 +202,12 @@ define(function (require, exports, module) {
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}}]);
|
||||
FindReplace._expandWordAndAddNextToSelection(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: true, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: false, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: true, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: false, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should do nothing if all instances are already selected", function () {
|
||||
@ -177,10 +216,12 @@ define(function (require, exports, module) {
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}}]);
|
||||
FindReplace._expandWordAndAddNextToSelection(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: true, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: true, reversed: false}
|
||||
]));
|
||||
});
|
||||
});
|
||||
|
||||
@ -188,27 +229,35 @@ define(function (require, exports, module) {
|
||||
it("should remove a single range selection and select the next instance", function () {
|
||||
editor.setSelection({line: 2, ch: 23}, {line: 2, ch: 30});
|
||||
FindReplace._expandWordAndAddNextToSelection(editor, true);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 3, ch: 23}, end: {line: 3, ch: 30}, primary: true, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 3, ch: 23}, end: {line: 3, ch: 30}, primary: true, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should expand a single cursor to a range, then change the selection to the next instance of that range", function () {
|
||||
editor.setSelection({line: 2, ch: 26}, {line: 2, ch: 26});
|
||||
FindReplace._expandWordAndAddNextToSelection(editor, true);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 3, ch: 23}, end: {line: 3, ch: 30}, primary: true, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 3, ch: 23}, end: {line: 3, ch: 30}, primary: true, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should, when one cursor and one range are selected, expand the cursor and change the range selection to its next match", function () {
|
||||
editor.setSelections([{start: {line: 2, ch: 26}, end: {line: 2, ch: 26}},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}}]); // "require"
|
||||
FindReplace._expandWordAndAddNextToSelection(editor, true);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 2, ch: 23}, end: {line: 2, ch: 30}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: true, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 2, ch: 23}, end: {line: 2, ch: 30}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: true, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should wrap around the end of the document and switch to the next instance at the beginning of the document", function () {
|
||||
editor.setSelection({line: 4, ch: 14}, {line: 4, ch: 21}); // "require"
|
||||
FindReplace._expandWordAndAddNextToSelection(editor, true);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: true, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: true, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should skip over matches that are already in the selection (but still remove the current one)", function () {
|
||||
@ -217,9 +266,11 @@ define(function (require, exports, module) {
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}}]);
|
||||
FindReplace._expandWordAndAddNextToSelection(editor, true);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: true, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: false, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: true, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: false, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should just remove the primary selection if all instances are already selected", function () {
|
||||
@ -228,9 +279,11 @@ define(function (require, exports, module) {
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}}]);
|
||||
FindReplace._expandWordAndAddNextToSelection(editor, true);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: true, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: true, reversed: false}
|
||||
]));
|
||||
});
|
||||
});
|
||||
|
||||
@ -238,55 +291,67 @@ define(function (require, exports, module) {
|
||||
it("should find all instances of a selected range when first instance is selected, keeping it primary", function () {
|
||||
editor.setSelection({line: 1, ch: 17}, {line: 1, ch: 24});
|
||||
FindReplace._findAllAndSelect(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: true, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: false, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: true, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: false, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should find all instances of a selected range when instance other than first is selected, keeping it primary", function () {
|
||||
editor.setSelection({line: 3, ch: 14}, {line: 3, ch: 21});
|
||||
FindReplace._findAllAndSelect(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: true, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: false, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: true, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: false, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should throw away selections other than the primary selection", function () {
|
||||
editor.setSelections([{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: true},
|
||||
{start: {line: 6, ch: 4}, end: {line: 6, ch: 6}}]);
|
||||
FindReplace._findAllAndSelect(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: true, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: false, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: true, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: false, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should expand cursor to range, then find other instances", function () {
|
||||
editor.setSelection({line: 3, ch: 18}, {line: 3, ch: 18});
|
||||
FindReplace._findAllAndSelect(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: true, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: false, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 1, ch: 17}, end: {line: 1, ch: 24}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 14}, end: {line: 2, ch: 21}, primary: false, reversed: false},
|
||||
{start: {line: 3, ch: 14}, end: {line: 3, ch: 21}, primary: true, reversed: false},
|
||||
{start: {line: 4, ch: 14}, end: {line: 4, ch: 21}, primary: false, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should find all case insensitively", function () {
|
||||
editor.setSelection({line: 8, ch: 10}, {line: 8, ch: 10}); // inside "foo", should also find "Foo"s
|
||||
FindReplace._findAllAndSelect(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 2, ch: 8}, end: {line: 2, ch: 11}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 31}, end: {line: 2, ch: 34}, primary: false, reversed: false},
|
||||
{start: {line: 6, ch: 17}, end: {line: 6, ch: 20}, primary: false, reversed: false},
|
||||
{start: {line: 8, ch: 8}, end: {line: 8, ch: 11}, primary: true, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 2, ch: 8}, end: {line: 2, ch: 11}, primary: false, reversed: false},
|
||||
{start: {line: 2, ch: 31}, end: {line: 2, ch: 34}, primary: false, reversed: false},
|
||||
{start: {line: 6, ch: 17}, end: {line: 6, ch: 20}, primary: false, reversed: false},
|
||||
{start: {line: 8, ch: 8}, end: {line: 8, ch: 11}, primary: true, reversed: false}
|
||||
]));
|
||||
});
|
||||
|
||||
it("should not change the selection if the primary selection is a cursor inside a non-word", function () {
|
||||
editor.setSelections([{start: {line: 1, ch: 4}, end: {line: 1, ch: 10}},
|
||||
{start: {line: 8, ch: 0}, end: {line: 8, ch: 0}}]);
|
||||
FindReplace._findAllAndSelect(editor);
|
||||
expect(editor.getSelections()).toEqual([{start: {line: 1, ch: 4}, end: {line: 1, ch: 10}, primary: false, reversed: false},
|
||||
{start: {line: 8, ch: 0}, end: {line: 8, ch: 0}, primary: true, reversed: false}]);
|
||||
expect(editor.getSelections()).toEqual(fixSels([
|
||||
{start: {line: 1, ch: 4}, end: {line: 1, ch: 10}, primary: false, reversed: false},
|
||||
{start: {line: 8, ch: 0}, end: {line: 8, ch: 0}, primary: true, reversed: false}
|
||||
]));
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -325,7 +390,7 @@ define(function (require, exports, module) {
|
||||
if (!sel.reversed) {
|
||||
sel.reversed = false;
|
||||
}
|
||||
expect(myEditor.getSelection()).toEqual(sel);
|
||||
expect(fixSel(myEditor.getSelection())).toEqual(fixSel(sel));
|
||||
}
|
||||
function expectMatchIndex(index, count) {
|
||||
var matchInfo = StringUtils.format(Strings.FIND_MATCH_INDEX, index + 1, count);
|
||||
@ -346,8 +411,8 @@ define(function (require, exports, module) {
|
||||
selections.forEach(function (location, index) {
|
||||
var textMarker = searchState.marked[index];
|
||||
var markerLocation = textMarker.find();
|
||||
expect(markerLocation.from).toEqual(location.start);
|
||||
expect(markerLocation.to).toEqual(location.end);
|
||||
expect(fixPos(markerLocation.from)).toEqual(fixPos(location.start));
|
||||
expect(fixPos(markerLocation.to)).toEqual(fixPos(location.end));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,14 @@ define(function (require, exports, module) {
|
||||
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
|
||||
Strings = require("strings");
|
||||
|
||||
// Helper functions for testing cursor position / selection range
|
||||
function fixPos(pos) {
|
||||
if (!("sticky" in pos)) {
|
||||
pos.sticky = null;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
describe("InlineEditorProviders", function () {
|
||||
|
||||
this.category = "integration";
|
||||
@ -314,7 +322,7 @@ define(function (require, exports, module) {
|
||||
var inlinePos = inlineWidget.editor.getCursorPos();
|
||||
|
||||
// verify cursor position and displayed range in inline editor
|
||||
expect(inlinePos).toEqual(infos["test1.php"].offsets[0]);
|
||||
expect(fixPos(inlinePos)).toEqual(fixPos(infos["test1.php"].offsets[0]));
|
||||
expect(inlineWidget.editor).toHaveInlineEditorRange(toRange(4, 8));
|
||||
|
||||
inlineWidget = null;
|
||||
@ -329,7 +337,7 @@ define(function (require, exports, module) {
|
||||
var inlinePos = inlineWidget.editor.getCursorPos();
|
||||
|
||||
// verify cursor position in inline editor
|
||||
expect(inlinePos).toEqual(infos["test1.css"].offsets[0]);
|
||||
expect(fixPos(inlinePos)).toEqual(fixPos(infos["test1.css"].offsets[0]));
|
||||
|
||||
inlineWidget = null;
|
||||
});
|
||||
@ -343,7 +351,7 @@ define(function (require, exports, module) {
|
||||
var inlinePos = inlineWidget.editor.getCursorPos();
|
||||
|
||||
// verify cursor position in inline editor
|
||||
expect(inlinePos).toEqual(infos["test1.css"].offsets[0]);
|
||||
expect(fixPos(inlinePos)).toEqual(fixPos(infos["test1.css"].offsets[0]));
|
||||
|
||||
inlineWidget = null;
|
||||
});
|
||||
@ -357,7 +365,7 @@ define(function (require, exports, module) {
|
||||
var inlinePos = inlineWidget.editor.getCursorPos();
|
||||
|
||||
// verify cursor position in inline editor
|
||||
expect(inlinePos).toEqual(infos["test1.css"].offsets[1]);
|
||||
expect(fixPos(inlinePos)).toEqual(fixPos(infos["test1.css"].offsets[1]));
|
||||
|
||||
inlineWidget = null;
|
||||
});
|
||||
@ -371,7 +379,7 @@ define(function (require, exports, module) {
|
||||
var inlinePos = inlineWidget.editor.getCursorPos();
|
||||
|
||||
// verify cursor position in inline editor
|
||||
expect(inlinePos).toEqual(infos["test1.css"].offsets[1]);
|
||||
expect(fixPos(inlinePos)).toEqual(fixPos(infos["test1.css"].offsets[1]));
|
||||
|
||||
inlineWidget = null;
|
||||
});
|
||||
@ -385,7 +393,7 @@ define(function (require, exports, module) {
|
||||
var inlinePos = inlineWidget.editor.getCursorPos();
|
||||
|
||||
// verify cursor position in inline editor
|
||||
expect(inlinePos).toEqual(infos["test1.html"].offsets[11]);
|
||||
expect(fixPos(inlinePos)).toEqual(fixPos(infos["test1.html"].offsets[11]));
|
||||
|
||||
inlineWidget = null;
|
||||
});
|
||||
@ -399,7 +407,7 @@ define(function (require, exports, module) {
|
||||
var inlinePos = inlineWidget.editor.getCursorPos();
|
||||
|
||||
// verify cursor position in inline editor
|
||||
expect(inlinePos).toEqual(infos["test1.css"].offsets[2]);
|
||||
expect(fixPos(inlinePos)).toEqual(fixPos(infos["test1.css"].offsets[2]));
|
||||
|
||||
inlineWidget = null;
|
||||
});
|
||||
@ -444,7 +452,7 @@ define(function (require, exports, module) {
|
||||
var inlinePos = inlineWidget.editor.getCursorPos();
|
||||
|
||||
// verify cursor position in inline editor
|
||||
expect(inlinePos).toEqual(infos["test1.css"].offsets[8]);
|
||||
expect(fixPos(inlinePos)).toEqual(fixPos(infos["test1.css"].offsets[8]));
|
||||
|
||||
inlineWidget = null;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user