@codemirror/state 6.1.4 → 6.2.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,15 @@
1
+ ## 6.2.1 (2023-05-23)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue that could cause `RangeSet.compare` to miss changes in the set of active ranges around a point range.
6
+
7
+ ## 6.2.0 (2022-12-26)
8
+
9
+ ### New features
10
+
11
+ `EditorSelection.range` now accepts an optional 4th argument to specify the bidi level of the range's head position.
12
+
1
13
  ## 6.1.4 (2022-11-15)
2
14
 
3
15
  ### Bug fixes
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (C) 2018-2021 by Marijn Haverbeke <marijnh@gmail.com> and others
3
+ Copyright (C) 2018-2021 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.cjs CHANGED
@@ -6,10 +6,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
6
6
  The data structure for documents. @nonabstract
7
7
  */
8
8
  class Text {
9
- /**
10
- @internal
11
- */
12
- constructor() { }
13
9
  /**
14
10
  Get the line description around the given position.
15
11
  */
@@ -104,7 +100,8 @@ class Text {
104
100
  return new LineCursor(inner);
105
101
  }
106
102
  /**
107
- @internal
103
+ Return the document as a string, using newline characters to
104
+ separate lines.
108
105
  */
109
106
  toString() { return this.sliceString(0); }
110
107
  /**
@@ -117,6 +114,10 @@ class Text {
117
114
  return lines;
118
115
  }
119
116
  /**
117
+ @internal
118
+ */
119
+ constructor() { }
120
+ /**
120
121
  Create a `Text` instance for the given array of lines.
121
122
  */
122
123
  static of(text) {
@@ -1516,10 +1517,11 @@ class EditorSelection {
1516
1517
  /**
1517
1518
  Create a selection range.
1518
1519
  */
1519
- static range(anchor, head, goalColumn) {
1520
- let goal = (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* RangeFlag.NoGoalColumn */) << 5 /* RangeFlag.GoalColumnOffset */;
1521
- return head < anchor ? SelectionRange.create(head, anchor, 16 /* RangeFlag.Inverted */ | goal | 8 /* RangeFlag.AssocAfter */)
1522
- : SelectionRange.create(anchor, head, goal | (head > anchor ? 4 /* RangeFlag.AssocBefore */ : 0));
1520
+ static range(anchor, head, goalColumn, bidiLevel) {
1521
+ let flags = ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* RangeFlag.NoGoalColumn */) << 5 /* RangeFlag.GoalColumnOffset */) |
1522
+ (bidiLevel == null ? 3 : Math.min(2, bidiLevel));
1523
+ return head < anchor ? SelectionRange.create(head, anchor, 16 /* RangeFlag.Inverted */ | 8 /* RangeFlag.AssocAfter */ | flags)
1524
+ : SelectionRange.create(anchor, head, (head > anchor ? 4 /* RangeFlag.AssocBefore */ : 0) | flags);
1523
1525
  }
1524
1526
  /**
1525
1527
  @internal
@@ -2160,7 +2162,10 @@ class StateEffect {
2160
2162
  is(type) { return this.type == type; }
2161
2163
  /**
2162
2164
  Define a new effect type. The type parameter indicates the type
2163
- of values that his effect holds.
2165
+ of values that his effect holds. It should be a type that
2166
+ doesn't include `undefined`, since that is used in
2167
+ [mapping](https://codemirror.net/6/docs/ref/#state.StateEffect.map) to indicate that an effect is
2168
+ removed.
2164
2169
  */
2165
2170
  static define(spec = {}) {
2166
2171
  return new StateEffectType(spec.map || (v => v));
@@ -3304,8 +3309,7 @@ class RangeSet {
3304
3309
  static compare(oldSets, newSets,
3305
3310
  /**
3306
3311
  This indicates how the underlying data changed between these
3307
- ranges, and is needed to synchronize the iteration. `from` and
3308
- `to` are coordinates in the _new_ space, after these changes.
3312
+ ranges, and is needed to synchronize the iteration.
3309
3313
  */
3310
3314
  textDiff, comparator,
3311
3315
  /**
@@ -3416,6 +3420,18 @@ A range set builder is a data structure that helps build up a
3416
3420
  an array of [`Range`](https://codemirror.net/6/docs/ref/#state.Range) objects.
3417
3421
  */
3418
3422
  class RangeSetBuilder {
3423
+ finishChunk(newArrays) {
3424
+ this.chunks.push(new Chunk(this.from, this.to, this.value, this.maxPoint));
3425
+ this.chunkPos.push(this.chunkStart);
3426
+ this.chunkStart = -1;
3427
+ this.setMaxPoint = Math.max(this.setMaxPoint, this.maxPoint);
3428
+ this.maxPoint = -1;
3429
+ if (newArrays) {
3430
+ this.from = [];
3431
+ this.to = [];
3432
+ this.value = [];
3433
+ }
3434
+ }
3419
3435
  /**
3420
3436
  Create an empty builder.
3421
3437
  */
@@ -3433,18 +3449,6 @@ class RangeSetBuilder {
3433
3449
  this.setMaxPoint = -1;
3434
3450
  this.nextLayer = null;
3435
3451
  }
3436
- finishChunk(newArrays) {
3437
- this.chunks.push(new Chunk(this.from, this.to, this.value, this.maxPoint));
3438
- this.chunkPos.push(this.chunkStart);
3439
- this.chunkStart = -1;
3440
- this.setMaxPoint = Math.max(this.setMaxPoint, this.maxPoint);
3441
- this.maxPoint = -1;
3442
- if (newArrays) {
3443
- this.from = [];
3444
- this.to = [];
3445
- this.value = [];
3446
- }
3447
- }
3448
3452
  /**
3449
3453
  Add a range. Ranges should be added in sorted (by `from` and
3450
3454
  `value.startSide`) order.
@@ -3804,7 +3808,7 @@ function compare(a, startA, b, startB, length, comparator) {
3804
3808
  let end = diff < 0 ? a.to + dPos : b.to, clipEnd = Math.min(end, endB);
3805
3809
  if (a.point || b.point) {
3806
3810
  if (!(a.point && b.point && (a.point == b.point || a.point.eq(b.point)) &&
3807
- sameValues(a.activeForPoint(a.to + dPos), b.activeForPoint(b.to))))
3811
+ sameValues(a.activeForPoint(a.to), b.activeForPoint(b.to))))
3808
3812
  comparator.comparePoint(pos, clipEnd, a.point, b.point);
3809
3813
  }
3810
3814
  else {
package/dist/index.d.ts CHANGED
@@ -85,6 +85,11 @@ declare abstract class Text implements Iterable<string> {
85
85
  */
86
86
  iterLines(from?: number, to?: number): TextIterator;
87
87
  /**
88
+ Return the document as a string, using newline characters to
89
+ separate lines.
90
+ */
91
+ toString(): string;
92
+ /**
88
93
  Convert the document to an array of lines (which can be
89
94
  deserialized again via [`Text.of`](https://codemirror.net/6/docs/ref/#state.Text^of)).
90
95
  */
@@ -252,7 +257,7 @@ plain object describing a change (a deletion, insertion, or
252
257
  replacement, depending on which fields are present), a [change
253
258
  set](https://codemirror.net/6/docs/ref/#state.ChangeSet), or an array of change specs.
254
259
  */
255
- declare type ChangeSpec = {
260
+ type ChangeSpec = {
256
261
  from: number;
257
262
  to?: number;
258
263
  insert?: string | Text;
@@ -476,10 +481,10 @@ declare class EditorSelection {
476
481
  /**
477
482
  Create a selection range.
478
483
  */
479
- static range(anchor: number, head: number, goalColumn?: number): SelectionRange;
484
+ static range(anchor: number, head: number, goalColumn?: number, bidiLevel?: number): SelectionRange;
480
485
  }
481
486
 
482
- declare type FacetConfig<Input, Output> = {
487
+ type FacetConfig<Input, Output> = {
483
488
  /**
484
489
  How to combine the input values into a single output value. When
485
490
  not given, the array of input values becomes the output. This
@@ -559,8 +564,8 @@ declare class Facet<Input, Output = readonly Input[]> {
559
564
  from<T extends Input>(field: StateField<T>): Extension;
560
565
  from<T>(field: StateField<T>, get: (value: T) => Input): Extension;
561
566
  }
562
- declare type Slot<T> = Facet<any, T> | StateField<T> | "doc" | "selection";
563
- declare type StateFieldSpec<Value> = {
567
+ type Slot<T> = Facet<any, T> | StateField<T> | "doc" | "selection";
568
+ type StateFieldSpec<Value> = {
564
569
  /**
565
570
  Creates the initial value for the field when a state is created.
566
571
  */
@@ -635,7 +640,7 @@ providers](https://codemirror.net/6/docs/ref/#state.Facet.of), or objects with a
635
640
  `extension` property. Extensions can be nested in arrays
636
641
  arbitrarily deep—they will be flattened when processed.
637
642
  */
638
- declare type Extension = {
643
+ type Extension = {
639
644
  extension: Extension;
640
645
  } | readonly Extension[];
641
646
  /**
@@ -780,7 +785,10 @@ declare class StateEffect<Value> {
780
785
  is<T>(type: StateEffectType<T>): this is StateEffect<T>;
781
786
  /**
782
787
  Define a new effect type. The type parameter indicates the type
783
- of values that his effect holds.
788
+ of values that his effect holds. It should be a type that
789
+ doesn't include `undefined`, since that is used in
790
+ [mapping](https://codemirror.net/6/docs/ref/#state.StateEffect.map) to indicate that an effect is
791
+ removed.
784
792
  */
785
793
  static define<Value = null>(spec?: StateEffectSpec<Value>): StateEffectType<Value>;
786
794
  /**
@@ -1317,7 +1325,7 @@ Subtype of [`Command`](https://codemirror.net/6/docs/ref/#view.Command) that doe
1317
1325
  to the actual editor view. Mostly useful to define commands that
1318
1326
  can be run and tested outside of a browser environment.
1319
1327
  */
1320
- declare type StateCommand = (target: {
1328
+ type StateCommand = (target: {
1321
1329
  state: EditorState;
1322
1330
  dispatch: (transaction: Transaction) => void;
1323
1331
  }) => boolean;
@@ -1459,7 +1467,7 @@ interface RangeCursor<T> {
1459
1467
  */
1460
1468
  to: number;
1461
1469
  }
1462
- declare type RangeSetUpdate<T extends RangeValue> = {
1470
+ type RangeSetUpdate<T extends RangeValue> = {
1463
1471
  /**
1464
1472
  An array of ranges to add. If given, this should be sorted by
1465
1473
  `from` position and `startSide` unless
@@ -1538,8 +1546,7 @@ declare class RangeSet<T extends RangeValue> {
1538
1546
  static compare<T extends RangeValue>(oldSets: readonly RangeSet<T>[], newSets: readonly RangeSet<T>[],
1539
1547
  /**
1540
1548
  This indicates how the underlying data changed between these
1541
- ranges, and is needed to synchronize the iteration. `from` and
1542
- `to` are coordinates in the _new_ space, after these changes.
1549
+ ranges, and is needed to synchronize the iteration.
1543
1550
  */
1544
1551
  textDiff: ChangeDesc, comparator: RangeComparator<T>,
1545
1552
  /**
package/dist/index.js CHANGED
@@ -2,10 +2,6 @@
2
2
  The data structure for documents. @nonabstract
3
3
  */
4
4
  class Text {
5
- /**
6
- @internal
7
- */
8
- constructor() { }
9
5
  /**
10
6
  Get the line description around the given position.
11
7
  */
@@ -100,7 +96,8 @@ class Text {
100
96
  return new LineCursor(inner);
101
97
  }
102
98
  /**
103
- @internal
99
+ Return the document as a string, using newline characters to
100
+ separate lines.
104
101
  */
105
102
  toString() { return this.sliceString(0); }
106
103
  /**
@@ -113,6 +110,10 @@ class Text {
113
110
  return lines;
114
111
  }
115
112
  /**
113
+ @internal
114
+ */
115
+ constructor() { }
116
+ /**
116
117
  Create a `Text` instance for the given array of lines.
117
118
  */
118
119
  static of(text) {
@@ -1511,10 +1512,11 @@ class EditorSelection {
1511
1512
  /**
1512
1513
  Create a selection range.
1513
1514
  */
1514
- static range(anchor, head, goalColumn) {
1515
- let goal = (goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* RangeFlag.NoGoalColumn */) << 5 /* RangeFlag.GoalColumnOffset */;
1516
- return head < anchor ? SelectionRange.create(head, anchor, 16 /* RangeFlag.Inverted */ | goal | 8 /* RangeFlag.AssocAfter */)
1517
- : SelectionRange.create(anchor, head, goal | (head > anchor ? 4 /* RangeFlag.AssocBefore */ : 0));
1515
+ static range(anchor, head, goalColumn, bidiLevel) {
1516
+ let flags = ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 33554431 /* RangeFlag.NoGoalColumn */) << 5 /* RangeFlag.GoalColumnOffset */) |
1517
+ (bidiLevel == null ? 3 : Math.min(2, bidiLevel));
1518
+ return head < anchor ? SelectionRange.create(head, anchor, 16 /* RangeFlag.Inverted */ | 8 /* RangeFlag.AssocAfter */ | flags)
1519
+ : SelectionRange.create(anchor, head, (head > anchor ? 4 /* RangeFlag.AssocBefore */ : 0) | flags);
1518
1520
  }
1519
1521
  /**
1520
1522
  @internal
@@ -2155,7 +2157,10 @@ class StateEffect {
2155
2157
  is(type) { return this.type == type; }
2156
2158
  /**
2157
2159
  Define a new effect type. The type parameter indicates the type
2158
- of values that his effect holds.
2160
+ of values that his effect holds. It should be a type that
2161
+ doesn't include `undefined`, since that is used in
2162
+ [mapping](https://codemirror.net/6/docs/ref/#state.StateEffect.map) to indicate that an effect is
2163
+ removed.
2159
2164
  */
2160
2165
  static define(spec = {}) {
2161
2166
  return new StateEffectType(spec.map || (v => v));
@@ -3298,8 +3303,7 @@ class RangeSet {
3298
3303
  static compare(oldSets, newSets,
3299
3304
  /**
3300
3305
  This indicates how the underlying data changed between these
3301
- ranges, and is needed to synchronize the iteration. `from` and
3302
- `to` are coordinates in the _new_ space, after these changes.
3306
+ ranges, and is needed to synchronize the iteration.
3303
3307
  */
3304
3308
  textDiff, comparator,
3305
3309
  /**
@@ -3410,6 +3414,18 @@ A range set builder is a data structure that helps build up a
3410
3414
  an array of [`Range`](https://codemirror.net/6/docs/ref/#state.Range) objects.
3411
3415
  */
3412
3416
  class RangeSetBuilder {
3417
+ finishChunk(newArrays) {
3418
+ this.chunks.push(new Chunk(this.from, this.to, this.value, this.maxPoint));
3419
+ this.chunkPos.push(this.chunkStart);
3420
+ this.chunkStart = -1;
3421
+ this.setMaxPoint = Math.max(this.setMaxPoint, this.maxPoint);
3422
+ this.maxPoint = -1;
3423
+ if (newArrays) {
3424
+ this.from = [];
3425
+ this.to = [];
3426
+ this.value = [];
3427
+ }
3428
+ }
3413
3429
  /**
3414
3430
  Create an empty builder.
3415
3431
  */
@@ -3427,18 +3443,6 @@ class RangeSetBuilder {
3427
3443
  this.setMaxPoint = -1;
3428
3444
  this.nextLayer = null;
3429
3445
  }
3430
- finishChunk(newArrays) {
3431
- this.chunks.push(new Chunk(this.from, this.to, this.value, this.maxPoint));
3432
- this.chunkPos.push(this.chunkStart);
3433
- this.chunkStart = -1;
3434
- this.setMaxPoint = Math.max(this.setMaxPoint, this.maxPoint);
3435
- this.maxPoint = -1;
3436
- if (newArrays) {
3437
- this.from = [];
3438
- this.to = [];
3439
- this.value = [];
3440
- }
3441
- }
3442
3446
  /**
3443
3447
  Add a range. Ranges should be added in sorted (by `from` and
3444
3448
  `value.startSide`) order.
@@ -3798,7 +3802,7 @@ function compare(a, startA, b, startB, length, comparator) {
3798
3802
  let end = diff < 0 ? a.to + dPos : b.to, clipEnd = Math.min(end, endB);
3799
3803
  if (a.point || b.point) {
3800
3804
  if (!(a.point && b.point && (a.point == b.point || a.point.eq(b.point)) &&
3801
- sameValues(a.activeForPoint(a.to + dPos), b.activeForPoint(b.to))))
3805
+ sameValues(a.activeForPoint(a.to), b.activeForPoint(b.to))))
3802
3806
  comparator.comparePoint(pos, clipEnd, a.point, b.point);
3803
3807
  }
3804
3808
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/state",
3
- "version": "6.1.4",
3
+ "version": "6.2.1",
4
4
  "description": "Editor state data structures for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",
@@ -12,7 +12,7 @@
12
12
  ],
13
13
  "author": {
14
14
  "name": "Marijn Haverbeke",
15
- "email": "marijnh@gmail.com",
15
+ "email": "marijn@haverbeke.berlin",
16
16
  "url": "http://marijnhaverbeke.nl"
17
17
  },
18
18
  "type": "module",