@codemirror/state 6.1.2 → 6.1.4

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.1.4 (2022-11-15)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix a bug that caused the `openStart` value passed to span iterators to be incorrect around widgets in some circumstances.
6
+
7
+ ## 6.1.3 (2022-11-10)
8
+
9
+ ### Bug fixes
10
+
11
+ Avoid unnecessary calls to computed facet getters when a state is reconfigured but no dependencies of the computed facet change.
12
+
13
+ Fix an infinite loop in `RangeSet.eq` when the `to` parameter isn't given.
14
+
1
15
  ## 6.1.2 (2022-09-21)
2
16
 
3
17
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -1664,18 +1664,20 @@ class FacetProvider {
1664
1664
  return 0;
1665
1665
  },
1666
1666
  reconfigure: (state, oldState) => {
1667
- let newVal = getter(state);
1668
- let oldAddr = oldState.config.address[id];
1667
+ let newVal, oldAddr = oldState.config.address[id];
1669
1668
  if (oldAddr != null) {
1670
1669
  let oldVal = getAddr(oldState, oldAddr);
1671
1670
  if (this.dependencies.every(dep => {
1672
1671
  return dep instanceof Facet ? oldState.facet(dep) === state.facet(dep) :
1673
1672
  dep instanceof StateField ? oldState.field(dep, false) == state.field(dep, false) : true;
1674
- }) || (multi ? compareArray(newVal, oldVal, compare) : compare(newVal, oldVal))) {
1673
+ }) || (multi ? compareArray(newVal = getter(state), oldVal, compare) : compare(newVal = getter(state), oldVal))) {
1675
1674
  state.values[idx] = oldVal;
1676
1675
  return 0;
1677
1676
  }
1678
1677
  }
1678
+ else {
1679
+ newVal = getter(state);
1680
+ }
1679
1681
  state.values[idx] = newVal;
1680
1682
  return 1 /* SlotStatus.Changed */;
1681
1683
  }
