add extendMarkRange command

This commit is contained in:
Philipp Kühn
2020-11-06 13:38:21 +01:00
parent dc62ac1326
commit ab1d789161
2 changed files with 25 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import { TextSelection } from 'prosemirror-state'
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 type = getMarkType(typeOrName, state.schema)
const { doc, selection } = tr
const { $from, empty } = selection
if (empty && dispatch) {
const range = getMarkRange($from, type)
if (range) {
const newSelection = TextSelection.create(doc, range.from, range.to)
tr.setSelection(newSelection)
}
}
return true
}