Skip to content

Commit

Permalink
fix: fix error when calculating contentMatch within clearNodes command,
Browse files Browse the repository at this point in the history
fix #1361
  • Loading branch information
philippkuehn committed May 28, 2021
1 parent a24e333 commit 3709668
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions packages/core/src/commands/clearNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (nodeRange) {
const targetLiftDepth = liftTarget(nodeRange)

if (node.type.isTextblock && dispatch) {
tr.setNodeMarkup(nodeRange.start, state.doc.type.contentMatch.defaultType)
}

if ((targetLiftDepth || targetLiftDepth === 0) && dispatch) {
tr.lift(nodeRange, targetLiftDepth)
}
}
if (node.type.isText) {
return
}

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 (!nodeRange) {
return
}

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)
}
})
})
Expand Down

0 comments on commit 3709668

Please sign in to comment.