Skip to content

Commit

Permalink
fix: Fix the issue with the lift command. Directly using `ProseMirr…
Browse files Browse the repository at this point in the history
…or.lift` leads to incorrect modifications.
  • Loading branch information
guanriyue committed Oct 22, 2024
1 parent 5a15480 commit acdcdbf
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/core/src/commands/lift.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { lift as originalLift } from '@tiptap/pm/commands'
import { NodeType } from '@tiptap/pm/model'
import { liftTarget } from '@tiptap/pm/transform'

import { getNodeType } from '../helpers/getNodeType.js'
import { isNodeActive } from '../helpers/isNodeActive.js'
import { RawCommands } from '../types.js'
import { isNumber } from '../utilities/isNumber.js'

declare module '@tiptap/core' {
interface Commands<ReturnType> {
Expand All @@ -20,13 +21,26 @@ declare module '@tiptap/core' {
}
}

export const lift: RawCommands['lift'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
export const lift: RawCommands['lift'] = (typeOrName, attributes = {}) => ({ state, tr, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)
const isActive = isNodeActive(state, type, attributes)

if (!isActive) {
return false
}

return originalLift(state, dispatch)
const { $from, $to } = state.selection

const range = $from.blockRange($to, node => node.type === type)

if (range) {
const target = liftTarget(range)

if (isNumber(target)) {
dispatch?.(tr.lift(range, target))
return true
}
}

return false
}

0 comments on commit acdcdbf

Please sign in to comment.