Skip to content

Commit 9477cdf

Browse files
committed
Make joinBackward and joinForward able to join lone textblocks into wrapped blocks
... but only if the wrapped textblock is the last child of the wrapping structure. FIX: `joinBackward` and `joinForward` will now, when the textblock after the cut can't be moved into the structure before the cut, try to just join the inline content onto the last child in the structure before the cut. See https://discuss.prosemirror.net/t/joinbackward-behavior/3296
1 parent 1c5e939 commit 9477cdf

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/commands.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ function deleteBarrier(state, $cut, dispatch) {
379379
if (before.type.spec.isolating || after.type.spec.isolating) return false
380380
if (joinMaybeClear(state, $cut, dispatch)) return true
381381

382-
if ($cut.parent.canReplace($cut.index(), $cut.index() + 1) &&
382+
let canDelAfter = $cut.parent.canReplace($cut.index(), $cut.index() + 1)
383+
if (canDelAfter &&
383384
(conn = (match = before.contentMatchAt(before.childCount)).findWrapping(after.type)) &&
384385
match.matchType(conn[0] || after.type).validEnd) {
385386
if (dispatch) {
@@ -402,6 +403,26 @@ function deleteBarrier(state, $cut, dispatch) {
402403
return true
403404
}
404405

406+
if (canDelAfter && after.isTextblock && textblockAt(before, "end")) {
407+
let at = before, wrap = []
408+
for (;;) {
409+
wrap.push(at)
410+
if (at.isTextblock) break
411+
at = at.lastChild
412+
}
413+
if (at.canReplace(at.childCount, at.childCount, after.content)) {
414+
if (dispatch) {
415+
let end = Fragment.empty
416+
for (let i = wrap.length - 1; i >= 0; i--) end = Fragment.from(wrap[i].copy(end))
417+
let tr = state.tr.step(new ReplaceAroundStep($cut.pos - wrap.length, $cut.pos + after.nodeSize,
418+
$cut.pos + 1, $cut.pos + after.nodeSize - 1,
419+
new Slice(end, wrap.length, 0), 0, true))
420+
dispatch(tr.scrollIntoView())
421+
}
422+
return true
423+
}
424+
}
425+
405426
return false
406427
}
407428

0 commit comments

Comments
 (0)