Files
tiptap/packages/core/src/commands/toggleMark.ts
Philipp Kühn 9c3d8fe142 fix command name
2020-11-05 22:53:22 +01:00

20 lines
665 B
TypeScript

import { toggleMark } from 'prosemirror-commands'
import { MarkType } from 'prosemirror-model'
import { Command } from '../Editor'
import getMarkType from '../utils/getMarkType'
import markIsActive from '../utils/markIsActive'
export default (typeOrName: string | MarkType, attrs?: {}): Command => ({ state, dispatch, commands }) => {
const type = getMarkType(typeOrName, state.schema)
const hasMarkWithDifferentAttributes = attrs
&& markIsActive(state, type)
&& !markIsActive(state, type, attrs)
if (attrs && hasMarkWithDifferentAttributes) {
return commands.updateMarkAttributes(type, attrs)
}
return toggleMark(type)(state, dispatch)
}