Skip to content

Commit 48c305c

Browse files
committed
Fix bug in selection model
Doing shift-left-arrow a few times and then shift-up a few times, you'd get weird jumping selections as you went up.
1 parent e7d8247 commit 48c305c

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

lib/codemirror.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -569,13 +569,10 @@ var CodeMirror = (function() {
569569
// so that you can, for example, press shift-up at the start of
570570
// your selection and have the right thing happen.
571571
if (rs) {
572-
from = sr.start == rs.anchor ? to : from;
573-
to = shiftSelecting ? sel.to : sr.start == rs.anchor ? from : to;
574-
if (!posLess(from, to)) {
575-
reducedSelection = null;
576-
sel.inverted = false;
577-
var tmp = from; from = to; to = tmp;
578-
}
572+
var head = sr.start == rs.anchor ? to : from;
573+
var tail = shiftSelecting ? sel.to : sr.start == rs.anchor ? from : to;
574+
if (sel.inverted = posLess(head, tail)) { from = head; to = tail; }
575+
else { reducedSelection = null; from = tail; to = head; }
579576
}
580577

581578
// In some cases (cursor on same line as before), we don't have
@@ -854,10 +851,9 @@ var CodeMirror = (function() {
854851
if (posEq(sel.from, from) && posEq(sel.to, to)) return;
855852
if (posLess(to, from)) {var tmp = to; to = from; from = tmp;}
856853

857-
var startEq = posEq(sel.to, to), endEq = posEq(sel.from, from);
858854
if (posEq(from, to)) sel.inverted = false;
859-
else if (startEq && !endEq) sel.inverted = true;
860-
else if (endEq && !startEq) sel.inverted = false;
855+
else if (posEq(from, sel.to)) sel.inverted = false;
856+
else if (posEq(to, sel.from)) sel.inverted = true;
861857

862858
// Some ugly logic used to only mark the lines that actually did
863859
// see a change in selection as changed, rather than the whole

0 commit comments

Comments
 (0)