fix: don’t check for active node in wrapIn command, fix #1059
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { wrapIn, lift } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { RawCommands } from '../types'
|
||||
import { isNodeActive } from '../helpers/isNodeActive'
|
||||
@@ -15,13 +14,13 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const toggleWrap: RawCommands['toggleWrap'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
export const toggleWrap: RawCommands['toggleWrap'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const isActive = isNodeActive(state, type, attributes)
|
||||
|
||||
if (isActive) {
|
||||
return lift(state, dispatch)
|
||||
return commands.lift(type)
|
||||
}
|
||||
|
||||
return wrapIn(type, attributes)(state, dispatch)
|
||||
return commands.wrapIn(type, attributes)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { wrapIn as originalWrapIn } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { RawCommands } from '../types'
|
||||
import { isNodeActive } from '../helpers/isNodeActive'
|
||||
import { getNodeType } from '../helpers/getNodeType'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
@@ -17,11 +16,6 @@ declare module '@tiptap/core' {
|
||||
|
||||
export const wrapIn: RawCommands['wrapIn'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const isActive = isNodeActive(state, type, attributes)
|
||||
|
||||
if (isActive) {
|
||||
return false
|
||||
}
|
||||
|
||||
return originalWrapIn(type, attributes)(state, dispatch)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user