@codemirror/state 6.6.0 → 6.7.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,9 @@
1
+ ## 6.7.0 (2026-06-23)
2
+
3
+ ### New features
4
+
5
+ Selection ranges can now be 'undirectional', making selection-expanding commands pick the side that would grow the selection, instead of the given head.
6
+
1
7
  ## 6.6.0 (2026-03-12)
2
8
 
3
9
  ### New features
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @codemirror/state [![NPM version](https://img.shields.io/npm/v/@codemirror/state.svg)](https://www.npmjs.org/package/@codemirror/state)
2
2
 
3
- [ [**WEBSITE**](https://codemirror.net/) | [**DOCS**](https://codemirror.net/docs/ref/#state) | [**ISSUES**](https://github.com/codemirror/dev/issues) | [**FORUM**](https://discuss.codemirror.net/c/next/) | [**CHANGELOG**](https://github.com/codemirror/state/blob/main/CHANGELOG.md) ]
3
+ [ [**WEBSITE**](https://codemirror.net/) | [**DOCS**](https://codemirror.net/docs/ref/#state) | [**ISSUES**](https://code.haverbeke.berlin/codemirror/dev/issues) | [**FORUM**](https://discuss.codemirror.net/) | [**CHANGELOG**](https://code.haverbeke.berlin/codemirror/state/src/branch/main/CHANGELOG.md) ]
4
4
 
5
5
  This package implements the editor state data structures for the
6
6
  [CodeMirror](https://codemirror.net/) code editor.
@@ -10,7 +10,7 @@ number of [examples](https://codemirror.net/examples/) and the
10
10
  [documentation](https://codemirror.net/docs/).
11
11
 
12
12
  This code is released under an
13
- [MIT license](https://github.com/codemirror/state/tree/main/LICENSE).
13
+ [MIT license](https://code.haverbeke.berlin/codemirror/state/tree/main/LICENSE).
14
14
 
15
15
  We aim to be an inclusive, welcoming community. To make that explicit,
16
16
  we have a [code of
package/dist/index.cjs CHANGED
@@ -1265,10 +1265,18 @@ class SelectionRange {
1265
1265
  /**
1266
1266
  The upper boundary of the range.
1267
1267
  */
1268
- to, flags) {
1268
+ to, flags,
1269
+ /**
1270
+ The goal column (stored vertical offset) associated with a
1271
+ cursor. This is used to preserve the vertical position when
1272
+ [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
1273
+ lines of different length.
1274
+ */
1275
+ goalColumn) {
1269
1276
  this.from = from;
1270
1277
  this.to = to;
1271
1278
  this.flags = flags;
1279
+ this.goalColumn = goalColumn;
1272
1280
  }
1273
1281
  /**
1274
1282
  The anchor of the range—the side that doesn't move when you
@@ -1292,6 +1300,16 @@ class SelectionRange {
1292
1300
  */
1293
1301
  get assoc() { return this.flags & 8 /* RangeFlag.AssocBefore */ ? -1 : this.flags & 16 /* RangeFlag.AssocAfter */ ? 1 : 0; }
1294
1302
  /**
1303
+ A flag that, when set, makes some selection-extending commands
1304
+ treat the range's head and anchor as exchangeable, so that for
1305
+ example Shift-ArrowUp will make the lower side of the selection
1306
+ the anchor, even if that was the head before. Used to implement
1307
+ MacOS-style undirectional selections.
1308
+ */
1309
+ get undirectional() {
1310
+ return (this.flags & 64 /* RangeFlag.Undirectional */) > 0;
1311
+ }
1312
+ /**
1295
1313
  The bidirectional text level associated with this cursor, if
1296
1314
  any.
1297
1315
  */
@@ -1300,16 +1318,6 @@ class SelectionRange {
1300
1318
  return level == 7 ? null : level;
1301
1319
  }
1302
1320
  /**
1303
- The goal column (stored vertical offset) associated with a
1304
- cursor. This is used to preserve the vertical position when
1305
- [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
1306
- lines of different length.
1307
- */
1308
- get goalColumn() {
1309
- let value = this.flags >> 6 /* RangeFlag.GoalColumnOffset */;
1310
- return value == 16777215 /* RangeFlag.NoGoalColumn */ ? undefined : value;
1311
- }
1312
- /**
1313
1321
  Map this range through a change, producing a valid range in the
1314
1322
  updated document.
1315
1323
  */
@@ -1322,7 +1330,7 @@ class SelectionRange {
1322
1330
  from = change.mapPos(this.from, 1);
1323
1331
  to = change.mapPos(this.to, -1);
1324
1332
  }
1325
- return from == this.from && to == this.to ? this : new SelectionRange(from, to, this.flags);
1333
+ return from == this.from && to == this.to ? this : new SelectionRange(from, to, this.flags, this.goalColumn);
1326
1334
  }
1327
1335
  /**
1328
1336
  Extend this range to cover at least `from` to `to`.
@@ -1356,8 +1364,8 @@ class SelectionRange {
1356
1364
  /**
1357
1365
  @internal
1358
1366
  */
1359
- static create(from, to, flags) {
1360
- return new SelectionRange(from, to, flags);
1367
+ static create(from, to, flags, goalColumn) {
1368
+ return new SelectionRange(from, to, flags, goalColumn);
1361
1369
  }
1362
1370
  }
1363
1371
  /**
@@ -1472,19 +1480,26 @@ class EditorSelection {
1472
1480
  */
1473
1481
  static cursor(pos, assoc = 0, bidiLevel, goalColumn) {
1474
1482
  return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 8 /* RangeFlag.AssocBefore */ : 16 /* RangeFlag.AssocAfter */) |
1475
- (bidiLevel == null ? 7 : Math.min(6, bidiLevel)) |
1476
- ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215 /* RangeFlag.NoGoalColumn */) << 6 /* RangeFlag.GoalColumnOffset */));
1483
+ (bidiLevel == null ? 7 : Math.min(6, bidiLevel)), goalColumn);
1477
1484
  }
1478
1485
  /**
1479
1486
  Create a selection range.
1480
1487
  */
1481
1488
  static range(anchor, head, goalColumn, bidiLevel, assoc) {
1482
- let flags = ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215 /* RangeFlag.NoGoalColumn */) << 6 /* RangeFlag.GoalColumnOffset */) |
1483
- (bidiLevel == null ? 7 : Math.min(6, bidiLevel));
1489
+ let flags = bidiLevel == null ? 7 : Math.min(6, bidiLevel);
1484
1490
  if (!assoc && anchor != head)
1485
1491
  assoc = head < anchor ? 1 : -1;
1486
- return head < anchor ? SelectionRange.create(head, anchor, 32 /* RangeFlag.Inverted */ | 16 /* RangeFlag.AssocAfter */ | flags)
1487
- : SelectionRange.create(anchor, head, (!assoc ? 0 : assoc < 0 ? 8 /* RangeFlag.AssocBefore */ : 16 /* RangeFlag.AssocAfter */) | flags);
1492
+ if (assoc)
1493
+ flags |= assoc < 0 ? 8 /* RangeFlag.AssocBefore */ : 16 /* RangeFlag.AssocAfter */;
1494
+ return head < anchor ? SelectionRange.create(head, anchor, flags | 32 /* RangeFlag.Inverted */, goalColumn)
1495
+ : SelectionRange.create(anchor, head, flags, goalColumn);
1496
+ }
1497
+ /**
1498
+ Create an [undirectional](https://codemirror.net/6/docs/ref/#state.SelectionRange.undirectional)
1499
+ selection range.
1500
+ */
1501
+ static undirectionalRange(from, to) {
1502
+ return SelectionRange.create(from, to, 64 /* RangeFlag.Undirectional */, undefined);
1488
1503
  }
1489
1504
  /**
1490
1505
  @internal
package/dist/index.d.cts CHANGED
@@ -358,6 +358,13 @@ declare class SelectionRange {
358
358
  */
359
359
  readonly to: number;
360
360
  private flags;
361
+ /**
362
+ The goal column (stored vertical offset) associated with a
363
+ cursor. This is used to preserve the vertical position when
364
+ [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
365
+ lines of different length.
366
+ */
367
+ readonly goalColumn: number | undefined;
361
368
  private constructor();
362
369
  /**
363
370
  The anchor of the range—the side that doesn't move when you
@@ -381,18 +388,19 @@ declare class SelectionRange {
381
388
  */
382
389
  get assoc(): -1 | 0 | 1;
383
390
  /**
391
+ A flag that, when set, makes some selection-extending commands
392
+ treat the range's head and anchor as exchangeable, so that for
393
+ example Shift-ArrowUp will make the lower side of the selection
394
+ the anchor, even if that was the head before. Used to implement
395
+ MacOS-style undirectional selections.
396
+ */
397
+ get undirectional(): boolean;
398
+ /**
384
399
  The bidirectional text level associated with this cursor, if
385
400
  any.
386
401
  */
387
402
  get bidiLevel(): number | null;
388
403
  /**
389
- The goal column (stored vertical offset) associated with a
390
- cursor. This is used to preserve the vertical position when
391
- [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
392
- lines of different length.
393
- */
394
- get goalColumn(): number | undefined;
395
- /**
396
404
  Map this range through a change, producing a valid range in the
397
405
  updated document.
398
406
  */
@@ -489,6 +497,11 @@ declare class EditorSelection {
489
497
  Create a selection range.
490
498
  */
491
499
  static range(anchor: number, head: number, goalColumn?: number, bidiLevel?: number, assoc?: number): SelectionRange;
500
+ /**
501
+ Create an [undirectional](https://codemirror.net/6/docs/ref/#state.SelectionRange.undirectional)
502
+ selection range.
503
+ */
504
+ static undirectionalRange(from: number, to: number): SelectionRange;
492
505
  }
493
506
 
494
507
  type FacetConfig<Input, Output> = {
package/dist/index.d.ts CHANGED
@@ -358,6 +358,13 @@ declare class SelectionRange {
358
358
  */
359
359
  readonly to: number;
360
360
  private flags;
361
+ /**
362
+ The goal column (stored vertical offset) associated with a
363
+ cursor. This is used to preserve the vertical position when
364
+ [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
365
+ lines of different length.
366
+ */
367
+ readonly goalColumn: number | undefined;
361
368
  private constructor();
362
369
  /**
363
370
  The anchor of the range—the side that doesn't move when you
@@ -381,18 +388,19 @@ declare class SelectionRange {
381
388
  */
382
389
  get assoc(): -1 | 0 | 1;
383
390
  /**
391
+ A flag that, when set, makes some selection-extending commands
392
+ treat the range's head and anchor as exchangeable, so that for
393
+ example Shift-ArrowUp will make the lower side of the selection
394
+ the anchor, even if that was the head before. Used to implement
395
+ MacOS-style undirectional selections.
396
+ */
397
+ get undirectional(): boolean;
398
+ /**
384
399
  The bidirectional text level associated with this cursor, if
385
400
  any.
386
401
  */
387
402
  get bidiLevel(): number | null;
388
403
  /**
389
- The goal column (stored vertical offset) associated with a
390
- cursor. This is used to preserve the vertical position when
391
- [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
392
- lines of different length.
393
- */
394
- get goalColumn(): number | undefined;
395
- /**
396
404
  Map this range through a change, producing a valid range in the
397
405
  updated document.
398
406
  */
@@ -489,6 +497,11 @@ declare class EditorSelection {
489
497
  Create a selection range.
490
498
  */
491
499
  static range(anchor: number, head: number, goalColumn?: number, bidiLevel?: number, assoc?: number): SelectionRange;
500
+ /**
501
+ Create an [undirectional](https://codemirror.net/6/docs/ref/#state.SelectionRange.undirectional)
502
+ selection range.
503
+ */
504
+ static undirectionalRange(from: number, to: number): SelectionRange;
492
505
  }
493
506
 
494
507
  type FacetConfig<Input, Output> = {
package/dist/index.js CHANGED
@@ -1262,10 +1262,18 @@ class SelectionRange {
1262
1262
  /**
1263
1263
  The upper boundary of the range.
1264
1264
  */
1265
- to, flags) {
1265
+ to, flags,
1266
+ /**
1267
+ The goal column (stored vertical offset) associated with a
1268
+ cursor. This is used to preserve the vertical position when
1269
+ [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
1270
+ lines of different length.
1271
+ */
1272
+ goalColumn) {
1266
1273
  this.from = from;
1267
1274
  this.to = to;
1268
1275
  this.flags = flags;
1276
+ this.goalColumn = goalColumn;
1269
1277
  }
1270
1278
  /**
1271
1279
  The anchor of the range—the side that doesn't move when you
@@ -1289,6 +1297,16 @@ class SelectionRange {
1289
1297
  */
1290
1298
  get assoc() { return this.flags & 8 /* RangeFlag.AssocBefore */ ? -1 : this.flags & 16 /* RangeFlag.AssocAfter */ ? 1 : 0; }
1291
1299
  /**
1300
+ A flag that, when set, makes some selection-extending commands
1301
+ treat the range's head and anchor as exchangeable, so that for
1302
+ example Shift-ArrowUp will make the lower side of the selection
1303
+ the anchor, even if that was the head before. Used to implement
1304
+ MacOS-style undirectional selections.
1305
+ */
1306
+ get undirectional() {
1307
+ return (this.flags & 64 /* RangeFlag.Undirectional */) > 0;
1308
+ }
1309
+ /**
1292
1310
  The bidirectional text level associated with this cursor, if
1293
1311
  any.
1294
1312
  */
@@ -1297,16 +1315,6 @@ class SelectionRange {
1297
1315
  return level == 7 ? null : level;
1298
1316
  }
1299
1317
  /**
1300
- The goal column (stored vertical offset) associated with a
1301
- cursor. This is used to preserve the vertical position when
1302
- [moving](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) across
1303
- lines of different length.
1304
- */
1305
- get goalColumn() {
1306
- let value = this.flags >> 6 /* RangeFlag.GoalColumnOffset */;
1307
- return value == 16777215 /* RangeFlag.NoGoalColumn */ ? undefined : value;
1308
- }
1309
- /**
1310
1318
  Map this range through a change, producing a valid range in the
1311
1319
  updated document.
1312
1320
  */
@@ -1319,7 +1327,7 @@ class SelectionRange {
1319
1327
  from = change.mapPos(this.from, 1);
1320
1328
  to = change.mapPos(this.to, -1);
1321
1329
  }
1322
- return from == this.from && to == this.to ? this : new SelectionRange(from, to, this.flags);
1330
+ return from == this.from && to == this.to ? this : new SelectionRange(from, to, this.flags, this.goalColumn);
1323
1331
  }
1324
1332
  /**
1325
1333
  Extend this range to cover at least `from` to `to`.
@@ -1353,8 +1361,8 @@ class SelectionRange {
1353
1361
  /**
1354
1362
  @internal
1355
1363
  */
1356
- static create(from, to, flags) {
1357
- return new SelectionRange(from, to, flags);
1364
+ static create(from, to, flags, goalColumn) {
1365
+ return new SelectionRange(from, to, flags, goalColumn);
1358
1366
  }
1359
1367
  }
1360
1368
  /**
@@ -1469,19 +1477,26 @@ class EditorSelection {
1469
1477
  */
1470
1478
  static cursor(pos, assoc = 0, bidiLevel, goalColumn) {
1471
1479
  return SelectionRange.create(pos, pos, (assoc == 0 ? 0 : assoc < 0 ? 8 /* RangeFlag.AssocBefore */ : 16 /* RangeFlag.AssocAfter */) |
1472
- (bidiLevel == null ? 7 : Math.min(6, bidiLevel)) |
1473
- ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215 /* RangeFlag.NoGoalColumn */) << 6 /* RangeFlag.GoalColumnOffset */));
1480
+ (bidiLevel == null ? 7 : Math.min(6, bidiLevel)), goalColumn);
1474
1481
  }
1475
1482
  /**
1476
1483
  Create a selection range.
1477
1484
  */
1478
1485
  static range(anchor, head, goalColumn, bidiLevel, assoc) {
1479
- let flags = ((goalColumn !== null && goalColumn !== void 0 ? goalColumn : 16777215 /* RangeFlag.NoGoalColumn */) << 6 /* RangeFlag.GoalColumnOffset */) |
1480
- (bidiLevel == null ? 7 : Math.min(6, bidiLevel));
1486
+ let flags = bidiLevel == null ? 7 : Math.min(6, bidiLevel);
1481
1487
  if (!assoc && anchor != head)
1482
1488
  assoc = head < anchor ? 1 : -1;
1483
- return head < anchor ? SelectionRange.create(head, anchor, 32 /* RangeFlag.Inverted */ | 16 /* RangeFlag.AssocAfter */ | flags)
1484
- : SelectionRange.create(anchor, head, (!assoc ? 0 : assoc < 0 ? 8 /* RangeFlag.AssocBefore */ : 16 /* RangeFlag.AssocAfter */) | flags);
1489
+ if (assoc)
1490
+ flags |= assoc < 0 ? 8 /* RangeFlag.AssocBefore */ : 16 /* RangeFlag.AssocAfter */;
1491
+ return head < anchor ? SelectionRange.create(head, anchor, flags | 32 /* RangeFlag.Inverted */, goalColumn)
1492
+ : SelectionRange.create(anchor, head, flags, goalColumn);
1493
+ }
1494
+ /**
1495
+ Create an [undirectional](https://codemirror.net/6/docs/ref/#state.SelectionRange.undirectional)
1496
+ selection range.
1497
+ */
1498
+ static undirectionalRange(from, to) {
1499
+ return SelectionRange.create(from, to, 64 /* RangeFlag.Undirectional */, undefined);
1485
1500
  }
1486
1501
  /**
1487
1502
  @internal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/state",
3
- "version": "6.6.0",
3
+ "version": "6.7.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": "git+https://github.com/codemirror/state.git"
36
+ "url": "git+https://code.haverbeke.berlin/codemirror/state.git"
37
37
  }
38
38
  }
@@ -1,16 +0,0 @@
1
- name: Trigger CI
2
- on: push
3
-
4
- jobs:
5
- build:
6
- name: Dispatch to main repo
7
- runs-on: ubuntu-latest
8
- steps:
9
- - name: Emit repository_dispatch
10
- uses: mvasigh/dispatch-action@main
11
- with:
12
- # You should create a personal access token and store it in your repository
13
- token: ${{ secrets.DISPATCH_AUTH }}
14
- repo: dev
15
- owner: codemirror
16
- event_type: push