mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-23 19:19:03 +08:00
fix: Fix the issue with the lift
command. Directly using ProseMirror.lift
leads to incorrect modifications.
This commit is contained in:
parent
5a15480652
commit
acdcdbfcc3
@ -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> {
|
||||
@ -20,7 +21,7 @@ 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)
|
||||
|
||||
@ -28,5 +29,18 @@ export const lift: RawCommands['lift'] = (typeOrName, attributes = {}) => ({ sta
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user