mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-22 09:25:53 +08:00
27 lines
622 B
TypeScript
27 lines
622 B
TypeScript
|
import { MarkType } from 'prosemirror-model'
|
||
|
import { Command } from '../Editor'
|
||
|
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
|
||
|
}
|