use markRange for empty selections in removeMark and updateMark, fix #449

This commit is contained in:
Philipp Kühn 2019-10-04 14:16:38 +02:00
parent 103d2b16a0
commit 08aa7e88bc
2 changed files with 24 additions and 2 deletions

View File

@ -1,6 +1,17 @@
import { getMarkRange } from 'tiptap-utils'
export default function (type) {
return (state, dispatch) => {
const { from, to } = state.selection
let { from, to } = state.selection
const { $from, empty } = state.selection
if (empty) {
const range = getMarkRange($from, type)
from = range.from
to = range.to
}
return dispatch(state.tr.removeMark(from, to, type))
}
}

View File

@ -1,6 +1,17 @@
import { getMarkRange } from 'tiptap-utils'
export default function (type, attrs) {
return (state, dispatch) => {
const { from, to } = state.selection
let { from, to } = state.selection
const { $from, empty } = state.selection
if (empty) {
const range = getMarkRange($from, type)
from = range.from
to = range.to
}
return dispatch(state.tr.addMark(from, to, type.create(attrs)))
}
}