fix(core): adjust the splitBlock to return false when failed (#5371)

This commit is contained in:
Markus Greystone 2024-07-22 09:10:29 -04:00 committed by GitHub
parent 2104f0fa70
commit 618bca91e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 28 deletions

View File

@ -0,0 +1,5 @@
---
"@tiptap/core": patch
---
Adjust the `splitBlock` command to return `false` when it was unsuccessful.

View File

@ -61,13 +61,8 @@ export const splitBlock: RawCommands['splitBlock'] = ({ keepMarks = true } = {})
return false
}
if (dispatch) {
const atEnd = $to.parentOffset === $to.parent.content.size
if (selection instanceof TextSelection) {
tr.deleteSelection()
}
const deflt = $from.depth === 0
? undefined
: defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)))
@ -99,7 +94,12 @@ export const splitBlock: RawCommands['splitBlock'] = ({ keepMarks = true } = {})
: undefined
}
if (dispatch) {
if (can) {
if (selection instanceof TextSelection) {
tr.deleteSelection()
}
tr.split(tr.mapping.map($from.pos), 1, types)
if (deflt && !atEnd && !$from.parentOffset && $from.parent.type !== deflt) {
@ -119,5 +119,5 @@ export const splitBlock: RawCommands['splitBlock'] = ({ keepMarks = true } = {})
tr.scrollIntoView()
}
return true
return can
}