tiptap/packages/core/src/commands/removeMark.ts

27 lines
621 B
TypeScript
Raw Normal View History

2020-11-05 05:38:52 +08:00
import { MarkType } from 'prosemirror-model'
2020-11-17 04:42:35 +08:00
import { Command } from '../types'
2020-11-05 05:38:52 +08:00
import getMarkType from '../utils/getMarkType'
import getMarkRange from '../utils/getMarkRange'
export default (typeOrName: string | MarkType): Command => ({ tr, state, dispatch }) => {
const { selection } = tr
const type = getMarkType(typeOrName, state.schema)
let { from, to } = selection
const { $from, empty } = selection
if (empty) {
const range = getMarkRange($from, type)
if (range) {
from = range.from
to = range.to
}
}
if (dispatch) {
tr.removeMark(from, to, type)
}
return true
}