@codemirror/rangeset
Advanced tools
Comparing version 0.18.2 to 0.18.3
@@ -0,1 +1,7 @@ | ||
## 0.18.3 (2021-06-03) | ||
### New features | ||
The new static `RangeSet.eq` method can be used to efficiently check whether two groups of change sets differ in a given range. | ||
## 0.18.2 (2021-05-27) | ||
@@ -2,0 +8,0 @@ |
@@ -206,2 +206,7 @@ import { MapMode, ChangeDesc } from '@codemirror/state'; | ||
/** | ||
Compare the contents of two groups of range sets, returning true | ||
if they are equivalent in the given range. | ||
*/ | ||
static eq<T extends RangeValue>(oldSets: readonly RangeSet<T>[], newSets: readonly RangeSet<T>[], from?: number, to?: number): boolean; | ||
/** | ||
Iterate over a group of range sets at the same time, notifying | ||
@@ -208,0 +213,0 @@ the iterator about the ranges covering every given piece of |
@@ -158,3 +158,3 @@ import { MapMode } from '@codemirror/state'; | ||
get size() { | ||
if (this == RangeSet.empty) | ||
if (this.isEmpty) | ||
return 0; | ||
@@ -188,3 +188,3 @@ let size = this.nextLayer.size; | ||
add.slice().sort(cmpRange); | ||
if (this == RangeSet.empty) | ||
if (this.isEmpty) | ||
return add.length ? RangeSet.of(add) : this; | ||
@@ -213,3 +213,3 @@ let cur = new LayerCursor(this, null, -1).goto(0), i = 0, spill = []; | ||
} | ||
return builder.finishInner(this.nextLayer == RangeSet.empty && !spill.length ? RangeSet.empty | ||
return builder.finishInner(this.nextLayer.isEmpty && !spill.length ? RangeSet.empty | ||
: this.nextLayer.update({ add: spill, filter, filterFrom, filterTo })); | ||
@@ -221,3 +221,3 @@ } | ||
map(changes) { | ||
if (changes.length == 0 || this == RangeSet.empty) | ||
if (changes.length == 0 || this.isEmpty) | ||
return this; | ||
@@ -252,3 +252,3 @@ let chunks = [], chunkPos = [], maxPoint = -1; | ||
between(from, to, f) { | ||
if (this == RangeSet.empty) | ||
if (this.isEmpty) | ||
return; | ||
@@ -271,2 +271,6 @@ for (let i = 0; i < this.chunk.length; i++) { | ||
/** | ||
@internal | ||
*/ | ||
get isEmpty() { return this.nextLayer == this; } | ||
/** | ||
Iterate over the ranges in a collection of sets, in order, | ||
@@ -295,5 +299,5 @@ starting from `from`. | ||
let a = oldSets.filter(set => set.maxPoint >= 500 /* BigPointSize */ || | ||
set != RangeSet.empty && newSets.indexOf(set) < 0 && set.maxPoint >= minPointSize); | ||
!set.isEmpty && newSets.indexOf(set) < 0 && set.maxPoint >= minPointSize); | ||
let b = newSets.filter(set => set.maxPoint >= 500 /* BigPointSize */ || | ||
set != RangeSet.empty && oldSets.indexOf(set) < 0 && set.maxPoint >= minPointSize); | ||
!set.isEmpty && oldSets.indexOf(set) < 0 && set.maxPoint >= minPointSize); | ||
let sharedChunks = findSharedChunks(a, b); | ||
@@ -307,2 +311,28 @@ let sideA = new SpanCursor(a, sharedChunks, minPointSize); | ||
/** | ||
Compare the contents of two groups of range sets, returning true | ||
if they are equivalent in the given range. | ||
*/ | ||
static eq(oldSets, newSets, from = 0, to) { | ||
if (to == null) | ||
to = 1000000000 /* Far */; | ||
let a = oldSets.filter(set => !set.isEmpty && newSets.indexOf(set) < 0); | ||
let b = newSets.filter(set => !set.isEmpty && oldSets.indexOf(set) < 0); | ||
if (a.length != b.length) | ||
return false; | ||
if (!a.length) | ||
return true; | ||
let sharedChunks = findSharedChunks(a, b); | ||
let sideA = new SpanCursor(a, sharedChunks, 0).goto(from), sideB = new SpanCursor(b, sharedChunks, 0).goto(from); | ||
for (;;) { | ||
if (sideA.to != sideB.to || | ||
!sameValues(sideA.active, sideB.active) || | ||
sideA.point && (!sideB.point || !sideA.point.eq(sideB.point))) | ||
return false; | ||
if (sideA.to >= to) | ||
return true; | ||
sideA.next(); | ||
sideB.next(); | ||
} | ||
} | ||
/** | ||
Iterate over a group of range sets at the same time, notifying | ||
@@ -548,3 +578,3 @@ the iterator about the ranges covering every given piece of | ||
for (let i = 0; i < sets.length; i++) { | ||
for (let cur = sets[i]; cur != RangeSet.empty; cur = cur.nextLayer) { | ||
for (let cur = sets[i]; !cur.isEmpty; cur = cur.nextLayer) { | ||
if (cur.maxPoint >= minPoint) | ||
@@ -551,0 +581,0 @@ heap.push(new LayerCursor(cur, skip, minPoint, i)); |
{ | ||
"name": "@codemirror/rangeset", | ||
"version": "0.18.2", | ||
"version": "0.18.3", | ||
"description": "Range set data structure for the CodeMirror code editor", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71520
1883