prosemirror-transform 1.10.4 → 1.10.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 +6 -0
- package/dist/index.cjs +6 -4
- package/dist/index.js +7 -3
- package/package.json +1 -1
- package/src/replace.ts +1 -1
- package/src/structure.ts +4 -2
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -853,12 +853,14 @@ function canCut(node, start, end) {
|
|
|
853
853
|
function liftTarget(range) {
|
|
854
854
|
var parent = range.parent;
|
|
855
855
|
var content = parent.content.cutByIndex(range.startIndex, range.endIndex);
|
|
856
|
-
for (var depth = range.depth;; --depth) {
|
|
856
|
+
for (var depth = range.depth, contentBefore = 0, contentAfter = 0;; --depth) {
|
|
857
857
|
var node = range.$from.node(depth);
|
|
858
|
-
var index = range.$from.index(depth),
|
|
859
|
-
endIndex = range.$to.indexAfter(depth);
|
|
858
|
+
var index = range.$from.index(depth) + contentBefore,
|
|
859
|
+
endIndex = range.$to.indexAfter(depth) - contentAfter;
|
|
860
860
|
if (depth < range.depth && node.canReplace(index, endIndex, content)) return depth;
|
|
861
861
|
if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex)) break;
|
|
862
|
+
if (index) contentBefore = 1;
|
|
863
|
+
if (endIndex < node.childCount) contentAfter = 1;
|
|
862
864
|
}
|
|
863
865
|
return null;
|
|
864
866
|
}
|
|
@@ -1434,7 +1436,7 @@ function _replaceRange(tr, from, to, slice) {
|
|
|
1434
1436
|
var $from = tr.doc.resolve(from),
|
|
1435
1437
|
$to = tr.doc.resolve(to);
|
|
1436
1438
|
if (fitsTrivially($from, $to, slice)) return tr.step(new ReplaceStep(from, to, slice));
|
|
1437
|
-
var targetDepths = coveredDepths($from,
|
|
1439
|
+
var targetDepths = coveredDepths($from, $to);
|
|
1438
1440
|
if (targetDepths[targetDepths.length - 1] == 0) targetDepths.pop();
|
|
1439
1441
|
var preferredTarget = -($from.depth + 1);
|
|
1440
1442
|
targetDepths.unshift(preferredTarget);
|
package/dist/index.js
CHANGED
|
@@ -982,13 +982,17 @@ can be lifted. Will not go across
|
|
|
982
982
|
function liftTarget(range) {
|
|
983
983
|
let parent = range.parent;
|
|
984
984
|
let content = parent.content.cutByIndex(range.startIndex, range.endIndex);
|
|
985
|
-
for (let depth = range.depth;; --depth) {
|
|
985
|
+
for (let depth = range.depth, contentBefore = 0, contentAfter = 0;; --depth) {
|
|
986
986
|
let node = range.$from.node(depth);
|
|
987
|
-
let index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth);
|
|
987
|
+
let index = range.$from.index(depth) + contentBefore, endIndex = range.$to.indexAfter(depth) - contentAfter;
|
|
988
988
|
if (depth < range.depth && node.canReplace(index, endIndex, content))
|
|
989
989
|
return depth;
|
|
990
990
|
if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex))
|
|
991
991
|
break;
|
|
992
|
+
if (index)
|
|
993
|
+
contentBefore = 1;
|
|
994
|
+
if (endIndex < node.childCount)
|
|
995
|
+
contentAfter = 1;
|
|
992
996
|
}
|
|
993
997
|
return null;
|
|
994
998
|
}
|
|
@@ -1639,7 +1643,7 @@ function replaceRange(tr, from, to, slice) {
|
|
|
1639
1643
|
let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);
|
|
1640
1644
|
if (fitsTrivially($from, $to, slice))
|
|
1641
1645
|
return tr.step(new ReplaceStep(from, to, slice));
|
|
1642
|
-
let targetDepths = coveredDepths($from,
|
|
1646
|
+
let targetDepths = coveredDepths($from, $to);
|
|
1643
1647
|
// Can't replace the whole document, so remove 0 if it's present
|
|
1644
1648
|
if (targetDepths[targetDepths.length - 1] == 0)
|
|
1645
1649
|
targetDepths.pop();
|
package/package.json
CHANGED
package/src/replace.ts
CHANGED
|
@@ -338,7 +338,7 @@ export function replaceRange(tr: Transform, from: number, to: number, slice: Sli
|
|
|
338
338
|
if (fitsTrivially($from, $to, slice))
|
|
339
339
|
return tr.step(new ReplaceStep(from, to, slice))
|
|
340
340
|
|
|
341
|
-
let targetDepths = coveredDepths($from,
|
|
341
|
+
let targetDepths = coveredDepths($from, $to)
|
|
342
342
|
// Can't replace the whole document, so remove 0 if it's present
|
|
343
343
|
if (targetDepths[targetDepths.length - 1] == 0) targetDepths.pop()
|
|
344
344
|
// Negative numbers represent not expansion over the whole node at
|
package/src/structure.ts
CHANGED
|
@@ -15,12 +15,14 @@ function canCut(node: Node, start: number, end: number) {
|
|
|
15
15
|
export function liftTarget(range: NodeRange): number | null {
|
|
16
16
|
let parent = range.parent
|
|
17
17
|
let content = parent.content.cutByIndex(range.startIndex, range.endIndex)
|
|
18
|
-
for (let depth = range.depth;; --depth) {
|
|
18
|
+
for (let depth = range.depth, contentBefore = 0, contentAfter = 0;; --depth) {
|
|
19
19
|
let node = range.$from.node(depth)
|
|
20
|
-
let index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth)
|
|
20
|
+
let index = range.$from.index(depth) + contentBefore, endIndex = range.$to.indexAfter(depth) - contentAfter
|
|
21
21
|
if (depth < range.depth && node.canReplace(index, endIndex, content))
|
|
22
22
|
return depth
|
|
23
23
|
if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex)) break
|
|
24
|
+
if (index) contentBefore = 1
|
|
25
|
+
if (endIndex < node.childCount) contentAfter = 1
|
|
24
26
|
}
|
|
25
27
|
return null
|
|
26
28
|
}
|