add removeMark command

This commit is contained in:
Philipp Kühn
2020-04-22 14:22:31 +02:00
parent fd4453f7c5
commit fd8f5de375
4 changed files with 77 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import { Editor } from '../Editor'
import { MarkType } from 'prosemirror-model'
import getMarkType from '../utils/getMarkType'
import getMarkRange from '../utils/getMarkRange'
type RemoveMark = (type: string | MarkType) => any
declare module '../Editor' {
interface Editor {
toggleMark: RemoveMark,
}
}
export default (next: Function, editor: Editor): RemoveMark => typeOrName => {
const { view, state, schema } = editor
const { tr, selection } = state
const type = getMarkType(typeOrName, schema)
let { from, to, $from, empty } = selection
if (empty) {
const range = getMarkRange($from, type)
if (range) {
from = range.from
to = range.to
}
}
tr.removeMark(from, to, type)
view.dispatch(tr)
next()
}