@codemirror/language 6.11.1 → 6.11.2

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.11.2 (2025-06-27)
2
+
3
+ ### Bug fixes
4
+
5
+ Make sure folded ranges open when backspacing or deleting into them.
6
+
1
7
  ## 6.11.1 (2025-06-02)
2
8
 
3
9
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -1318,6 +1318,8 @@ const foldState = state.StateField.define({
1318
1318
  return view.Decoration.none;
1319
1319
  },
1320
1320
  update(folded, tr) {
1321
+ if (tr.isUserEvent("delete"))
1322
+ tr.changes.iterChangedRanges((fromA, toA) => folded = clearTouchedFolds(folded, fromA, toA));
1321
1323
  folded = folded.map(tr.changes);
1322
1324
  for (let e of tr.effects) {
1323
1325
  if (e.is(foldEffect) && !foldExists(folded, e.value.from, e.value.to)) {
@@ -1332,17 +1334,8 @@ const foldState = state.StateField.define({
1332
1334
  }
1333
1335
  }
1334
1336
  // Clear folded ranges that cover the selection head
1335
- if (tr.selection) {
1336
- let onSelection = false, { head } = tr.selection.main;
1337
- folded.between(head, head, (a, b) => { if (a < head && b > head)
1338
- onSelection = true; });
1339
- if (onSelection)
1340
- folded = folded.update({
1341
- filterFrom: head,
1342
- filterTo: head,
1343
- filter: (a, b) => b <= head || a >= head
1344
- });
1345
- }
1337
+ if (tr.selection)
1338
+ folded = clearTouchedFolds(folded, tr.selection.main.head);
1346
1339
  return folded;
1347
1340
  },
1348
1341
  provide: f => view.EditorView.decorations.from(f),
@@ -1364,6 +1357,16 @@ const foldState = state.StateField.define({
1364
1357
  return view.Decoration.set(ranges, true);
1365
1358
  }
1366
1359
  });
1360
+ function clearTouchedFolds(folded, from, to = from) {
1361
+ let touched = false;
1362
+ folded.between(from, to, (a, b) => { if (a < to && b > from)
1363
+ touched = true; });
1364
+ return !touched ? folded : folded.update({
1365
+ filterFrom: from,
1366
+ filterTo: to,
1367
+ filter: (a, b) => a >= to || b <= from
1368
+ });
1369
+ }
1367
1370
  /**
1368
1371
  Get a [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) containing the folded ranges
1369
1372
  in the given state.
package/dist/index.js CHANGED
@@ -1316,6 +1316,8 @@ const foldState = /*@__PURE__*/StateField.define({
1316
1316
  return Decoration.none;
1317
1317
  },
1318
1318
  update(folded, tr) {
1319
+ if (tr.isUserEvent("delete"))
1320
+ tr.changes.iterChangedRanges((fromA, toA) => folded = clearTouchedFolds(folded, fromA, toA));
1319
1321
  folded = folded.map(tr.changes);
1320
1322
  for (let e of tr.effects) {
1321
1323
  if (e.is(foldEffect) && !foldExists(folded, e.value.from, e.value.to)) {
@@ -1330,17 +1332,8 @@ const foldState = /*@__PURE__*/StateField.define({
1330
1332
  }
1331
1333
  }
1332
1334
  // Clear folded ranges that cover the selection head
1333
- if (tr.selection) {
1334
- let onSelection = false, { head } = tr.selection.main;
1335
- folded.between(head, head, (a, b) => { if (a < head && b > head)
1336
- onSelection = true; });
1337
- if (onSelection)
1338
- folded = folded.update({
1339
- filterFrom: head,
1340
- filterTo: head,
1341
- filter: (a, b) => b <= head || a >= head
1342
- });
1343
- }
1335
+ if (tr.selection)
1336
+ folded = clearTouchedFolds(folded, tr.selection.main.head);
1344
1337
  return folded;
1345
1338
  },
1346
1339
  provide: f => EditorView.decorations.from(f),
@@ -1362,6 +1355,16 @@ const foldState = /*@__PURE__*/StateField.define({
1362
1355
  return Decoration.set(ranges, true);
1363
1356
  }
1364
1357
  });
1358
+ function clearTouchedFolds(folded, from, to = from) {
1359
+ let touched = false;
1360
+ folded.between(from, to, (a, b) => { if (a < to && b > from)
1361
+ touched = true; });
1362
+ return !touched ? folded : folded.update({
1363
+ filterFrom: from,
1364
+ filterTo: to,
1365
+ filter: (a, b) => a >= to || b <= from
1366
+ });
1367
+ }
1365
1368
  /**
1366
1369
  Get a [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) containing the folded ranges
1367
1370
  in the given state.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/language",
3
- "version": "6.11.1",
3
+ "version": "6.11.2",
4
4
  "description": "Language support infrastructure for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",