Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit da1f4a5

Browse files
committed
Merge pull request #7214 from adobe/nj/fix-unit-tests
Restore original selection behavior and fix up unit tests for recent CM change
2 parents 5c4eac3 + b2447ac commit da1f4a5

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

src/editor/Editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ define(function (require, exports, module) {
11551155
* @param {number} centerOptions Option value, or 0 for no options; one of the BOUNDARY_* constants above.
11561156
*/
11571157
Editor.prototype.setSelections = function (selections, center, centerOptions) {
1158-
var primIndex;
1158+
var primIndex = selections.length - 1;
11591159
this._codeMirror.setSelections(_.map(selections, function (sel, index) {
11601160
if (sel.primary) {
11611161
primIndex = index;

test/spec/Editor-test.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -346,23 +346,23 @@ define(function (require, exports, module) {
346346
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
347347
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
348348
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
349-
]);
349+
], 2);
350350
expect(myEditor.hasSelection()).toBe(false);
351351
});
352352

353353
it("should return true for multiple selections", function () {
354354
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
355355
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
356356
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
357-
]);
357+
], 2);
358358
expect(myEditor.hasSelection()).toBe(true);
359359
});
360360

361361
it("should return true for mixed cursors and selections", function () {
362362
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
363363
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
364364
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
365-
]);
365+
], 2);
366366
expect(myEditor.hasSelection()).toBe(true);
367367
});
368368
});
@@ -390,7 +390,7 @@ define(function (require, exports, module) {
390390
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
391391
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
392392
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
393-
]);
393+
], 2);
394394
expect(myEditor.getCursorPos()).toEqual({line: 2, ch: 1});
395395
expect(myEditor.getCursorPos(false, "start")).toEqual({line: 2, ch: 1});
396396
expect(myEditor.getCursorPos(false, "anchor")).toEqual({line: 2, ch: 1});
@@ -414,7 +414,7 @@ define(function (require, exports, module) {
414414
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
415415
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
416416
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
417-
]);
417+
], 2);
418418
expect(myEditor.getCursorPos()).toEqual({line: 2, ch: 4});
419419
expect(myEditor.getCursorPos(false, "start")).toEqual({line: 2, ch: 1});
420420
expect(myEditor.getCursorPos(false, "anchor")).toEqual({line: 2, ch: 1});
@@ -452,7 +452,7 @@ define(function (require, exports, module) {
452452
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
453453
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
454454
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
455-
]);
455+
], 2);
456456
myEditor.setCursorPos(1, 3);
457457
expect(myEditor.getCursorPos()).toEqual({line: 1, ch: 3});
458458
});
@@ -461,7 +461,7 @@ define(function (require, exports, module) {
461461
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
462462
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
463463
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
464-
]);
464+
], 2);
465465
myEditor.setCursorPos(1, 3);
466466
expect(myEditor.getCursorPos()).toEqual({line: 1, ch: 3});
467467
});
@@ -497,7 +497,7 @@ define(function (require, exports, module) {
497497
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
498498
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
499499
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
500-
]);
500+
], 2);
501501
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 1}, end: {line: 2, ch: 1}, reversed: false});
502502
});
503503

@@ -513,15 +513,15 @@ define(function (require, exports, module) {
513513
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
514514
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
515515
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
516-
]);
516+
], 2);
517517
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 1}, end: {line: 2, ch: 4}, reversed: false});
518518
});
519519

520520
it("should return the default primary selection in the proper order when reversed", function () {
521521
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
522522
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
523523
{anchor: {line: 2, ch: 4}, head: {line: 2, ch: 1}}
524-
]);
524+
], 2);
525525
expect(myEditor.getSelection()).toEqual({start: {line: 2, ch: 1}, end: {line: 2, ch: 4}, reversed: true});
526526
});
527527

