Files
tiptap/packages/core/src/commands/toggleMark.ts
Philipp Kühn 6f8632f643 fix toggleMark
2020-11-30 21:31:57 +01:00

19 lines
548 B
TypeScript

import { MarkType } from 'prosemirror-model'
import { Command } from '../types'
import getMarkType from '../helpers/getMarkType'
import markIsActive from '../helpers/markIsActive'
/**
* Toggle a mark on and off.
*/
export const toggleMark = (typeOrName: string | MarkType, attributes?: {}): Command => ({ state, commands }) => {
const type = getMarkType(typeOrName, state.schema)
const isActive = markIsActive(state, type, attributes)
if (isActive) {
return commands.unsetMark(type)
}
return commands.setMark(type, attributes)
}