Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ define(function (require, exports, module) {
* @param {number} centerOptions Option value, or 0 for no options; one of the BOUNDARY_* constants above.
*/
Editor.prototype.setSelections = function (selections, center, centerOptions) {
var primIndex;
var primIndex = selections.length - 1;
this._codeMirror.setSelections(_.map(selections, function (sel, index) {
if (sel.primary) {
primIndex = index;
Expand Down
40 changes: 20 additions & 20 deletions test/spec/Editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,23 +346,23 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
]);
], 2);
expect(myEditor.hasSelection()).toBe(false);
});

it("should return true for multiple selections", function () {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
]);
], 2);
expect(myEditor.hasSelection()).toBe(true);
});

it("should return true for mixed cursors and selections", function () {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
]);
], 2);
expect(myEditor.hasSelection()).toBe(true);
});
});
Expand Down Expand Up @@ -390,7 +390,7 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
{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});
Expand All @@ -414,7 +414,7 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
{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});
Expand Down Expand Up @@ -452,7 +452,7 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
]);
], 2);
myEditor.setCursorPos(1, 3);
expect(myEditor.getCursorPos()).toEqual({line: 1, ch: 3});
});
Expand All @@ -461,7 +461,7 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
]);
], 2);
myEditor.setCursorPos(1, 3);
expect(myEditor.getCursorPos()).toEqual({line: 1, ch: 3});
});
Expand Down Expand Up @@ -497,7 +497,7 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
{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});
});

Expand All @@ -513,15 +513,15 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
{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});
});

it("should return the default primary selection in the proper order when reversed", function () {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
{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});
});

Expand Down Expand Up @@ -563,7 +563,7 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
{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},
{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}
Expand All @@ -574,7 +574,7 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
{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},
{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}
Expand All @@ -585,7 +585,7 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 4}, head: {line: 0, ch: 1}},
{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},
{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}
Expand All @@ -595,7 +595,7 @@ define(function (require, exports, module) {
it("should properly reverse multiline selections whose heads are before their anchors in a multiple selection", function () {
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},
{start: {line: 3, ch: 1}, end: {line: 4, ch: 4}, reversed: true, primary: true}
]);
Expand All @@ -619,7 +619,7 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 8}, head: {line: 0, ch: 14}},
{anchor: {line: 1, ch: 8}, head: {line: 1, ch: 14}},
{anchor: {line: 2, ch: 8}, head: {line: 2, ch: 14}}
]);
], 2);
expect(myEditor.getSelectedText()).toEqual("line 2");
expect(myEditor.getSelectedText(true)).toEqual("line 0\nline 1\nline 2");
});
Expand All @@ -637,7 +637,7 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 14}, head: {line: 0, ch: 8}},
{anchor: {line: 1, ch: 8}, head: {line: 1, ch: 14}},
{anchor: {line: 2, ch: 14}, head: {line: 2, ch: 8}}
]);
], 2);
expect(myEditor.getSelectedText()).toEqual("line 2");
expect(myEditor.getSelectedText(true)).toEqual("line 0\nline 1\nline 2");
});
Expand Down Expand Up @@ -665,7 +665,7 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
{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});
});
Expand All @@ -674,7 +674,7 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
{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});
});
Expand Down Expand Up @@ -703,7 +703,7 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
]);
], 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},
Expand All @@ -715,7 +715,7 @@ define(function (require, exports, module) {
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
]);
], 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},
Expand Down