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,18 +61,30 @@ 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) {
|
const deflt = $from.depth === 0
|
||||||
tr.deleteSelection()
|
? undefined
|
||||||
}
|
: defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)))
|
||||||
|
|
||||||
const deflt = $from.depth === 0
|
let types = atEnd && deflt
|
||||||
? undefined
|
? [
|
||||||
: defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)))
|
{
|
||||||
|
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,
|
type: deflt,
|
||||||
@ -80,26 +92,14 @@ export const splitBlock: RawCommands['splitBlock'] = ({ keepMarks = true } = {})
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
: undefined
|
: undefined
|
||||||
|
}
|
||||||
|
|
||||||
let can = canSplit(tr.doc, tr.mapping.map($from.pos), 1, types)
|
if (dispatch) {
|
||||||
|
|
||||||
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 (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