diff --git a/packages/tiptap-commands/src/commands/removeMark.js b/packages/tiptap-commands/src/commands/removeMark.js index 158caf47a..4c967a698 100644 --- a/packages/tiptap-commands/src/commands/removeMark.js +++ b/packages/tiptap-commands/src/commands/removeMark.js @@ -2,8 +2,9 @@ import { getMarkRange } from 'tiptap-utils' export default function (type) { return (state, dispatch) => { - let { from, to } = state.selection - const { $from, empty } = state.selection + const { tr, selection } = state + let { from, to } = selection + const { $from, empty } = selection if (empty) { const range = getMarkRange($from, type) @@ -12,6 +13,8 @@ export default function (type) { to = range.to } - return dispatch(state.tr.removeMark(from, to, type)) + tr.removeMark(from, to, type) + + return dispatch(tr) } } diff --git a/packages/tiptap-commands/src/commands/updateMark.js b/packages/tiptap-commands/src/commands/updateMark.js index 4c217cf1f..0082ae260 100644 --- a/packages/tiptap-commands/src/commands/updateMark.js +++ b/packages/tiptap-commands/src/commands/updateMark.js @@ -2,8 +2,9 @@ import { getMarkRange } from 'tiptap-utils' export default function (type, attrs) { return (state, dispatch) => { - let { from, to } = state.selection - const { $from, empty } = state.selection + const { tr, selection, doc } = state + let { from, to } = selection + const { $from, empty } = selection if (empty) { const range = getMarkRange($from, type) @@ -12,6 +13,14 @@ export default function (type, attrs) { to = range.to } - return dispatch(state.tr.addMark(from, to, type.create(attrs))) + const hasMark = doc.rangeHasMark(from, to, type) + + if (hasMark) { + tr.removeMark(from, to, type) + } + + tr.addMark(from, to, type.create(attrs)) + + return dispatch(tr) } }