@codemirror/state 6.5.1 → 6.5.3

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,17 @@
1
+ ## 6.5.3 (2025-12-22)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue where `RangeValue.eq` could get called with a value of a different class.
6
+
7
+ `EditorState.charCategorizer` now only uses the highest-precedence set of word characters from the language data, to allow overriding these.
8
+
9
+ ## 6.5.2 (2025-02-03)
10
+
11
+ ### Bug fixes
12
+
13
+ Fix a bug where reconfiguring a field with a new `init` value didn't update the value of the field.
14
+
1
15
  ## 6.5.1 (2025-01-10)
2
16
 
3
17
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -1777,6 +1777,11 @@ class StateField {
1777
1777
  return 1 /* SlotStatus.Changed */;
1778
1778
  },
1779
1779
  reconfigure: (state, oldState) => {
1780
+ let init = state.facet(initField), oldInit = oldState.facet(initField), reInit;
1781
+ if ((reInit = init.find(i => i.field == this)) && reInit != oldInit.find(i => i.field == this)) {
1782
+ state.values[idx] = reInit.create(state);
1783
+ return 1 /* SlotStatus.Changed */;
1784
+ }
1780
1785
  if (oldState.config.address[this.id] != null) {
1781
1786
  state.values[idx] = oldState.field(this);
1782
1787
  return 0;
@@ -2822,7 +2827,8 @@ class EditorState {
2822
2827
  - Other (anything else)
2823
2828
  */
2824
2829
  charCategorizer(at) {
2825
- return makeCategorizer(this.languageDataAt("wordChars", at).join(""));
2830
+ let chars = this.languageDataAt("wordChars", at);
2831
+ return makeCategorizer(chars.length ? chars[0] : "");
2826
2832
  }
2827
2833
  /**
2828
2834
  Find the word at the given position, meaning the range
@@ -3008,6 +3014,9 @@ class RangeValue {
3008
3014
  RangeValue.prototype.startSide = RangeValue.prototype.endSide = 0;
3009
3015
  RangeValue.prototype.point = false;
3010
3016
  RangeValue.prototype.mapMode = exports.MapMode.TrackDel;
3017
+ function cmpVal(a, b) {
3018
+ return a == b || a.constructor == b.constructor && a.eq(b);
3019
+ }
3011
3020
  /**
3012
3021
  A range associates a value with a range of positions.
3013
3022
  */
@@ -3314,7 +3323,7 @@ class RangeSet {
3314
3323
  for (;;) {
3315
3324
  if (sideA.to != sideB.to ||
3316
3325
  !sameValues(sideA.active, sideB.active) ||
3317
- sideA.point && (!sideB.point || !sideA.point.eq(sideB.point)))
3326
+ sideA.point && (!sideB.point || !cmpVal(sideA.point, sideB.point)))
3318
3327
  return false;
3319
3328
  if (sideA.to > to)
3320
3329
  return true;
@@ -3789,22 +3798,27 @@ function compare(a, startA, b, startB, length, comparator) {
3789
3798
  b.goto(startB);
3790
3799
  let endB = startB + length;
3791
3800
  let pos = startB, dPos = startB - startA;
3792
- for (;;) {
3801
+ let bounds = !!comparator.boundChange;
3802
+ for (let boundChange = false;;) {
3793
3803
  let dEnd = (a.to + dPos) - b.to, diff = dEnd || a.endSide - b.endSide;
3794
3804
  let end = diff < 0 ? a.to + dPos : b.to, clipEnd = Math.min(end, endB);
3795
- if (a.point || b.point) {
3796
- if (!(a.point && b.point && (a.point == b.point || a.point.eq(b.point)) &&
3805
+ let point = a.point || b.point;
3806
+ if (point) {
3807
+ if (!(a.point && b.point && cmpVal(a.point, b.point) &&
3797
3808
  sameValues(a.activeForPoint(a.to), b.activeForPoint(b.to))))
3798
3809
  comparator.comparePoint(pos, clipEnd, a.point, b.point);
3810
+ boundChange = false;
3799
3811
  }
3800
3812
  else {
3813
+ if (boundChange)
3814
+ comparator.boundChange(pos);
3801
3815
  if (clipEnd > pos && !sameValues(a.active, b.active))
3802
3816
  comparator.compareRange(pos, clipEnd, a.active, b.active);
3817
+ if (bounds && clipEnd < endB && (dEnd || a.openEnd(end) != b.openEnd(end)))
3818
+ boundChange = true;
3803
3819
  }
3804
3820
  if (end > endB)
3805
3821
  break;
3806
- if ((dEnd || a.openEnd != b.openEnd) && comparator.boundChange)
3807
- comparator.boundChange(end);
3808
3822
  pos = end;
3809
3823
  if (diff <= 0)
3810
3824
  a.next();
@@ -3816,7 +3830,7 @@ function sameValues(a, b) {
3816
3830
  if (a.length != b.length)
3817
3831
  return false;
3818
3832
  for (let i = 0; i < a.length; i++)
3819
- if (a[i] != b[i] && !a[i].eq(b[i]))
3833
+ if (a[i] != b[i] && !cmpVal(a[i], b[i]))
3820
3834
  return false;
3821
3835
  return true;
3822
3836
  }
package/dist/index.d.cts CHANGED
@@ -221,12 +221,13 @@ declare class ChangeDesc {
221
221
  position pointing into the new document.
222
222
 
223
223
  `assoc` indicates which side the position should be associated
224
- with. When it is negative or zero, the mapping will try to keep
225
- the position close to the character before it (if any), and will
224
+ with. When it is negative, the mapping will try to keep the
225
+ position close to the character before it (if any), and will
226
226
  move it before insertions at that point or replacements across
227
- that point. When it is positive, the position is associated with
228
- the character after it, and will be moved forward for insertions
229
- at or replacements across the position. Defaults to -1.
227
+ that point. When it is zero or positive, the position is associated
228
+ with the character after it, and will be moved forward for
229
+ */
230
+ /**
230
231
 
231
232
  `mode` determines whether deletions should be
232
233
  [reported](https://codemirror.net/6/docs/ref/#state.MapMode). It defaults to
@@ -1488,7 +1489,11 @@ interface RangeCursor<T> {
1488
1489
  /**
1489
1490
  Move the iterator forward.
1490
1491
  */
1491
- next: () => void;
1492
+ next(): void;
1493
+ /**
1494
+ Jump the cursor to the given position.
1495
+ */
1496
+ goto(pos: number): void;
1492
1497
  /**
1493
1498
  The next range's value. Holds `null` when the cursor has reached
1494
1499
  its end.
@@ -1502,6 +1507,11 @@ interface RangeCursor<T> {
1502
1507
  The next end position.
1503
1508
  */
1504
1509
  to: number;
1510
+ /**
1511
+ The position of the set that this range comes from in the array
1512
+ of sets being iterated over.
1513
+ */
1514
+ rank: number;
1505
1515
  }
1506
1516
  type RangeSetUpdate<T extends RangeValue> = {
1507
1517
  /**
package/dist/index.d.ts CHANGED
@@ -221,12 +221,13 @@ declare class ChangeDesc {
221
221
  position pointing into the new document.
222
222
 
223
223
  `assoc` indicates which side the position should be associated
224
- with. When it is negative or zero, the mapping will try to keep
225
- the position close to the character before it (if any), and will
224
+ with. When it is negative, the mapping will try to keep the
225
+ position close to the character before it (if any), and will
226
226
  move it before insertions at that point or replacements across
227
- that point. When it is positive, the position is associated with
228
- the character after it, and will be moved forward for insertions
229
- at or replacements across the position. Defaults to -1.
227
+ that point. When it is zero or positive, the position is associated
228
+ with the character after it, and will be moved forward for
229
+ */
230
+ /**
230
231
 
231
232
  `mode` determines whether deletions should be
232
233
  [reported](https://codemirror.net/6/docs/ref/#state.MapMode). It defaults to
@@ -1488,7 +1489,11 @@ interface RangeCursor<T> {
1488
1489
  /**
1489
1490
  Move the iterator forward.
1490
1491
  */
1491
- next: () => void;
1492
+ next(): void;
1493
+ /**
1494
+ Jump the cursor to the given position.
1495
+ */
1496
+ goto(pos: number): void;
1492
1497
  /**
1493
1498
  The next range's value. Holds `null` when the cursor has reached
1494
1499
  its end.
@@ -1502,6 +1507,11 @@ interface RangeCursor<T> {
1502
1507
  The next end position.
1503
1508
  */
1504
1509
  to: number;
1510
+ /**
1511
+ The position of the set that this range comes from in the array
1512
+ of sets being iterated over.
1513
+ */
1514
+ rank: number;
1505
1515
  }
1506
1516
  type RangeSetUpdate<T extends RangeValue> = {
1507
1517
  /**
package/dist/index.js CHANGED
@@ -1774,6 +1774,11 @@ class StateField {
1774
1774
  return 1 /* SlotStatus.Changed */;
1775
1775
  },
1776
1776
  reconfigure: (state, oldState) => {
1777
+ let init = state.facet(initField), oldInit = oldState.facet(initField), reInit;
1778
+ if ((reInit = init.find(i => i.field == this)) && reInit != oldInit.find(i => i.field == this)) {
1779
+ state.values[idx] = reInit.create(state);
1780
+ return 1 /* SlotStatus.Changed */;
1781
+ }
1777
1782
  if (oldState.config.address[this.id] != null) {
1778
1783
  state.values[idx] = oldState.field(this);
1779
1784
  return 0;
@@ -2818,7 +2823,8 @@ class EditorState {
2818
2823
  - Other (anything else)
2819
2824
  */
2820
2825
  charCategorizer(at) {
2821
- return makeCategorizer(this.languageDataAt("wordChars", at).join(""));
2826
+ let chars = this.languageDataAt("wordChars", at);
2827
+ return makeCategorizer(chars.length ? chars[0] : "");
2822
2828
  }
2823
2829
  /**
2824
2830
  Find the word at the given position, meaning the range
@@ -3004,6 +3010,9 @@ class RangeValue {
3004
3010
  RangeValue.prototype.startSide = RangeValue.prototype.endSide = 0;
3005
3011
  RangeValue.prototype.point = false;
3006
3012
  RangeValue.prototype.mapMode = MapMode.TrackDel;
3013
+ function cmpVal(a, b) {
3014
+ return a == b || a.constructor == b.constructor && a.eq(b);
3015
+ }
3007
3016
  /**
3008
3017
  A range associates a value with a range of positions.
3009
3018
  */
@@ -3310,7 +3319,7 @@ class RangeSet {
3310
3319
  for (;;) {
3311
3320
  if (sideA.to != sideB.to ||
3312
3321
  !sameValues(sideA.active, sideB.active) ||
3313
- sideA.point && (!sideB.point || !sideA.point.eq(sideB.point)))
3322
+ sideA.point && (!sideB.point || !cmpVal(sideA.point, sideB.point)))
3314
3323
  return false;
3315
3324
  if (sideA.to > to)
3316
3325
  return true;
@@ -3785,22 +3794,27 @@ function compare(a, startA, b, startB, length, comparator) {
3785
3794
  b.goto(startB);
3786
3795
  let endB = startB + length;
3787
3796
  let pos = startB, dPos = startB - startA;
3788
- for (;;) {
3797
+ let bounds = !!comparator.boundChange;
3798
+ for (let boundChange = false;;) {
3789
3799
  let dEnd = (a.to + dPos) - b.to, diff = dEnd || a.endSide - b.endSide;
3790
3800
  let end = diff < 0 ? a.to + dPos : b.to, clipEnd = Math.min(end, endB);
3791
- if (a.point || b.point) {
3792
- if (!(a.point && b.point && (a.point == b.point || a.point.eq(b.point)) &&
3801
+ let point = a.point || b.point;
3802
+ if (point) {
3803
+ if (!(a.point && b.point && cmpVal(a.point, b.point) &&
3793
3804
  sameValues(a.activeForPoint(a.to), b.activeForPoint(b.to))))
3794
3805
  comparator.comparePoint(pos, clipEnd, a.point, b.point);
3806
+ boundChange = false;
3795
3807
  }
3796
3808
  else {
3809
+ if (boundChange)
3810
+ comparator.boundChange(pos);
3797
3811
  if (clipEnd > pos && !sameValues(a.active, b.active))
3798
3812
  comparator.compareRange(pos, clipEnd, a.active, b.active);
3813
+ if (bounds && clipEnd < endB && (dEnd || a.openEnd(end) != b.openEnd(end)))
3814
+ boundChange = true;
3799
3815
  }
3800
3816
  if (end > endB)
3801
3817
  break;
3802
- if ((dEnd || a.openEnd != b.openEnd) && comparator.boundChange)
3803
- comparator.boundChange(end);
3804
3818
  pos = end;
3805
3819
  if (diff <= 0)
3806
3820
  a.next();
@@ -3812,7 +3826,7 @@ function sameValues(a, b) {
3812
3826
  if (a.length != b.length)
3813
3827
  return false;
3814
3828
  for (let i = 0; i < a.length; i++)
3815
- if (a[i] != b[i] && !a[i].eq(b[i]))
3829
+ if (a[i] != b[i] && !cmpVal(a[i], b[i]))
3816
3830
  return false;
3817
3831
  return true;
3818
3832
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/state",
3
- "version": "6.5.1",
3
+ "version": "6.5.3",
4
4
  "description": "Editor state data structures for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",