@@ -563,7 +563,7 @@ define(function (require, exports, module) {
563563
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
564564
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
565565
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
566-
]);
566+
], 2);
567567
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 0, ch: 1}, reversed: false, primary: false},
568568
{start: {line: 1, ch: 1}, end: {line: 1, ch: 1}, reversed: false, primary: false},
569569
{start: {line: 2, ch: 1}, end: {line: 2, ch: 1}, reversed: false, primary: true}
@@ -574,7 +574,7 @@ define(function (require, exports, module) {
574574
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
575575
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
576576
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
577-
]);
577+
], 2);
578578
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 0, ch: 4}, reversed: false, primary: false},
579579
{start: {line: 1, ch: 1}, end: {line: 1, ch: 4}, reversed: false, primary: false},
580580
{start: {line: 2, ch: 1}, end: {line: 2, ch: 4}, reversed: false, primary: true}
@@ -585,7 +585,7 @@ define(function (require, exports, module) {
585585
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 4}, head: {line: 0, ch: 1}},
586586
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
587587
{anchor: {line: 2, ch: 4}, head: {line: 2, ch: 1}}
588-
]);
588+
], 2);
589589
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 0, ch: 4}, reversed: true, primary: false},
590590
{start: {line: 1, ch: 1}, end: {line: 1, ch: 4}, reversed: false, primary: false},
591591
{start: {line: 2, ch: 1}, end: {line: 2, ch: 4}, reversed: true, primary: true}
@@ -595,7 +595,7 @@ define(function (require, exports, module) {
595595
it("should properly reverse multiline selections whose heads are before their anchors in a multiple selection", function () {
596596
myEditor._codeMirror.setSelections([{anchor: {line: 1, ch: 3}, head: {line: 0, ch: 5}},
597597
{anchor: {line: 4, ch: 4}, head: {line: 3, ch: 1}}
598-
]);
598+
], 1);
599599
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 5}, end: {line: 1, ch: 3}, reversed: true, primary: false},
600600
{start: {line: 3, ch: 1}, end: {line: 4, ch: 4}, reversed: true, primary: true}
601601
]);
@@ -619,7 +619,7 @@ define(function (require, exports, module) {
619619
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 8}, head: {line: 0, ch: 14}},
620620
{anchor: {line: 1, ch: 8}, head: {line: 1, ch: 14}},
621621
{anchor: {line: 2, ch: 8}, head: {line: 2, ch: 14}}
622-
]);
622+
], 2);
623623
expect(myEditor.getSelectedText()).toEqual("line 2");
624624
expect(myEditor.getSelectedText(true)).toEqual("line 0\nline 1\nline 2");
625625
});
@@ -637,7 +637,7 @@ define(function (require, exports, module) {
637637
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 14}, head: {line: 0, ch: 8}},
638638
{anchor: {line: 1, ch: 8}, head: {line: 1, ch: 14}},
639639
{anchor: {line: 2, ch: 14}, head: {line: 2, ch: 8}}
640-
]);
640+
], 2);
641641
expect(myEditor.getSelectedText()).toEqual("line 2");
642642
expect(myEditor.getSelectedText(true)).toEqual("line 0\nline 1\nline 2");
643643
});
@@ -665,7 +665,7 @@ define(function (require, exports, module) {
665665
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
666666
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
667667
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
668-
]);
668+
], 2);
669669
myEditor.setSelection({line: 1, ch: 3}, {line: 2, ch: 5});
670670
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 3}, end: {line: 2, ch: 5}, reversed: false});
671671
});
@@ -674,7 +674,7 @@ define(function (require, exports, module) {
674674
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
675675
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
676676
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
677-
]);
677+
], 2);
678678
myEditor.setSelection({line: 1, ch: 3}, {line: 2, ch: 5});
679679
expect(myEditor.getSelection()).toEqual({start: {line: 1, ch: 3}, end: {line: 2, ch: 5}, reversed: false});
680680
});
@@ -703,7 +703,7 @@ define(function (require, exports, module) {
703703
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 1}},
704704
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 1}},
705705
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 1}}
706-
]);
706+
], 2);
707707
myEditor.setSelections([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}},
708708
{start: {line: 1, ch: 8}, end: {line: 2, ch: 5}}]);
709709
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: false, primary: false},
@@ -715,7 +715,7 @@ define(function (require, exports, module) {
715715
myEditor._codeMirror.setSelections([{anchor: {line: 0, ch: 1}, head: {line: 0, ch: 4}},
716716
{anchor: {line: 1, ch: 1}, head: {line: 1, ch: 4}},
717717
{anchor: {line: 2, ch: 1}, head: {line: 2, ch: 4}}
718-
]);
718+
], 2);
719719
myEditor.setSelections([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}},
720720
{start: {line: 1, ch: 8}, end: {line: 2, ch: 5}}]);
721721
expect(myEditor.getSelections()).toEqual([{start: {line: 0, ch: 1}, end: {line: 1, ch: 3}, reversed: false, primary: false},

0 commit comments

Comments
 (0)