From 08aa7e88bc546eb9789d9d8df321f990fd04a576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 4 Oct 2019 14:16:38 +0200 Subject: [PATCH] use markRange for empty selections in removeMark and updateMark, fix #449 --- packages/tiptap-commands/src/commands/removeMark.js | 13 ++++++++++++- packages/tiptap-commands/src/commands/updateMark.js | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/tiptap-commands/src/commands/removeMark.js b/packages/tiptap-commands/src/commands/removeMark.js index 6483d2749..158caf47a 100644 --- a/packages/tiptap-commands/src/commands/removeMark.js +++ b/packages/tiptap-commands/src/commands/removeMark.js @@ -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)) } } diff --git a/packages/tiptap-commands/src/commands/updateMark.js b/packages/tiptap-commands/src/commands/updateMark.js index eb6c4a16b..4c217cf1f 100644 --- a/packages/tiptap-commands/src/commands/updateMark.js +++ b/packages/tiptap-commands/src/commands/updateMark.js @@ -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))) } }