add addMark command

This commit is contained in:
Philipp Kühn
2020-11-17 21:38:15 +01:00
parent 127d99eb26
commit 0354f02842
2 changed files with 20 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
import { MarkType } from 'prosemirror-model'
import { Command } from '../types'
import getMarkType from '../utils/getMarkType'
export default (typeOrName: string | MarkType, attributes?: {}): Command => ({ tr, state, dispatch }) => {
const { selection } = tr
const type = getMarkType(typeOrName, state.schema)
const { from, to } = selection
if (dispatch) {
tr.addMark(from, to, type.create(attributes))
}
return true
}