Skip to content

Commit

Permalink
Selection API: addRange() ignores additional Ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
giabao committed Apr 21, 2019
1 parent ebcf31f commit 7a92af1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 4 additions & 6 deletions src/core/internal/wrappedselection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,10 @@ let selectionIsCollapsed =
if (isDirectionBackward(direction) && selectionHasExtend) {
addRangeBackward(this, range);
} else {
var previousRangeCount;
if (features.selectionSupportsMultipleRanges) {
previousRangeCount = this.rangeCount;
} else {
this.removeAllRanges();
previousRangeCount = 0;
const previousRangeCount = this.rangeCount;
if (! features.selectionSupportsMultipleRanges && previousRangeCount > 0) {
// https://www.chromestatus.com/features/6680566019653632
return;
}
// Clone the native range so that changing the selected range does not affect the selection.
// This is contrary to the spec but is the only way to achieve consistency between browsers. See
Expand Down
6 changes: 4 additions & 2 deletions test/core/selection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,11 @@ function testSelectionAndRangeCreators(wins, winName,
// Rangy doesn't do this either because it sometimes needs to change the range boundary points to make
// them valid selection boundaries.
//t.strictEqual(range2, sel.getRangeAt(0));
sel.removeRange(range1);
t.equal(sel.rangeCount, 1);

// https://www.chromestatus.com/features/6680566019653632
sel.removeRange(range2);
t.equal(sel.rangeCount, 1);
sel.removeRange(range1);
t.equal(sel.rangeCount, 0);
rangy.config.checkSelectionRanges = false;
}, setUp_noRangeCheck, tearDown_noRangeCheck);
Expand Down

0 comments on commit 7a92af1

Please sign in to comment.