@codemirror/language 6.11.0 → 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 +12 -0
- package/dist/index.cjs +24 -17
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +24 -17
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
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
|
+
|
|
7
|
+
## 6.11.1 (2025-06-02)
|
|
8
|
+
|
|
9
|
+
### Bug fixes
|
|
10
|
+
|
|
11
|
+
Fix an issue where indentation would sometimes miss nodes in mixed-language situations.
|
|
12
|
+
|
|
1
13
|
## 6.11.0 (2025-03-13)
|
|
2
14
|
|
|
3
15
|
### New features
|
package/dist/index.cjs
CHANGED
|
@@ -803,8 +803,8 @@ service.
|
|
|
803
803
|
const indentService = state.Facet.define();
|
|
804
804
|
/**
|
|
805
805
|
Facet for overriding the unit by which indentation happens. Should
|
|
806
|
-
be a string consisting
|
|
807
|
-
|
|
806
|
+
be a string consisting entirely of the same whitespace character.
|
|
807
|
+
When not set, this defaults to 2 spaces.
|
|
808
808
|
*/
|
|
809
809
|
const indentUnit = state.Facet.define({
|
|
810
810
|
combine: values => {
|
|
@@ -998,7 +998,8 @@ function syntaxIndentation(cx, ast, pos) {
|
|
|
998
998
|
let inner = ast.resolveInner(pos, -1).resolve(pos, 0).enterUnfinishedNodesBefore(pos);
|
|
999
999
|
if (inner != stack.node) {
|
|
1000
1000
|
let add = [];
|
|
1001
|
-
for (let cur = inner; cur && !(cur.from
|
|
1001
|
+
for (let cur = inner; cur && !(cur.from < stack.node.from || cur.to > stack.node.to ||
|
|
1002
|
+
cur.from == stack.node.from && cur.type == stack.node.type); cur = cur.parent)
|
|
1002
1003
|
add.push(cur);
|
|
1003
1004
|
for (let i = add.length - 1; i >= 0; i--)
|
|
1004
1005
|
stack = { node: add[i], next: stack };
|
|
@@ -1317,6 +1318,8 @@ const foldState = state.StateField.define({
|
|
|
1317
1318
|
return view.Decoration.none;
|
|
1318
1319
|
},
|
|
1319
1320
|
update(folded, tr) {
|
|
1321
|
+
if (tr.isUserEvent("delete"))
|
|
1322
|
+
tr.changes.iterChangedRanges((fromA, toA) => folded = clearTouchedFolds(folded, fromA, toA));
|
|
1320
1323
|
folded = folded.map(tr.changes);
|
|
1321
1324
|
for (let e of tr.effects) {
|
|
1322
1325
|
if (e.is(foldEffect) && !foldExists(folded, e.value.from, e.value.to)) {
|
|
@@ -1331,17 +1334,8 @@ const foldState = state.StateField.define({
|
|
|
1331
1334
|
}
|
|
1332
1335
|
}
|
|
1333
1336
|
// Clear folded ranges that cover the selection head
|
|
1334
|
-
if (tr.selection)
|
|
1335
|
-
|
|
1336
|
-
folded.between(head, head, (a, b) => { if (a < head && b > head)
|
|
1337
|
-
onSelection = true; });
|
|
1338
|
-
if (onSelection)
|
|
1339
|
-
folded = folded.update({
|
|
1340
|
-
filterFrom: head,
|
|
1341
|
-
filterTo: head,
|
|
1342
|
-
filter: (a, b) => b <= head || a >= head
|
|
1343
|
-
});
|
|
1344
|
-
}
|
|
1337
|
+
if (tr.selection)
|
|
1338
|
+
folded = clearTouchedFolds(folded, tr.selection.main.head);
|
|
1345
1339
|
return folded;
|
|
1346
1340
|
},
|
|
1347
1341
|
provide: f => view.EditorView.decorations.from(f),
|
|
@@ -1363,6 +1357,16 @@ const foldState = state.StateField.define({
|
|
|
1363
1357
|
return view.Decoration.set(ranges, true);
|
|
1364
1358
|
}
|
|
1365
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
|
+
}
|
|
1366
1370
|
/**
|
|
1367
1371
|
Get a [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) containing the folded ranges
|
|
1368
1372
|
in the given state.
|
|
@@ -1579,7 +1583,7 @@ fold status indicator before foldable lines (which can be clicked
|
|
|
1579
1583
|
to fold or unfold the line).
|
|
1580
1584
|
*/
|
|
1581
1585
|
function foldGutter(config = {}) {
|
|
1582
|
-
let fullConfig =
|
|
1586
|
+
let fullConfig = { ...foldGutterDefaults, ...config };
|
|
1583
1587
|
let canFold = new FoldMarker(fullConfig, true), canUnfold = new FoldMarker(fullConfig, false);
|
|
1584
1588
|
let markers = view.ViewPlugin.fromClass(class {
|
|
1585
1589
|
constructor(view) {
|
|
@@ -1614,7 +1618,9 @@ function foldGutter(config = {}) {
|
|
|
1614
1618
|
initialSpacer() {
|
|
1615
1619
|
return new FoldMarker(fullConfig, false);
|
|
1616
1620
|
},
|
|
1617
|
-
domEventHandlers:
|
|
1621
|
+
domEventHandlers: {
|
|
1622
|
+
...domEventHandlers,
|
|
1623
|
+
click: (view, line, event) => {
|
|
1618
1624
|
if (domEventHandlers.click && domEventHandlers.click(view, line, event))
|
|
1619
1625
|
return true;
|
|
1620
1626
|
let folded = findFold(view.state, line.from, line.to);
|
|
@@ -1628,7 +1634,8 @@ function foldGutter(config = {}) {
|
|
|
1628
1634
|
return true;
|
|
1629
1635
|
}
|
|
1630
1636
|
return false;
|
|
1631
|
-
}
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1632
1639
|
}),
|
|
1633
1640
|
codeFolding()
|
|
1634
1641
|
];
|
package/dist/index.d.cts
CHANGED
|
@@ -429,8 +429,8 @@ service.
|
|
|
429
429
|
declare const indentService: Facet<(context: IndentContext, pos: number) => number | null | undefined, readonly ((context: IndentContext, pos: number) => number | null | undefined)[]>;
|
|
430
430
|
/**
|
|
431
431
|
Facet for overriding the unit by which indentation happens. Should
|
|
432
|
-
be a string consisting
|
|
433
|
-
|
|
432
|
+
be a string consisting entirely of the same whitespace character.
|
|
433
|
+
When not set, this defaults to 2 spaces.
|
|
434
434
|
*/
|
|
435
435
|
declare const indentUnit: Facet<string, string>;
|
|
436
436
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -429,8 +429,8 @@ service.
|
|
|
429
429
|
declare const indentService: Facet<(context: IndentContext, pos: number) => number | null | undefined, readonly ((context: IndentContext, pos: number) => number | null | undefined)[]>;
|
|
430
430
|
/**
|
|
431
431
|
Facet for overriding the unit by which indentation happens. Should
|
|
432
|
-
be a string consisting
|
|
433
|
-
|
|
432
|
+
be a string consisting entirely of the same whitespace character.
|
|
433
|
+
When not set, this defaults to 2 spaces.
|
|
434
434
|
*/
|
|
435
435
|
declare const indentUnit: Facet<string, string>;
|
|
436
436
|
/**
|
package/dist/index.js
CHANGED
|
@@ -801,8 +801,8 @@ service.
|
|
|
801
801
|
const indentService = /*@__PURE__*/Facet.define();
|
|
802
802
|
/**
|
|
803
803
|
Facet for overriding the unit by which indentation happens. Should
|
|
804
|
-
be a string consisting
|
|
805
|
-
|
|
804
|
+
be a string consisting entirely of the same whitespace character.
|
|
805
|
+
When not set, this defaults to 2 spaces.
|
|
806
806
|
*/
|
|
807
807
|
const indentUnit = /*@__PURE__*/Facet.define({
|
|
808
808
|
combine: values => {
|
|
@@ -996,7 +996,8 @@ function syntaxIndentation(cx, ast, pos) {
|
|
|
996
996
|
let inner = ast.resolveInner(pos, -1).resolve(pos, 0).enterUnfinishedNodesBefore(pos);
|
|
997
997
|
if (inner != stack.node) {
|
|
998
998
|
let add = [];
|
|
999
|
-
for (let cur = inner; cur && !(cur.from
|
|
999
|
+
for (let cur = inner; cur && !(cur.from < stack.node.from || cur.to > stack.node.to ||
|
|
1000
|
+
cur.from == stack.node.from && cur.type == stack.node.type); cur = cur.parent)
|
|
1000
1001
|
add.push(cur);
|
|
1001
1002
|
for (let i = add.length - 1; i >= 0; i--)
|
|
1002
1003
|
stack = { node: add[i], next: stack };
|
|
@@ -1315,6 +1316,8 @@ const foldState = /*@__PURE__*/StateField.define({
|
|
|
1315
1316
|
return Decoration.none;
|
|
1316
1317
|
},
|
|
1317
1318
|
update(folded, tr) {
|
|
1319
|
+
if (tr.isUserEvent("delete"))
|
|
1320
|
+
tr.changes.iterChangedRanges((fromA, toA) => folded = clearTouchedFolds(folded, fromA, toA));
|
|
1318
1321
|
folded = folded.map(tr.changes);
|
|
1319
1322
|
for (let e of tr.effects) {
|
|
1320
1323
|
if (e.is(foldEffect) && !foldExists(folded, e.value.from, e.value.to)) {
|
|
@@ -1329,17 +1332,8 @@ const foldState = /*@__PURE__*/StateField.define({
|
|
|
1329
1332
|
}
|
|
1330
1333
|
}
|
|
1331
1334
|
// Clear folded ranges that cover the selection head
|
|
1332
|
-
if (tr.selection)
|
|
1333
|
-
|
|
1334
|
-
folded.between(head, head, (a, b) => { if (a < head && b > head)
|
|
1335
|
-
onSelection = true; });
|
|
1336
|
-
if (onSelection)
|
|
1337
|
-
folded = folded.update({
|
|
1338
|
-
filterFrom: head,
|
|
1339
|
-
filterTo: head,
|
|
1340
|
-
filter: (a, b) => b <= head || a >= head
|
|
1341
|
-
});
|
|
1342
|
-
}
|
|
1335
|
+
if (tr.selection)
|
|
1336
|
+
folded = clearTouchedFolds(folded, tr.selection.main.head);
|
|
1343
1337
|
return folded;
|
|
1344
1338
|
},
|
|
1345
1339
|
provide: f => EditorView.decorations.from(f),
|
|
@@ -1361,6 +1355,16 @@ const foldState = /*@__PURE__*/StateField.define({
|
|
|
1361
1355
|
return Decoration.set(ranges, true);
|
|
1362
1356
|
}
|
|
1363
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
|
+
}
|
|
1364
1368
|
/**
|
|
1365
1369
|
Get a [range set](https://codemirror.net/6/docs/ref/#state.RangeSet) containing the folded ranges
|
|
1366
1370
|
in the given state.
|
|
@@ -1577,7 +1581,7 @@ fold status indicator before foldable lines (which can be clicked
|
|
|
1577
1581
|
to fold or unfold the line).
|
|
1578
1582
|
*/
|
|
1579
1583
|
function foldGutter(config = {}) {
|
|
1580
|
-
let fullConfig =
|
|
1584
|
+
let fullConfig = { ...foldGutterDefaults, ...config };
|
|
1581
1585
|
let canFold = new FoldMarker(fullConfig, true), canUnfold = new FoldMarker(fullConfig, false);
|
|
1582
1586
|
let markers = ViewPlugin.fromClass(class {
|
|
1583
1587
|
constructor(view) {
|
|
@@ -1612,7 +1616,9 @@ function foldGutter(config = {}) {
|
|
|
1612
1616
|
initialSpacer() {
|
|
1613
1617
|
return new FoldMarker(fullConfig, false);
|
|
1614
1618
|
},
|
|
1615
|
-
domEventHandlers:
|
|
1619
|
+
domEventHandlers: {
|
|
1620
|
+
...domEventHandlers,
|
|
1621
|
+
click: (view, line, event) => {
|
|
1616
1622
|
if (domEventHandlers.click && domEventHandlers.click(view, line, event))
|
|
1617
1623
|
return true;
|
|
1618
1624
|
let folded = findFold(view.state, line.from, line.to);
|
|
@@ -1626,7 +1632,8 @@ function foldGutter(config = {}) {
|
|
|
1626
1632
|
return true;
|
|
1627
1633
|
}
|
|
1628
1634
|
return false;
|
|
1629
|
-
}
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1630
1637
|
}),
|
|
1631
1638
|
codeFolding()
|
|
1632
1639
|
];
|