@codemirror/state 6.3.3 → 6.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## 6.4.1 (2024-02-19)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue that caused widgets at the end of a mark decoration to be rendered in their own separate mark DOM element.
6
+
7
+ ## 6.4.0 (2023-12-28)
8
+
9
+ ### Bug fixes
10
+
11
+ When multiple ranges in a single range set overlap, put the smaller ones inside the bigger ones, so that overlapping decorations don't break up each other's elements when coming from the same source.
12
+
13
+ ### New features
14
+
15
+ Selection and selection range `eq` methods now support an optional argument that makes them also compare by cursor associativity.
16
+
17
+ The `RangeSet.join` function can be used to join multiple range sets together.
18
+
1
19
  ## 6.3.3 (2023-12-06)
2
20
 
3
21
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -1391,8 +1391,9 @@ class SelectionRange {
1391
1391
  /**
1392
1392
  Compare this range to another range.
1393
1393
  */
1394
- eq(other) {
1395
- return this.anchor == other.anchor && this.head == other.head;
1394
+ eq(other, includeAssoc = false) {
1395
+ return this.anchor == other.anchor && this.head == other.head &&
1396
+ (!includeAssoc || !this.empty || this.assoc == other.assoc);
1396
1397
  }
1397
1398
  /**
1398
1399
  Return a JSON-serializable object representing the range.
@@ -1442,14 +1443,17 @@ class EditorSelection {
1442
1443
  return EditorSelection.create(this.ranges.map(r => r.map(change, assoc)), this.mainIndex);
1443
1444
  }
1444
1445
  /**
1445
- Compare this selection to another selection.
1446
+ Compare this selection to another selection. By default, ranges
1447
+ are compared only by position. When `includeAssoc` is true,
1448
+ cursor ranges must also have the same
1449
+ [`assoc`](https://codemirror.net/6/docs/ref/#state.SelectionRange.assoc) value.
1446
1450
  */
1447
- eq(other) {
1451
+ eq(other, includeAssoc = false) {
1448
1452
  if (this.ranges.length != other.ranges.length ||
1449
1453
  this.mainIndex != other.mainIndex)
1450
1454
  return false;
1451
1455
  for (let i = 0; i < this.ranges.length; i++)
1452
- if (!this.ranges[i].eq(other.ranges[i]))
1456
+ if (!this.ranges[i].eq(other.ranges[i], includeAssoc))
1453
1457
  return false;
1454
1458
  return true;
1455
1459
  }
@@ -3392,7 +3396,9 @@ class RangeSet {
3392
3396
  let curTo = Math.min(cursor.to, to);
3393
3397
  if (cursor.point) {
3394
3398
  let active = cursor.activeForPoint(cursor.to);
3395
- let openCount = cursor.pointFrom < from ? active.length + 1 : Math.min(active.length, openRanges);
3399
+ let openCount = cursor.pointFrom < from ? active.length + 1
3400
+ : cursor.point.startSide < 0 ? active.length
3401
+ : Math.min(active.length, openRanges);
3396
3402
  iterator.point(pos, curTo, cursor.point, active, openCount, cursor.pointRank);
3397
3403
  openRanges = Math.min(cursor.openEnd(curTo), active.length);
3398
3404
  }
@@ -3419,6 +3425,19 @@ class RangeSet {
3419
3425
  build.add(range.from, range.to, range.value);
3420
3426
  return build.finish();
3421
3427
  }
3428
+ /**
3429
+ Join an array of range sets into a single set.
3430
+ */
3431
+ static join(sets) {
3432
+ if (!sets.length)
3433
+ return RangeSet.empty;
3434
+ let result = sets[sets.length - 1];
3435
+ for (let i = sets.length - 2; i >= 0; i--) {
3436
+ for (let layer = sets[i]; layer != RangeSet.empty; layer = layer.nextLayer)
3437
+ result = new RangeSet(layer.chunkPos, layer.chunk, result, Math.max(layer.maxPoint, result.maxPoint));
3438
+ }
3439
+ return result;
3440
+ }
3422
3441
  }
3423
3442
  /**
3424
3443
  The empty set of ranges.
@@ -3736,7 +3755,8 @@ class SpanCursor {
3736
3755
  }
3737
3756
  addActive(trackOpen) {
3738
3757
  let i = 0, { value, to, rank } = this.cursor;
3739
- while (i < this.activeRank.length && this.activeRank[i] <= rank)
3758
+ // Organize active marks by rank first, then by size
3759
+ while (i < this.activeRank.length && (rank - this.activeRank[i] || to - this.activeTo[i]) > 0)
3740
3760
  i++;
3741
3761
  insert(this.active, i, value);
3742
3762
  insert(this.activeTo, i, to);
package/dist/index.d.cts CHANGED
@@ -400,7 +400,7 @@ declare class SelectionRange {
400
400
  /**
401
401
  Compare this range to another range.
402
402
  */
403
- eq(other: SelectionRange): boolean;
403
+ eq(other: SelectionRange, includeAssoc?: boolean): boolean;
404
404
  /**
405
405
  Return a JSON-serializable object representing the range.
406
406
  */
@@ -432,9 +432,12 @@ declare class EditorSelection {
432
432
  */
433
433
  map(change: ChangeDesc, assoc?: number): EditorSelection;
434
434
  /**
435
- Compare this selection to another selection.
435
+ Compare this selection to another selection. By default, ranges
436
+ are compared only by position. When `includeAssoc` is true,
437
+ cursor ranges must also have the same
438
+ [`assoc`](https://codemirror.net/6/docs/ref/#state.SelectionRange.assoc) value.
436
439
  */
437
- eq(other: EditorSelection): boolean;
440
+ eq(other: EditorSelection, includeAssoc?: boolean): boolean;
438
441
  /**
439
442
  Get the primary selection range. Usually, you should make sure
440
443
  your code applies to _all_ ranges, by using methods like
@@ -848,7 +851,7 @@ interface TransactionSpec {
848
851
  selection?: EditorSelection | {
849
852
  anchor: number;
850
853
  head?: number;
851
- };
854
+ } | undefined;
852
855
  /**
853
856
  Attach [state effects](https://codemirror.net/6/docs/ref/#state.StateEffect) to this transaction.
854
857
  Again, when they contain positions and this same spec makes
@@ -1604,6 +1607,10 @@ declare class RangeSet<T extends RangeValue> {
1604
1607
  */
1605
1608
  static of<T extends RangeValue>(ranges: readonly Range<T>[] | Range<T>, sort?: boolean): RangeSet<T>;
1606
1609
  /**
1610
+ Join an array of range sets into a single set.
1611
+ */
1612
+ static join<T extends RangeValue>(sets: readonly RangeSet<T>[]): RangeSet<T>;
1613
+ /**
1607
1614
  The empty set of ranges.
1608
1615
  */
1609
1616
  static empty: RangeSet<any>;
@@ -1683,4 +1690,4 @@ situation.
1683
1690
  */
1684
1691
  declare function findColumn(string: string, col: number, tabSize: number, strict?: boolean): number;
1685
1692
 
1686
- export { Annotation, AnnotationType, ChangeDesc, ChangeSet, ChangeSpec, CharCategory, Compartment, EditorSelection, EditorState, EditorStateConfig, Extension, Facet, FacetReader, Line, MapMode, Prec, Range, RangeComparator, RangeCursor, RangeSet, RangeSetBuilder, RangeValue, SelectionRange, SpanIterator, StateCommand, StateEffect, StateEffectType, StateField, Text, TextIterator, Transaction, TransactionSpec, codePointAt, codePointSize, combineConfig, countColumn, findClusterBreak, findColumn, fromCodePoint };
1693
+ export { Annotation, AnnotationType, ChangeDesc, ChangeSet, type ChangeSpec, CharCategory, Compartment, EditorSelection, EditorState, type EditorStateConfig, type Extension, Facet, type FacetReader, Line, MapMode, Prec, Range, type RangeComparator, type RangeCursor, RangeSet, RangeSetBuilder, RangeValue, SelectionRange, type SpanIterator, type StateCommand, StateEffect, StateEffectType, StateField, Text, type TextIterator, Transaction, type TransactionSpec, codePointAt, codePointSize, combineConfig, countColumn, findClusterBreak, findColumn, fromCodePoint };
package/dist/index.d.ts CHANGED
@@ -400,7 +400,7 @@ declare class SelectionRange {
400
400
  /**
401
401
  Compare this range to another range.
402
402
  */
403
- eq(other: SelectionRange): boolean;
403
+ eq(other: SelectionRange, includeAssoc?: boolean): boolean;
404
404
  /**
405
405
  Return a JSON-serializable object representing the range.
406
406
  */
@@ -432,9 +432,12 @@ declare class EditorSelection {
432
432
  */
433
433
  map(change: ChangeDesc, assoc?: number): EditorSelection;
434
434
  /**
435
- Compare this selection to another selection.
435
+ Compare this selection to another selection. By default, ranges
436
+ are compared only by position. When `includeAssoc` is true,
437
+ cursor ranges must also have the same
438
+ [`assoc`](https://codemirror.net/6/docs/ref/#state.SelectionRange.assoc) value.
436
439
  */
437
- eq(other: EditorSelection): boolean;
440
+ eq(other: EditorSelection, includeAssoc?: boolean): boolean;
438
441
  /**
439
442
  Get the primary selection range. Usually, you should make sure
440
443
  your code applies to _all_ ranges, by using methods like
@@ -848,7 +851,7 @@ interface TransactionSpec {
848
851
  selection?: EditorSelection | {
849
852
  anchor: number;
850
853
  head?: number;
851
- };
854
+ } | undefined;
852
855
  /**
853
856
  Attach [state effects](https://codemirror.net/6/docs/ref/#state.StateEffect) to this transaction.
854
857
  Again, when they contain positions and this same spec makes
@@ -1604,6 +1607,10 @@ declare class RangeSet<T extends RangeValue> {
1604
1607
  */
1605
1608
  static of<T extends RangeValue>(ranges: readonly Range<T>[] | Range<T>, sort?: boolean): RangeSet<T>;
1606
1609
  /**
1610
+ Join an array of range sets into a single set.
1611
+ */
1612
+ static join<T extends RangeValue>(sets: readonly RangeSet<T>[]): RangeSet<T>;
1613
+ /**
1607
1614
  The empty set of ranges.
1608
1615
  */
1609
1616
  static empty: RangeSet<any>;
@@ -1683,4 +1690,4 @@ situation.
1683
1690
  */
1684
1691
  declare function findColumn(string: string, col: number, tabSize: number, strict?: boolean): number;
1685
1692
 
1686
- export { Annotation, AnnotationType, ChangeDesc, ChangeSet, ChangeSpec, CharCategory, Compartment, EditorSelection, EditorState, EditorStateConfig, Extension, Facet, FacetReader, Line, MapMode, Prec, Range, RangeComparator, RangeCursor, RangeSet, RangeSetBuilder, RangeValue, SelectionRange, SpanIterator, StateCommand, StateEffect, StateEffectType, StateField, Text, TextIterator, Transaction, TransactionSpec, codePointAt, codePointSize, combineConfig, countColumn, findClusterBreak, findColumn, fromCodePoint };
1693
+ export { Annotation, AnnotationType, ChangeDesc, ChangeSet, type ChangeSpec, CharCategory, Compartment, EditorSelection, EditorState, type EditorStateConfig, type Extension, Facet, type FacetReader, Line, MapMode, Prec, Range, type RangeComparator, type RangeCursor, RangeSet, RangeSetBuilder, RangeValue, SelectionRange, type SpanIterator, type StateCommand, StateEffect, StateEffectType, StateField, Text, type TextIterator, Transaction, type TransactionSpec, codePointAt, codePointSize, combineConfig, countColumn, findClusterBreak, findColumn, fromCodePoint };
package/dist/index.js CHANGED
@@ -1388,8 +1388,9 @@ class SelectionRange {
1388
1388
  /**
1389
1389
  Compare this range to another range.
1390
1390
  */
1391
- eq(other) {
1392
- return this.anchor == other.anchor && this.head == other.head;
1391
+ eq(other, includeAssoc = false) {
1392
+ return this.anchor == other.anchor && this.head == other.head &&
1393
+ (!includeAssoc || !this.empty || this.assoc == other.assoc);
1393
1394
  }
1394
1395
  /**
1395
1396
  Return a JSON-serializable object representing the range.
@@ -1439,14 +1440,17 @@ class EditorSelection {
1439
1440
  return EditorSelection.create(this.ranges.map(r => r.map(change, assoc)), this.mainIndex);
1440
1441
  }
1441
1442
  /**
1442
- Compare this selection to another selection.
1443
+ Compare this selection to another selection. By default, ranges
1444
+ are compared only by position. When `includeAssoc` is true,
1445
+ cursor ranges must also have the same
1446
+ [`assoc`](https://codemirror.net/6/docs/ref/#state.SelectionRange.assoc) value.
1443
1447
  */
1444
- eq(other) {
1448
+ eq(other, includeAssoc = false) {
1445
1449
  if (this.ranges.length != other.ranges.length ||
1446
1450
  this.mainIndex != other.mainIndex)
1447
1451
  return false;
1448
1452
  for (let i = 0; i < this.ranges.length; i++)
1449
- if (!this.ranges[i].eq(other.ranges[i]))
1453
+ if (!this.ranges[i].eq(other.ranges[i], includeAssoc))
1450
1454
  return false;
1451
1455
  return true;
1452
1456
  }
@@ -3388,7 +3392,9 @@ class RangeSet {
3388
3392
  let curTo = Math.min(cursor.to, to);
3389
3393
  if (cursor.point) {
3390
3394
  let active = cursor.activeForPoint(cursor.to);
3391
- let openCount = cursor.pointFrom < from ? active.length + 1 : Math.min(active.length, openRanges);
3395
+ let openCount = cursor.pointFrom < from ? active.length + 1
3396
+ : cursor.point.startSide < 0 ? active.length
3397
+ : Math.min(active.length, openRanges);
3392
3398
  iterator.point(pos, curTo, cursor.point, active, openCount, cursor.pointRank);
3393
3399
  openRanges = Math.min(cursor.openEnd(curTo), active.length);
3394
3400
  }
@@ -3415,6 +3421,19 @@ class RangeSet {
3415
3421
  build.add(range.from, range.to, range.value);
3416
3422
  return build.finish();
3417
3423
  }
3424
+ /**
3425
+ Join an array of range sets into a single set.
3426
+ */
3427
+ static join(sets) {
3428
+ if (!sets.length)
3429
+ return RangeSet.empty;
3430
+ let result = sets[sets.length - 1];
3431
+ for (let i = sets.length - 2; i >= 0; i--) {
3432
+ for (let layer = sets[i]; layer != RangeSet.empty; layer = layer.nextLayer)
3433
+ result = new RangeSet(layer.chunkPos, layer.chunk, result, Math.max(layer.maxPoint, result.maxPoint));
3434
+ }
3435
+ return result;
3436
+ }
3418
3437
  }
3419
3438
  /**
3420
3439
  The empty set of ranges.
@@ -3732,7 +3751,8 @@ class SpanCursor {
3732
3751
  }
3733
3752
  addActive(trackOpen) {
3734
3753
  let i = 0, { value, to, rank } = this.cursor;
3735
- while (i < this.activeRank.length && this.activeRank[i] <= rank)
3754
+ // Organize active marks by rank first, then by size
3755
+ while (i < this.activeRank.length && (rank - this.activeRank[i] || to - this.activeTo[i]) > 0)
3736
3756
  i++;
3737
3757
  insert(this.active, i, value);
3738
3758
  insert(this.activeTo, i, to);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/state",
3
- "version": "6.3.3",
3
+ "version": "6.4.1",
4
4
  "description": "Editor state data structures for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",