mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-08-06 21:46:22 +08:00
fix: fix error when calculating contentMatch within clearNodes command, fix #1361
This commit is contained in:
parent
a24e33350c
commit
370966847e
@ -18,22 +18,28 @@ export const clearNodes: RawCommands['clearNodes'] = () => ({ state, tr, dispatc
|
||||
|
||||
ranges.forEach(range => {
|
||||
state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
|
||||
if (!node.type.isText) {
|
||||
const fromPos = tr.doc.resolve(tr.mapping.map(pos + 1))
|
||||
const toPos = tr.doc.resolve(tr.mapping.map(pos + node.nodeSize - 1))
|
||||
const nodeRange = fromPos.blockRange(toPos)
|
||||
if (node.type.isText) {
|
||||
return
|
||||
}
|
||||
|
||||
if (nodeRange) {
|
||||
const targetLiftDepth = liftTarget(nodeRange)
|
||||
const $fromPos = tr.doc.resolve(tr.mapping.map(pos))
|
||||
const $toPos = tr.doc.resolve(tr.mapping.map(pos + node.nodeSize))
|
||||
const nodeRange = $fromPos.blockRange($toPos)
|
||||
|
||||
if (node.type.isTextblock && dispatch) {
|
||||
tr.setNodeMarkup(nodeRange.start, state.doc.type.contentMatch.defaultType)
|
||||
}
|
||||
if (!nodeRange) {
|
||||
return
|
||||
}
|
||||
|
||||
if ((targetLiftDepth || targetLiftDepth === 0) && dispatch) {
|
||||
tr.lift(nodeRange, targetLiftDepth)
|
||||
}
|
||||
}
|
||||
const targetLiftDepth = liftTarget(nodeRange)
|
||||
|
||||
if (node.type.isTextblock && dispatch) {
|
||||
const { defaultType } = $fromPos.parent.contentMatchAt($fromPos.index())
|
||||
|
||||
tr.setNodeMarkup(nodeRange.start, defaultType)
|
||||
}
|
||||
|
||||
if ((targetLiftDepth || targetLiftDepth === 0) && dispatch) {
|
||||
tr.lift(nodeRange, targetLiftDepth)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user