prosemirror-transform 1.12.3 → 1.12.5
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 +16 -0
- package/dist/index.cjs +22 -18
- package/dist/index.js +22 -23
- package/package.json +1 -1
- package/src/mark.ts +3 -4
- package/src/mark_step.ts +19 -11
- package/src/replace.ts +4 -5
- package/src/replace_step.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## 1.12.5 (2026-11-04)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Make sure `ReplaceAroundStep`s are dropped when mapped through another change that deletes their gap range.
|
|
6
|
+
|
|
7
|
+
Fix a crash in replace step fitting when an open slice is partially fitted.
|
|
8
|
+
|
|
9
|
+
Fix a crash in replace fitting that could occur when inserting nodes open at both ends.
|
|
10
|
+
|
|
11
|
+
## 1.12.4 (2026-10-22)
|
|
12
|
+
|
|
13
|
+
### Bug fixes
|
|
14
|
+
|
|
15
|
+
Fix broken deserialization of mark set steps.
|
|
16
|
+
|
|
1
17
|
## 1.12.3 (2026-10-22)
|
|
2
18
|
|
|
3
19
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -366,7 +366,6 @@ var AddMarkStep = function (_Step) {
|
|
|
366
366
|
key: "apply",
|
|
367
367
|
value: function apply(doc) {
|
|
368
368
|
var _this2 = this;
|
|
369
|
-
if (this.from == this.to) return new StepResult(doc, null);
|
|
370
369
|
var oldSlice = doc.slice(this.from, this.to),
|
|
371
370
|
$from = doc.resolve(this.from);
|
|
372
371
|
var parent = $from.node($from.sharedDepth(this.to));
|
|
@@ -387,13 +386,13 @@ var AddMarkStep = function (_Step) {
|
|
|
387
386
|
if (!prosemirrorModel.Mark.sameSet(added, node.marks)) {
|
|
388
387
|
var from = Math.max(_this3.from, pos),
|
|
389
388
|
to = Math.min(_this3.to, pos + node.nodeSize);
|
|
390
|
-
|
|
389
|
+
pushMarkStep(RemoveMarkStep, from, to, _this3.mark, steps);
|
|
391
390
|
var _iterator = _createForOfIteratorHelper(node.marks),
|
|
392
391
|
_step;
|
|
393
392
|
try {
|
|
394
393
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
395
394
|
var mark = _step.value;
|
|
396
|
-
if (!mark.isInSet(added))
|
|
395
|
+
if (!mark.isInSet(added)) pushMarkStep(AddMarkStep, from, to, mark, steps);
|
|
397
396
|
}
|
|
398
397
|
} catch (err) {
|
|
399
398
|
_iterator.e(err);
|
|
@@ -403,7 +402,7 @@ var AddMarkStep = function (_Step) {
|
|
|
403
402
|
}
|
|
404
403
|
}
|
|
405
404
|
});
|
|
406
|
-
return steps.length ==
|
|
405
|
+
return steps.length == 1 ? steps[0] : new MarkSetStep(steps);
|
|
407
406
|
}
|
|
408
407
|
}, {
|
|
409
408
|
key: "map",
|
|
@@ -455,7 +454,6 @@ var RemoveMarkStep = function (_Step2) {
|
|
|
455
454
|
key: "apply",
|
|
456
455
|
value: function apply(doc) {
|
|
457
456
|
var _this5 = this;
|
|
458
|
-
if (this.from == this.to) return new StepResult(doc, null);
|
|
459
457
|
var oldSlice = doc.slice(this.from, this.to);
|
|
460
458
|
var slice = new prosemirrorModel.Slice(mapFragment(oldSlice.content, function (node) {
|
|
461
459
|
return node.mark(_this5.mark.removeFromSet(node.marks));
|
|
@@ -468,9 +466,9 @@ var RemoveMarkStep = function (_Step2) {
|
|
|
468
466
|
var _this6 = this;
|
|
469
467
|
var steps = [];
|
|
470
468
|
doc.nodesBetween(this.from, this.to, function (node, pos) {
|
|
471
|
-
if (node.isInline && node.isAtom && _this6.mark.isInSet(node.marks))
|
|
469
|
+
if (node.isInline && node.isAtom && _this6.mark.isInSet(node.marks)) pushMarkStep(AddMarkStep, Math.max(_this6.from, pos), Math.min(_this6.to, pos + node.nodeSize), _this6.mark, steps);
|
|
472
470
|
});
|
|
473
|
-
return steps.length ==
|
|
471
|
+
return steps.length == 1 ? steps[0] : new MarkSetStep(steps);
|
|
474
472
|
}
|
|
475
473
|
}, {
|
|
476
474
|
key: "map",
|
|
@@ -506,6 +504,14 @@ var RemoveMarkStep = function (_Step2) {
|
|
|
506
504
|
return RemoveMarkStep;
|
|
507
505
|
}(Step);
|
|
508
506
|
Step.jsonID("removeMark", RemoveMarkStep);
|
|
507
|
+
function pushMarkStep(cls, from, to, mark, target) {
|
|
508
|
+
var last = target.length ? target[target.length - 1] : null;
|
|
509
|
+
if (last && last instanceof cls && last.to == from && last.mark.eq(mark)) {
|
|
510
|
+
target[target.length - 1] = new cls(last.from, to, mark);
|
|
511
|
+
} else {
|
|
512
|
+
target.push(new cls(from, to, mark));
|
|
513
|
+
}
|
|
514
|
+
}
|
|
509
515
|
var MarkSetStep = function (_Step3) {
|
|
510
516
|
_inherits(MarkSetStep, _Step3);
|
|
511
517
|
var _super3 = _createSuper(MarkSetStep);
|
|
@@ -571,7 +577,7 @@ var MarkSetStep = function (_Step3) {
|
|
|
571
577
|
})
|
|
572
578
|
};
|
|
573
579
|
}
|
|
574
|
-
}, {
|
|
580
|
+
}], [{
|
|
575
581
|
key: "fromJSON",
|
|
576
582
|
value: function fromJSON(schema, json) {
|
|
577
583
|
if (!Array.isArray(json.steps) || !json.steps.every(function (s) {
|
|
@@ -813,7 +819,7 @@ var ReplaceAroundStep = function (_Step7) {
|
|
|
813
819
|
to = mapping.mapResult(this.to, -1);
|
|
814
820
|
var gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1);
|
|
815
821
|
var gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
|
|
816
|
-
if (from.deletedAcross && to.deletedAcross || gapFrom < from.pos || gapTo > to.pos) return null;
|
|
822
|
+
if (from.deletedAcross && to.deletedAcross || gapFrom < from.pos || gapTo > to.pos || gapFrom > gapTo) return null;
|
|
817
823
|
return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
|
|
818
824
|
}
|
|
819
825
|
}, {
|
|
@@ -860,15 +866,14 @@ function contentBetween(doc, from, to) {
|
|
|
860
866
|
return false;
|
|
861
867
|
}
|
|
862
868
|
function _addMark(tr, from, to, mark) {
|
|
863
|
-
var added = []
|
|
864
|
-
adding;
|
|
869
|
+
var added = [];
|
|
865
870
|
tr.doc.nodesBetween(from, to, function (node, pos, parent) {
|
|
866
871
|
if (!node.isInline) return;
|
|
867
872
|
var marks = node.marks;
|
|
868
873
|
if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) {
|
|
869
874
|
var start = Math.max(pos, from),
|
|
870
875
|
end = Math.min(pos + node.nodeSize, to);
|
|
871
|
-
|
|
876
|
+
pushMarkStep(AddMarkStep, start, end, mark, added);
|
|
872
877
|
}
|
|
873
878
|
});
|
|
874
879
|
added.forEach(function (s) {
|
|
@@ -1418,15 +1423,14 @@ var Fitter = function () {
|
|
|
1418
1423
|
this.placed = addToFragment(this.placed, frontierDepth, prosemirrorModel.Fragment.from(add));
|
|
1419
1424
|
this.frontier[frontierDepth].match = match;
|
|
1420
1425
|
if (toEnd && openEndCount < 0 && parent && parent.type == this.frontier[this.depth].type && this.frontier.length > 1) this.closeFrontierNode();
|
|
1421
|
-
for (var _i4 = 0, cur =
|
|
1422
|
-
var node = cur.lastChild;
|
|
1426
|
+
for (var _i4 = 0, cur = add[add.length - 1]; cur && _i4 < openEndCount; _i4++) {
|
|
1423
1427
|
this.frontier.push({
|
|
1424
|
-
type:
|
|
1425
|
-
match:
|
|
1428
|
+
type: cur.type,
|
|
1429
|
+
match: cur.contentMatchAt(cur.childCount)
|
|
1426
1430
|
});
|
|
1427
|
-
cur =
|
|
1431
|
+
cur = cur.lastChild;
|
|
1428
1432
|
}
|
|
1429
|
-
this.unplaced = !toEnd ? new prosemirrorModel.Slice(dropFromFragment(slice.content, sliceDepth, taken),
|
|
1433
|
+
this.unplaced = !toEnd ? new prosemirrorModel.Slice(dropFromFragment(slice.content, sliceDepth, taken), sliceDepth, slice.openEnd) : sliceDepth == 0 ? prosemirrorModel.Slice.empty : new prosemirrorModel.Slice(dropFromFragment(slice.content, sliceDepth - 1, 1), sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1);
|
|
1430
1434
|
}
|
|
1431
1435
|
}, {
|
|
1432
1436
|
key: "mustMoveInline",
|
package/dist/index.js
CHANGED
|
@@ -457,8 +457,6 @@ class AddMarkStep extends Step {
|
|
|
457
457
|
this.mark = mark;
|
|
458
458
|
}
|
|
459
459
|
apply(doc) {
|
|
460
|
-
if (this.from == this.to)
|
|
461
|
-
return new StepResult(doc, null);
|
|
462
460
|
let oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from);
|
|
463
461
|
let parent = $from.node($from.sharedDepth(this.to));
|
|
464
462
|
let slice = new Slice(mapFragment(oldSlice.content, (node, parent) => {
|
|
@@ -475,15 +473,14 @@ class AddMarkStep extends Step {
|
|
|
475
473
|
let added = this.mark.addToSet(node.marks);
|
|
476
474
|
if (!Mark.sameSet(added, node.marks)) {
|
|
477
475
|
let from = Math.max(this.from, pos), to = Math.min(this.to, pos + node.nodeSize);
|
|
478
|
-
|
|
476
|
+
pushMarkStep(RemoveMarkStep, from, to, this.mark, steps);
|
|
479
477
|
for (let mark of node.marks)
|
|
480
478
|
if (!mark.isInSet(added))
|
|
481
|
-
|
|
479
|
+
pushMarkStep(AddMarkStep, from, to, mark, steps);
|
|
482
480
|
}
|
|
483
481
|
}
|
|
484
482
|
});
|
|
485
|
-
return steps.length ==
|
|
486
|
-
: steps.length == 1 ? steps[0] : new MarkSetStep(steps);
|
|
483
|
+
return steps.length == 1 ? steps[0] : new MarkSetStep(steps);
|
|
487
484
|
}
|
|
488
485
|
map(mapping) {
|
|
489
486
|
let from = mapping.map(this.from, 1), to = mapping.map(this.to, -1);
|
|
@@ -538,8 +535,6 @@ class RemoveMarkStep extends Step {
|
|
|
538
535
|
this.mark = mark;
|
|
539
536
|
}
|
|
540
537
|
apply(doc) {
|
|
541
|
-
if (this.from == this.to)
|
|
542
|
-
return new StepResult(doc, null);
|
|
543
538
|
let oldSlice = doc.slice(this.from, this.to);
|
|
544
539
|
let slice = new Slice(mapFragment(oldSlice.content, node => {
|
|
545
540
|
return node.mark(this.mark.removeFromSet(node.marks));
|
|
@@ -550,10 +545,9 @@ class RemoveMarkStep extends Step {
|
|
|
550
545
|
let steps = [];
|
|
551
546
|
doc.nodesBetween(this.from, this.to, (node, pos) => {
|
|
552
547
|
if (node.isInline && node.isAtom && this.mark.isInSet(node.marks))
|
|
553
|
-
|
|
548
|
+
pushMarkStep(AddMarkStep, Math.max(this.from, pos), Math.min(this.to, pos + node.nodeSize), this.mark, steps);
|
|
554
549
|
});
|
|
555
|
-
return steps.length ==
|
|
556
|
-
: steps.length == 1 ? steps[0] : new MarkSetStep(steps);
|
|
550
|
+
return steps.length == 1 ? steps[0] : new MarkSetStep(steps);
|
|
557
551
|
}
|
|
558
552
|
map(mapping) {
|
|
559
553
|
let from = mapping.map(this.from, 1), to = mapping.map(this.to, -1);
|
|
@@ -582,6 +576,15 @@ class RemoveMarkStep extends Step {
|
|
|
582
576
|
}
|
|
583
577
|
}
|
|
584
578
|
Step.jsonID("removeMark", RemoveMarkStep);
|
|
579
|
+
function pushMarkStep(cls, from, to, mark, target) {
|
|
580
|
+
let last = target.length ? target[target.length - 1] : null;
|
|
581
|
+
if (last && last instanceof cls && last.to == from && last.mark.eq(mark)) {
|
|
582
|
+
target[target.length - 1] = new cls(last.from, to, mark);
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
target.push(new cls(from, to, mark));
|
|
586
|
+
}
|
|
587
|
+
}
|
|
585
588
|
class MarkSetStep extends Step {
|
|
586
589
|
constructor(steps) {
|
|
587
590
|
super();
|
|
@@ -611,7 +614,7 @@ class MarkSetStep extends Step {
|
|
|
611
614
|
toJSON() {
|
|
612
615
|
return { stepType: "markSet", steps: this.steps.map(s => s.toJSON()) };
|
|
613
616
|
}
|
|
614
|
-
fromJSON(schema, json) {
|
|
617
|
+
static fromJSON(schema, json) {
|
|
615
618
|
if (!Array.isArray(json.steps) || !json.steps.every((s) => s.stepType == "addMark" || s.stepType == "removeMark"))
|
|
616
619
|
throw new RangeError("Invalid JSON for MarkSetStep");
|
|
617
620
|
return new MarkSetStep(json.steps.map((s) => Step.fromJSON(schema, s)));
|
|
@@ -899,7 +902,7 @@ class ReplaceAroundStep extends Step {
|
|
|
899
902
|
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
900
903
|
let gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1);
|
|
901
904
|
let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
|
|
902
|
-
if ((from.deletedAcross && to.deletedAcross) || gapFrom < from.pos || gapTo > to.pos)
|
|
905
|
+
if ((from.deletedAcross && to.deletedAcross) || gapFrom < from.pos || gapTo > to.pos || gapFrom > gapTo)
|
|
903
906
|
return null;
|
|
904
907
|
return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
|
|
905
908
|
}
|
|
@@ -942,17 +945,14 @@ function contentBetween(doc, from, to) {
|
|
|
942
945
|
}
|
|
943
946
|
|
|
944
947
|
function addMark(tr, from, to, mark) {
|
|
945
|
-
let added = []
|
|
948
|
+
let added = [];
|
|
946
949
|
tr.doc.nodesBetween(from, to, (node, pos, parent) => {
|
|
947
950
|
if (!node.isInline)
|
|
948
951
|
return;
|
|
949
952
|
let marks = node.marks;
|
|
950
953
|
if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) {
|
|
951
954
|
let start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to);
|
|
952
|
-
|
|
953
|
-
adding.to = end;
|
|
954
|
-
else
|
|
955
|
-
added.push(adding = new AddMarkStep(start, end, mark));
|
|
955
|
+
pushMarkStep(AddMarkStep, start, end, mark, added);
|
|
956
956
|
}
|
|
957
957
|
});
|
|
958
958
|
added.forEach(s => tr.step(s));
|
|
@@ -1588,15 +1588,14 @@ class Fitter {
|
|
|
1588
1588
|
if (toEnd && openEndCount < 0 && parent && parent.type == this.frontier[this.depth].type && this.frontier.length > 1)
|
|
1589
1589
|
this.closeFrontierNode();
|
|
1590
1590
|
// Add new frontier nodes for any open nodes at the end.
|
|
1591
|
-
for (let i = 0, cur =
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
cur = node.content;
|
|
1591
|
+
for (let i = 0, cur = add[add.length - 1]; cur && i < openEndCount; i++) {
|
|
1592
|
+
this.frontier.push({ type: cur.type, match: cur.contentMatchAt(cur.childCount) });
|
|
1593
|
+
cur = cur.lastChild;
|
|
1595
1594
|
}
|
|
1596
1595
|
// Update `this.unplaced`. Drop the entire node from which we
|
|
1597
1596
|
// placed it we got to its end, otherwise just drop the placed
|
|
1598
1597
|
// nodes.
|
|
1599
|
-
this.unplaced = !toEnd ? new Slice(dropFromFragment(slice.content, sliceDepth, taken),
|
|
1598
|
+
this.unplaced = !toEnd ? new Slice(dropFromFragment(slice.content, sliceDepth, taken), sliceDepth, slice.openEnd)
|
|
1600
1599
|
: sliceDepth == 0 ? Slice.empty
|
|
1601
1600
|
: new Slice(dropFromFragment(slice.content, sliceDepth - 1, 1), sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1);
|
|
1602
1601
|
}
|
package/package.json
CHANGED
package/src/mark.ts
CHANGED
|
@@ -2,18 +2,17 @@ import {Mark, MarkType, Slice, Fragment, NodeType} from "prosemirror-model"
|
|
|
2
2
|
|
|
3
3
|
import {Step} from "./step"
|
|
4
4
|
import {Transform} from "./transform"
|
|
5
|
-
import {AddMarkStep, RemoveMarkStep} from "./mark_step"
|
|
5
|
+
import {AddMarkStep, RemoveMarkStep, pushMarkStep} from "./mark_step"
|
|
6
6
|
import {ReplaceStep} from "./replace_step"
|
|
7
7
|
|
|
8
8
|
export function addMark(tr: Transform, from: number, to: number, mark: Mark) {
|
|
9
|
-
let added:
|
|
9
|
+
let added: AddMarkStep[] = []
|
|
10
10
|
tr.doc.nodesBetween(from, to, (node, pos, parent) => {
|
|
11
11
|
if (!node.isInline) return
|
|
12
12
|
let marks = node.marks
|
|
13
13
|
if (!mark.isInSet(marks) && parent!.type.allowsMarkType(mark.type)) {
|
|
14
14
|
let start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to)
|
|
15
|
-
|
|
16
|
-
else added.push(adding = new AddMarkStep(start, end, mark))
|
|
15
|
+
pushMarkStep(AddMarkStep, start, end, mark, added)
|
|
17
16
|
}
|
|
18
17
|
})
|
|
19
18
|
added.forEach(s => tr.step(s))
|
package/src/mark_step.ts
CHANGED
|
@@ -28,7 +28,6 @@ export class AddMarkStep extends Step {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
apply(doc: Node) {
|
|
31
|
-
if (this.from == this.to) return new StepResult(doc, null)
|
|
32
31
|
let oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from)
|
|
33
32
|
let parent = $from.node($from.sharedDepth(this.to))
|
|
34
33
|
let slice = new Slice(mapFragment(oldSlice.content, (node, parent) => {
|
|
@@ -45,14 +44,13 @@ export class AddMarkStep extends Step {
|
|
|
45
44
|
let added = this.mark.addToSet(node.marks)
|
|
46
45
|
if (!Mark.sameSet(added, node.marks)) {
|
|
47
46
|
let from = Math.max(this.from, pos), to = Math.min(this.to, pos + node.nodeSize)
|
|
48
|
-
|
|
47
|
+
pushMarkStep(RemoveMarkStep, from, to, this.mark, steps)
|
|
49
48
|
for (let mark of node.marks) if (!mark.isInSet(added))
|
|
50
|
-
|
|
49
|
+
pushMarkStep(AddMarkStep, from, to, mark, steps)
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
})
|
|
54
|
-
return steps.length ==
|
|
55
|
-
: steps.length == 1 ? steps[0] : new MarkSetStep(steps)
|
|
53
|
+
return steps.length == 1 ? steps[0] : new MarkSetStep(steps)
|
|
56
54
|
}
|
|
57
55
|
|
|
58
56
|
map(mapping: Mappable): Step | null {
|
|
@@ -100,7 +98,6 @@ export class RemoveMarkStep extends Step {
|
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
apply(doc: Node) {
|
|
103
|
-
if (this.from == this.to) return new StepResult(doc, null)
|
|
104
101
|
let oldSlice = doc.slice(this.from, this.to)
|
|
105
102
|
let slice = new Slice(mapFragment(oldSlice.content, node => {
|
|
106
103
|
return node.mark(this.mark.removeFromSet(node.marks))
|
|
@@ -109,13 +106,12 @@ export class RemoveMarkStep extends Step {
|
|
|
109
106
|
}
|
|
110
107
|
|
|
111
108
|
invert(doc: Node): Step {
|
|
112
|
-
let steps: AddMarkStep[] = []
|
|
109
|
+
let steps: (AddMarkStep | RemoveMarkStep)[] = []
|
|
113
110
|
doc.nodesBetween(this.from, this.to, (node, pos) => {
|
|
114
111
|
if (node.isInline && node.isAtom && this.mark.isInSet(node.marks))
|
|
115
|
-
|
|
112
|
+
pushMarkStep(AddMarkStep, Math.max(this.from, pos), Math.min(this.to, pos + node.nodeSize), this.mark, steps)
|
|
116
113
|
})
|
|
117
|
-
return steps.length ==
|
|
118
|
-
: steps.length == 1 ? steps[0] : new MarkSetStep(steps)
|
|
114
|
+
return steps.length == 1 ? steps[0] : new MarkSetStep(steps)
|
|
119
115
|
}
|
|
120
116
|
|
|
121
117
|
map(mapping: Mappable): Step | null {
|
|
@@ -148,6 +144,18 @@ export class RemoveMarkStep extends Step {
|
|
|
148
144
|
|
|
149
145
|
Step.jsonID("removeMark", RemoveMarkStep)
|
|
150
146
|
|
|
147
|
+
export function pushMarkStep(
|
|
148
|
+
cls: typeof AddMarkStep | typeof RemoveMarkStep,
|
|
149
|
+
from: number, to: number, mark: Mark,
|
|
150
|
+
target: (AddMarkStep | RemoveMarkStep)[]) {
|
|
151
|
+
let last = target.length ? target[target.length - 1] : null
|
|
152
|
+
if (last && last instanceof cls && last.to == from && last.mark.eq(mark)) {
|
|
153
|
+
target[target.length - 1] = new cls(last.from, to, mark)
|
|
154
|
+
} else {
|
|
155
|
+
target.push(new cls(from, to, mark))
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
151
159
|
class MarkSetStep extends Step {
|
|
152
160
|
constructor(
|
|
153
161
|
readonly steps: readonly (AddMarkStep | RemoveMarkStep)[]
|
|
@@ -181,7 +189,7 @@ class MarkSetStep extends Step {
|
|
|
181
189
|
return {stepType: "markSet", steps: this.steps.map(s => s.toJSON())}
|
|
182
190
|
}
|
|
183
191
|
|
|
184
|
-
fromJSON(schema: Schema, json: any) {
|
|
192
|
+
static fromJSON(schema: Schema, json: any) {
|
|
185
193
|
if (!Array.isArray(json.steps) || !json.steps.every((s: any) => s.stepType == "addMark" || s.stepType == "removeMark"))
|
|
186
194
|
throw new RangeError("Invalid JSON for MarkSetStep")
|
|
187
195
|
return new MarkSetStep(json.steps.map((s: any) => Step.fromJSON(schema, s)))
|
package/src/replace.ts
CHANGED
|
@@ -216,16 +216,15 @@ class Fitter {
|
|
|
216
216
|
this.closeFrontierNode()
|
|
217
217
|
|
|
218
218
|
// Add new frontier nodes for any open nodes at the end.
|
|
219
|
-
for (let i = 0, cur =
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
cur = node.content
|
|
219
|
+
for (let i = 0, cur: Node | null = add[add.length - 1]; cur && i < openEndCount; i++) {
|
|
220
|
+
this.frontier.push({type: cur.type, match: cur.contentMatchAt(cur.childCount)})
|
|
221
|
+
cur = cur.lastChild
|
|
223
222
|
}
|
|
224
223
|
|
|
225
224
|
// Update `this.unplaced`. Drop the entire node from which we
|
|
226
225
|
// placed it we got to its end, otherwise just drop the placed
|
|
227
226
|
// nodes.
|
|
228
|
-
this.unplaced = !toEnd ? new Slice(dropFromFragment(slice.content, sliceDepth, taken),
|
|
227
|
+
this.unplaced = !toEnd ? new Slice(dropFromFragment(slice.content, sliceDepth, taken), sliceDepth, slice.openEnd)
|
|
229
228
|
: sliceDepth == 0 ? Slice.empty
|
|
230
229
|
: new Slice(dropFromFragment(slice.content, sliceDepth - 1, 1),
|
|
231
230
|
sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1)
|
package/src/replace_step.ts
CHANGED
|
@@ -145,7 +145,7 @@ export class ReplaceAroundStep extends Step {
|
|
|
145
145
|
let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1)
|
|
146
146
|
let gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1)
|
|
147
147
|
let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1)
|
|
148
|
-
if ((from.deletedAcross && to.deletedAcross) || gapFrom < from.pos || gapTo > to.pos) return null
|
|
148
|
+
if ((from.deletedAcross && to.deletedAcross) || gapFrom < from.pos || gapTo > to.pos || gapFrom > gapTo) return null
|
|
149
149
|
return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure)
|
|
150
150
|
}
|
|
151
151
|
|