This commit is contained in:
Hans Pagel 2020-10-27 22:23:37 +01:00
parent c9da3ab269
commit 2a706fd3d2

View File

@ -1,28 +0,0 @@
import { toggleMark as originalToggleMark } from 'prosemirror-commands'
import { MarkType } from 'prosemirror-model'
import { Command } from '../Editor'
import getMarkType from '../utils/getMarkType'
import markIsActive from '../utils/markIsActive'
type ToggleMarkCommand = (typeOrName: string | MarkType, attrs?: {}) => Command
declare module '../Editor' {
interface Commands {
toggleMark: ToggleMarkCommand,
}
}
export const toggleMark: ToggleMarkCommand = (typeOrName, attrs) => ({ state, dispatch, commands }) => {
const type = getMarkType(typeOrName, state.schema)
const hasMarkWithDifferentAttributes = attrs
&& markIsActive(state, type)
&& !markIsActive(state, type, attrs)
if (hasMarkWithDifferentAttributes) {
// @ts-ignore
return commands.updateMark(type, attrs)
}
return originalToggleMark(type, attrs)(state, dispatch)
}