mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 14:59:27 +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,18 +61,30 @@ export const splitBlock: RawCommands['splitBlock'] = ({ keepMarks = true } = {})
|
||||
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
|
||||
? undefined
|
||||
: defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)))
|
||||
|
||||
const deflt = $from.depth === 0
|
||||
? undefined
|
||||
: defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)))
|
||||
let types = atEnd && deflt
|
||||
? [
|
||||
{
|
||||
type: deflt,
|
||||
attrs: newAttributes,
|
||||
},
|
||||
]
|
||||
: undefined
|
||||
|
||||
let types = atEnd && deflt
|
||||
let can = canSplit(tr.doc, tr.mapping.map($from.pos), 1, types)
|
||||
|
||||
if (
|
||||
!types
|
||||
&& !can
|
||||
&& canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : undefined)
|
||||
) {
|
||||
can = true
|
||||
types = deflt
|
||||
? [
|
||||
{
|
||||
type: deflt,
|
||||
@ -80,26 +92,14 @@ export const splitBlock: RawCommands['splitBlock'] = ({ keepMarks = true } = {})
|
||||
},
|
||||
]
|
||||
: undefined
|
||||
}
|
||||
|
||||
let can = canSplit(tr.doc, tr.mapping.map($from.pos), 1, types)
|
||||
|
||||
if (
|
||||
!types
|
||||
&& !can
|
||||
&& canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : undefined)
|
||||
) {
|
||||
can = true
|
||||
types = deflt
|
||||
? [
|
||||
{
|
||||
type: deflt,
|
||||
attrs: newAttributes,
|
||||
},
|
||||
]
|
||||
: 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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user