Skip to content

Commit acab5cd

Browse files
committed
Fix fragile schema validity test in splitBlock
FIX: Fix a crash in `splitBlock` that occurred with certain types of schemas. Closes ProseMirror/prosemirror#1172
1 parent a064537 commit acab5cd

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/commands.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,11 @@ export function splitBlock(state, dispatch) {
318318
}
319319
if (can) {
320320
tr.split(tr.mapping.map($from.pos), 1, types)
321-
if (!atEnd && !$from.parentOffset && $from.parent.type != deflt &&
322-
$from.node(-1).canReplace($from.index(-1), $from.indexAfter(-1), Fragment.from([deflt.create(), $from.parent])))
323-
tr.setNodeMarkup(tr.mapping.map($from.before()), deflt)
321+
if (!atEnd && !$from.parentOffset && $from.parent.type != deflt) {
322+
let first = tr.mapping.map($from.before()), $first = tr.doc.resolve(first)
323+
if ($from.parent.canReplaceWith($first.index(), $first.index() + 1, deflt))
324+
tr.setNodeMarkup(tr.mapping.map($from.before()), deflt)
325+
}
324326
}
325327
dispatch(tr.scrollIntoView())
326328
}

0 commit comments

Comments
 (0)