@codemirror/state 6.5.3 → 6.6.0

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.6.0 (2026-03-12)
2
+
3
+ ### New features
4
+
5
+ `EditorSelection.range` now takes an optional `assoc` argument.
6
+
7
+ `SelectionRange.extend` can now be given a third argument to specify associativity.
8
+
9
+ ## 6.5.4 (2026-01-14)
10
+
11
+ ### Bug fixes
12
+
13
+ Make `SelectionRange.eq` return false when the ranges have different goal columns.
14
+
1
15
  ## 6.5.3 (2025-12-22)
2
16
 
3
17
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -1327,17 +1327,17 @@ class SelectionRange {
1327
1327
  /**
1328
1328
  Extend this range to cover at least `from` to `to`.
1329
1329
  */
1330
- extend(from, to = from) {
1330
+ extend(from, to = from, assoc = 0) {
1331
1331
  if (from <= this.anchor && to >= this.anchor)
1332
- return EditorSelection.range(from, to);
1332
+ return EditorSelection.range(from, to, undefined, undefined, assoc);
1333
1333
  let head = Math.abs(from - this.anchor) > Math.abs(to - this.anchor) ? from : to;
1334
- return EditorSelection.range(this.anchor, head);
1334
+ return EditorSelection.range(this.anchor, head, undefined, undefined, assoc);
1335
1335
  }
1336
1336
  /**
1337
1337
  Compare this range to another range.
1338
1338
  */
1339
1339
  eq(other, includeAssoc = false) {
1340
- return this.anchor == other.anchor && this.head == other.head &&
1340
+ return this.anchor == other.anchor && this.head == other.head && this.goalColumn == other.goalColumn &&
1341
1341
  (!includeAssoc || !this.empty || this.assoc == other.assoc);
1342
1342
  }
1343
1343
  /**
@@ -1478,11 +1478,13 @@ class EditorSelection {
1478
1478
  /**
1479
1479
  Create a selection range.
1480
1480
  */
1481
- static range(anchor, head, goalColumn, bidiLevel) {
1481
+ static range(anchor, head, goalColumn, bidiLevel, assoc) {
1482
1482
  let flags = ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215 /* RangeFlag.NoGoalColumn */) << 6 /* RangeFlag.GoalColumnOffset */) |
1483
1483
  (bidiLevel == null ? 7 : Math.min(6, bidiLevel));
1484
+ if (!assoc && anchor != head)
1485
+ assoc = head < anchor ? 1 : -1;
1484
1486
  return head < anchor ? SelectionRange.create(head, anchor, 32 /* RangeFlag.Inverted */ | 16 /* RangeFlag.AssocAfter */ | flags)
1485
- : SelectionRange.create(anchor, head, (head > anchor ? 8 /* RangeFlag.AssocBefore */ : 0) | flags);
1487
+ : SelectionRange.create(anchor, head, (!assoc ? 0 : assoc < 0 ? 8 /* RangeFlag.AssocBefore */ : 16 /* RangeFlag.AssocAfter */) | flags);
1486
1488
  }
1487
1489
  /**
1488
1490
  @internal
package/dist/index.d.cts CHANGED
@@ -400,7 +400,7 @@ declare class SelectionRange {
400
400
  /**
401
401
  Extend this range to cover at least `from` to `to`.
402
402
  */
403
- extend(from: number, to?: number): SelectionRange;
403
+ extend(from: number, to?: number, assoc?: number): SelectionRange;
404
404
  /**
405
405
  Compare this range to another range.
406
406
  */
@@ -488,7 +488,7 @@ declare class EditorSelection {
488
488
  /**
489
489
  Create a selection range.
490
490
  */
491
- static range(anchor: number, head: number, goalColumn?: number, bidiLevel?: number): SelectionRange;
491
+ static range(anchor: number, head: number, goalColumn?: number, bidiLevel?: number, assoc?: number): SelectionRange;
492
492
  }
493
493
 
494
494
  type FacetConfig<Input, Output> = {
@@ -1258,9 +1258,9 @@ declare class EditorState {
1258
1258
  A facet used to register [language
1259
1259
  data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) providers.
1260
1260
  */
1261
- static languageData: Facet<(state: EditorState, pos: number, side: 0 | 1 | -1) => readonly {
1261
+ static languageData: Facet<(state: EditorState, pos: number, side: -1 | 0 | 1) => readonly {
1262
1262
  [name: string]: any;
1263
- }[], readonly ((state: EditorState, pos: number, side: 0 | 1 | -1) => readonly {
1263
+ }[], readonly ((state: EditorState, pos: number, side: -1 | 0 | 1) => readonly {
1264
1264
  [name: string]: any;
1265
1265
  }[])[]>;
1266
1266
  /**
package/dist/index.d.ts CHANGED
@@ -400,7 +400,7 @@ declare class SelectionRange {
400
400
  /**
401
401
  Extend this range to cover at least `from` to `to`.
402
402
  */
403
- extend(from: number, to?: number): SelectionRange;
403
+ extend(from: number, to?: number, assoc?: number): SelectionRange;
404
404
  /**
405
405
  Compare this range to another range.
406
406
  */
@@ -488,7 +488,7 @@ declare class EditorSelection {
488
488
  /**
489
489
  Create a selection range.
490
490
  */
491
- static range(anchor: number, head: number, goalColumn?: number, bidiLevel?: number): SelectionRange;
491
+ static range(anchor: number, head: number, goalColumn?: number, bidiLevel?: number, assoc?: number): SelectionRange;
492
492
  }
493
493
 
494
494
  type FacetConfig<Input, Output> = {
@@ -1258,9 +1258,9 @@ declare class EditorState {
1258
1258
  A facet used to register [language
1259
1259
  data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt) providers.
1260
1260
  */
1261
- static languageData: Facet<(state: EditorState, pos: number, side: 0 | 1 | -1) => readonly {
1261
+ static languageData: Facet<(state: EditorState, pos: number, side: -1 | 0 | 1) => readonly {
1262
1262
  [name: string]: any;
1263
- }[], readonly ((state: EditorState, pos: number, side: 0 | 1 | -1) => readonly {
1263
+ }[], readonly ((state: EditorState, pos: number, side: -1 | 0 | 1) => readonly {
1264
1264
  [name: string]: any;
1265
1265
  }[])[]>;
1266
1266
  /**
package/dist/index.js CHANGED
@@ -1324,17 +1324,17 @@ class SelectionRange {
1324
1324
  /**
1325
1325
  Extend this range to cover at least `from` to `to`.
1326
1326
  */
1327
- extend(from, to = from) {
1327
+ extend(from, to = from, assoc = 0) {
1328
1328
  if (from <= this.anchor && to >= this.anchor)
1329
- return EditorSelection.range(from, to);
1329
+ return EditorSelection.range(from, to, undefined, undefined, assoc);
1330
1330
  let head = Math.abs(from - this.anchor) > Math.abs(to - this.anchor) ? from : to;
1331
- return EditorSelection.range(this.anchor, head);
1331
+ return EditorSelection.range(this.anchor, head, undefined, undefined, assoc);
1332
1332
  }
1333
1333
  /**
1334
1334
  Compare this range to another range.
1335
1335
  */
1336
1336
  eq(other, includeAssoc = false) {
1337
- return this.anchor == other.anchor && this.head == other.head &&
1337
+ return this.anchor == other.anchor && this.head == other.head && this.goalColumn == other.goalColumn &&
1338
1338
  (!includeAssoc || !this.empty || this.assoc == other.assoc);
1339
1339
  }
1340
1340
  /**
@@ -1475,11 +1475,13 @@ class EditorSelection {
1475
1475
  /**
1476
1476
  Create a selection range.
1477
1477
  */
1478
- static range(anchor, head, goalColumn, bidiLevel) {
1478
+ static range(anchor, head, goalColumn, bidiLevel, assoc) {
1479
1479
  let flags = ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215 /* RangeFlag.NoGoalColumn */) << 6 /* RangeFlag.GoalColumnOffset */) |
1480
1480
  (bidiLevel == null ? 7 : Math.min(6, bidiLevel));
1481
+ if (!assoc && anchor != head)
1482
+ assoc = head < anchor ? 1 : -1;
1481
1483
  return head < anchor ? SelectionRange.create(head, anchor, 32 /* RangeFlag.Inverted */ | 16 /* RangeFlag.AssocAfter */ | flags)
1482
- : SelectionRange.create(anchor, head, (head > anchor ? 8 /* RangeFlag.AssocBefore */ : 0) | flags);
1484
+ : SelectionRange.create(anchor, head, (!assoc ? 0 : assoc < 0 ? 8 /* RangeFlag.AssocBefore */ : 16 /* RangeFlag.AssocAfter */) | flags);
1483
1485
  }
1484
1486
  /**
1485
1487
  @internal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/state",
3
- "version": "6.5.3",
3
+ "version": "6.6.0",
4
4
  "description": "Editor state data structures for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",
@@ -33,6 +33,6 @@
33
33
  },
34
34
  "repository": {
35
35
  "type": "git",
36
- "url": "https://github.com/codemirror/state.git"
36
+ "url": "git+https://github.com/codemirror/state.git"
37
37
  }
38
38
  }