mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-08 01:53:04 +08:00
fix(core): adjust the splitBlock
to return false
when failed (#5371)
This commit is contained in:
parent
2104f0fa70
commit
618bca91e8
5
.changeset/eleven-needles-argue.md
Normal file
5
.changeset/eleven-needles-argue.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@tiptap/core": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Adjust the `splitBlock` command to return `false` when it was unsuccessful.
|
@ -61,13 +61,8 @@ export const splitBlock: RawCommands['splitBlock'] = ({ keepMarks = true } = {})
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dispatch) {
|
|
||||||
const atEnd = $to.parentOffset === $to.parent.content.size
|
const atEnd = $to.parentOffset === $to.parent.content.size
|
||||||
|
|
||||||
if (selection instanceof TextSelection) {
|
|
||||||
tr.deleteSelection()
|
|
||||||
}
|
|
||||||
|
|
||||||
const deflt = $from.depth === 0
|
const deflt = $from.depth === 0
|
||||||
? undefined
|
? undefined
|
||||||
: defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)))
|
: defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)))
|
||||||
@ -99,7 +94,12 @@ export const splitBlock: RawCommands['splitBlock'] = ({ keepMarks = true } = {})
|
|||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dispatch) {
|
||||||
if (can) {
|
if (can) {
|
||||||
|
if (selection instanceof TextSelection) {
|
||||||
|
tr.deleteSelection()
|
||||||
|
}
|
||||||
|
|
||||||
tr.split(tr.mapping.map($from.pos), 1, types)
|
tr.split(tr.mapping.map($from.pos), 1, types)
|
||||||
|
|
||||||
if (deflt && !atEnd && !$from.parentOffset && $from.parent.type !== deflt) {
|
if (deflt && !atEnd && !$from.parentOffset && $from.parent.type !== deflt) {
|
||||||
@ -119,5 +119,5 @@ export const splitBlock: RawCommands['splitBlock'] = ({ keepMarks = true } = {})
|
|||||||
tr.scrollIntoView()
|
tr.scrollIntoView()
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return can
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user