@@ -2810,6 +2812,18 @@ class EditorState {
2810
2812
  /**
2811
2813
  Find the values for a given language data field, provided by the
2812
2814
  the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.
2815
+
2816
+ Examples of language data fields are...
2817
+
2818
+ - [`"commentTokens"`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) for specifying
2819
+ comment syntax.
2820
+ - [`"autocomplete"`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.override)
2821
+ for providing language-specific completion sources.
2822
+ - [`"wordChars"`](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) for adding
2823
+ characters that should be considered part of words in this
2824
+ language.
2825
+ - [`"closeBrackets"`](https://codemirror.net/6/docs/ref/#autocomplete.CloseBracketConfig) controls
2826
+ bracket closing behavior.
2813
2827
  */
2814
2828
  languageDataAt(name, pos, side = -1) {
2815
2829
  let values = [];
@@ -3314,7 +3328,7 @@ class RangeSet {
3314
3328
  */
3315
3329
  static eq(oldSets, newSets, from = 0, to) {
3316
3330
  if (to == null)
3317
- to = 1000000000 /* C.Far */;
3331
+ to = 1000000000 /* C.Far */ - 1;
3318
3332
  let a = oldSets.filter(set => !set.isEmpty && newSets.indexOf(set) < 0);
3319
3333
  let b = newSets.filter(set => !set.isEmpty && oldSets.indexOf(set) < 0);
3320
3334
  if (a.length != b.length)
@@ -3348,23 +3362,24 @@ class RangeSet {
3348
3362
  */
3349
3363
  minPointSize = -1) {
3350
3364
  let cursor = new SpanCursor(sets, null, minPointSize).goto(from), pos = from;
3351
- let open = cursor.openStart;
3365
+ let openRanges = cursor.openStart;
3352
3366
  for (;;) {
3353
3367
  let curTo = Math.min(cursor.to, to);
3354
3368
  if (cursor.point) {
3355
- iterator.point(pos, curTo, cursor.point, cursor.activeForPoint(cursor.to), open, cursor.pointRank);
3356
- open = cursor.openEnd(curTo) + (cursor.to > curTo ? 1 : 0);
3369
+ let active = cursor.activeForPoint(cursor.to);
3370
+ let openCount = cursor.pointFrom < from ? active.length + 1 : Math.min(active.length, openRanges);
3371
+ iterator.point(pos, curTo, cursor.point, active, openCount, cursor.pointRank);
3372
+ openRanges = Math.min(cursor.openEnd(curTo), active.length);
3357
3373
  }
3358
3374
  else if (curTo > pos) {
3359
- iterator.span(pos, curTo, cursor.active, open);
3360
- open = cursor.openEnd(curTo);
3375
+ iterator.span(pos, curTo, cursor.active, openRanges);
3376
+ openRanges = cursor.openEnd(curTo);
3361
3377
  }
3362
3378
  if (cursor.to > to)
3363
- break;
3379
+ return openRanges + (cursor.point && cursor.to > to ? 1 : 0);
3364
3380
  pos = cursor.to;
3365
3381
  cursor.next();
3366
3382
  }
3367
- return open;
3368
3383
  }
3369
3384
  /**
3370
3385
  Create a range set for the given range or array of ranges. By
@@ -3668,6 +3683,8 @@ class SpanCursor {
3668
3683
  this.pointRank = 0;
3669
3684
  this.to = -1000000000 /* C.Far */;
3670
3685
  this.endSide = 0;
3686
+ // The amount of open active ranges at the start of the iterator.
3687
+ // Not including points.
3671
3688
  this.openStart = -1;
3672
3689
  this.cursor = HeapCursor.from(sets, skip, minPoint);
3673
3690
  }
@@ -3708,7 +3725,7 @@ class SpanCursor {
3708
3725
  next() {
3709
3726
  let from = this.to, wasPoint = this.point;
3710
3727
  this.point = null;
3711
- let trackOpen = this.openStart < 0 ? [] : null, trackExtra = 0;
3728
+ let trackOpen = this.openStart < 0 ? [] : null;
3712
3729
  for (;;) {
3713
3730
  let a = this.minActive;
3714
3731
  if (a > -1 && (this.activeTo[a] - this.cursor.from || this.active[a].endSide - this.cursor.startSide) < 0) {
@@ -3734,8 +3751,6 @@ class SpanCursor {
3734
3751
  let nextVal = this.cursor.value;
3735
3752
  if (!nextVal.point) { // Opening a range
3736
3753
  this.addActive(trackOpen);
3737
- if (this.cursor.from < from && this.cursor.to > from)
3738
- trackExtra++;
3739
3754
  this.cursor.next();
3740
3755
  }
3741
3756
  else if (wasPoint && this.cursor.to == this.to && this.cursor.from < this.cursor.to) {
@@ -3748,8 +3763,6 @@ class SpanCursor {
3748
3763
  this.pointRank = this.cursor.rank;
3749
3764
  this.to = this.cursor.to;
3750
3765
  this.endSide = nextVal.endSide;
3751
- if (this.cursor.from < from)
3752
- trackExtra = 1;
3753
3766
  this.cursor.next();
3754
3767
  this.forward(this.to, this.endSide);
3755
3768
  break;
@@ -3757,10 +3770,9 @@ class SpanCursor {
3757
3770
  }
3758
3771
  }
3759
3772
  if (trackOpen) {
3760
- let openStart = 0;
3761
- while (openStart < trackOpen.length && trackOpen[openStart] < from)
3762
- openStart++;
3763
- this.openStart = openStart + trackExtra;
3773
+ this.openStart = 0;
3774
+ for (let i = trackOpen.length - 1; i >= 0 && trackOpen[i] < from; i--)
3775
+ this.openStart++;
3764
3776
  }
3765
3777
  }
3766
3778
  activeForPoint(to) {
package/dist/index.d.ts CHANGED
@@ -1228,6 +1228,18 @@ declare class EditorState {
1228
1228
  /**
1229
1229
  Find the values for a given language data field, provided by the
1230
1230
  the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.
1231
+
1232
+ Examples of language data fields are...
1233
+
1234
+ - [`"commentTokens"`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) for specifying
1235
+ comment syntax.
1236
+ - [`"autocomplete"`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.override)
1237
+ for providing language-specific completion sources.
1238
+ - [`"wordChars"`](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) for adding
1239
+ characters that should be considered part of words in this
1240
+ language.
1241
+ - [`"closeBrackets"`](https://codemirror.net/6/docs/ref/#autocomplete.CloseBracketConfig) controls
1242
+ bracket closing behavior.
1231
1243
  */
1232
1244
  languageDataAt<T>(name: string, pos: number, side?: -1 | 0 | 1): readonly T[];
1233
1245
  /**
package/dist/index.js CHANGED
@@ -1659,18 +1659,20 @@ class FacetProvider {
1659
1659
  return 0;
1660
1660
  },
1661
1661
  reconfigure: (state, oldState) => {
1662
- let newVal = getter(state);
1663
- let oldAddr = oldState.config.address[id];
1662
+ let newVal, oldAddr = oldState.config.address[id];
1664
1663
  if (oldAddr != null) {
1665
1664
  let oldVal = getAddr(oldState, oldAddr);
1666
1665
  if (this.dependencies.every(dep => {
1667
1666
  return dep instanceof Facet ? oldState.facet(dep) === state.facet(dep) :
1668
1667
  dep instanceof StateField ? oldState.field(dep, false) == state.field(dep, false) : true;
1669
- }) || (multi ? compareArray(newVal, oldVal, compare) : compare(newVal, oldVal))) {
1668
+ }) || (multi ? compareArray(newVal = getter(state), oldVal, compare) : compare(newVal = getter(state), oldVal))) {
1670
1669
  state.values[idx] = oldVal;
1671
1670
  return 0;
1672
1671
  }
1673
1672
  }
1673
+ else {
1674
+ newVal = getter(state);
1675
+ }
1674
1676
  state.values[idx] = newVal;
1675
1677
  return 1 /* SlotStatus.Changed */;
1676
1678
  }
@@ -2804,6 +2806,18 @@ class EditorState {
2804
2806
  /**
2805
2807
  Find the values for a given language data field, provided by the
2806
2808
  the [`languageData`](https://codemirror.net/6/docs/ref/#state.EditorState^languageData) facet.
2809
+
2810
+ Examples of language data fields are...
2811
+
2812
+ - [`"commentTokens"`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) for specifying
2813
+ comment syntax.
2814
+ - [`"autocomplete"`](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion^config.override)
2815
+ for providing language-specific completion sources.
2816
+ - [`"wordChars"`](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) for adding
2817
+ characters that should be considered part of words in this
2818
+ language.
2819
+ - [`"closeBrackets"`](https://codemirror.net/6/docs/ref/#autocomplete.CloseBracketConfig) controls
2820
+ bracket closing behavior.
2807
2821
  */
2808
2822
  languageDataAt(name, pos, side = -1) {
2809
2823
  let values = [];
@@ -3308,7 +3322,7 @@ class RangeSet {
3308
3322
  */
3309
3323
  static eq(oldSets, newSets, from = 0, to) {
3310
3324
  if (to == null)
3311
- to = 1000000000 /* C.Far */;
3325
+ to = 1000000000 /* C.Far */ - 1;
3312
3326
  let a = oldSets.filter(set => !set.isEmpty && newSets.indexOf(set) < 0);
3313
3327
  let b = newSets.filter(set => !set.isEmpty && oldSets.indexOf(set) < 0);
3314
3328
  if (a.length != b.length)
@@ -3342,23 +3356,24 @@ class RangeSet {
3342
3356
  */
3343
3357
  minPointSize = -1) {
3344
3358
  let cursor = new SpanCursor(sets, null, minPointSize).goto(from), pos = from;
3345
- let open = cursor.openStart;
3359
+ let openRanges = cursor.openStart;
3346
3360
  for (;;) {
3347
3361
  let curTo = Math.min(cursor.to, to);
3348
3362
  if (cursor.point) {
3349
- iterator.point(pos, curTo, cursor.point, cursor.activeForPoint(cursor.to), open, cursor.pointRank);
3350
- open = cursor.openEnd(curTo) + (cursor.to > curTo ? 1 : 0);
3363
+ let active = cursor.activeForPoint(cursor.to);
3364
+ let openCount = cursor.pointFrom < from ? active.length + 1 : Math.min(active.length, openRanges);
3365
+ iterator.point(pos, curTo, cursor.point, active, openCount, cursor.pointRank);
3366
+ openRanges = Math.min(cursor.openEnd(curTo), active.length);
3351
3367
  }
3352
3368
  else if (curTo > pos) {
3353
- iterator.span(pos, curTo, cursor.active, open);
3354
- open = cursor.openEnd(curTo);
3369
+ iterator.span(pos, curTo, cursor.active, openRanges);
3370
+ openRanges = cursor.openEnd(curTo);
3355
3371
  }
3356
3372
  if (cursor.to > to)
3357
- break;
3373
+ return openRanges + (cursor.point && cursor.to > to ? 1 : 0);
3358
3374
  pos = cursor.to;
3359
3375
  cursor.next();
3360
3376
  }
3361
- return open;
3362
3377
  }
3363
3378
  /**
3364
3379
  Create a range set for the given range or array of ranges. By
@@ -3662,6 +3677,8 @@ class SpanCursor {
3662
3677
  this.pointRank = 0;
3663
3678
  this.to = -1000000000 /* C.Far */;
3664
3679
  this.endSide = 0;
3680
+ // The amount of open active ranges at the start of the iterator.
3681
+ // Not including points.
3665
3682
  this.openStart = -1;
3666
3683
  this.cursor = HeapCursor.from(sets, skip, minPoint);
3667
3684
  }
@@ -3702,7 +3719,7 @@ class SpanCursor {
3702
3719
  next() {
3703
3720
  let from = this.to, wasPoint = this.point;
3704
3721
  this.point = null;
3705
- let trackOpen = this.openStart < 0 ? [] : null, trackExtra = 0;
3722
+ let trackOpen = this.openStart < 0 ? [] : null;
3706
3723
  for (;;) {
3707
3724
  let a = this.minActive;
3708
3725
  if (a > -1 && (this.activeTo[a] - this.cursor.from || this.active[a].endSide - this.cursor.startSide) < 0) {
@@ -3728,8 +3745,6 @@ class SpanCursor {
3728
3745
  let nextVal = this.cursor.value;
3729
3746
  if (!nextVal.point) { // Opening a range
3730
3747
  this.addActive(trackOpen);
3731
- if (this.cursor.from < from && this.cursor.to > from)
3732
- trackExtra++;
3733
3748
  this.cursor.next();
3734
3749
  }
3735
3750
  else if (wasPoint && this.cursor.to == this.to && this.cursor.from < this.cursor.to) {
@@ -3742,8 +3757,6 @@ class SpanCursor {
3742
3757
  this.pointRank = this.cursor.rank;
3743
3758
  this.to = this.cursor.to;
3744
3759
  this.endSide = nextVal.endSide;
3745
- if (this.cursor.from < from)
3746
- trackExtra = 1;
3747
3760
  this.cursor.next();
3748
3761
  this.forward(this.to, this.endSide);
3749
3762
  break;
@@ -3751,10 +3764,9 @@ class SpanCursor {
3751
3764
  }
3752
3765
  }
3753
3766
  if (trackOpen) {
3754
- let openStart = 0;
3755
- while (openStart < trackOpen.length && trackOpen[openStart] < from)
3756
- openStart++;
3757
- this.openStart = openStart + trackExtra;
3767
+ this.openStart = 0;
3768
+ for (let i = trackOpen.length - 1; i >= 0 && trackOpen[i] < from; i--)
3769
+ this.openStart++;
3758
3770
  }
3759
3771
  }
3760
3772
  activeForPoint(to) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/state",
3
- "version": "6.1.2",
3
+ "version": "6.1.4",
4
4
  "description": "Editor state data structures for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",