diff --git a/packages/core/src/commands/setMark.ts b/packages/core/src/commands/setMark.ts index 4154167b..24e7941f 100644 --- a/packages/core/src/commands/setMark.ts +++ b/packages/core/src/commands/setMark.ts @@ -16,7 +16,7 @@ declare module '@tiptap/core' { export const setMark: RawCommands['setMark'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => { const { selection } = tr - const { from, to, empty } = selection + const { empty, ranges } = selection const type = getMarkType(typeOrName, state.schema) const oldAttributes = getMarkAttributes(state, type) const newAttributes = { @@ -28,7 +28,9 @@ export const setMark: RawCommands['setMark'] = (typeOrName, attributes = {}) => if (empty) { tr.addStoredMark(type.create(newAttributes)) } else { - tr.addMark(from, to, type.create(newAttributes)) + ranges.forEach(range => { + tr.addMark(range.$from.pos, range.$to.pos, type.create(newAttributes)) + }) } } diff --git a/packages/core/src/commands/unsetMark.ts b/packages/core/src/commands/unsetMark.ts index a9ff6a57..bee3e197 100644 --- a/packages/core/src/commands/unsetMark.ts +++ b/packages/core/src/commands/unsetMark.ts @@ -17,20 +17,25 @@ declare module '@tiptap/core' { export const unsetMark: RawCommands['unsetMark'] = typeOrName => ({ tr, state, dispatch }) => { const { selection } = tr const type = getMarkType(typeOrName, state.schema) - let { from, to } = selection - const { $from, empty } = selection - - if (empty) { - const range = getMarkRange($from, type) - - if (range) { - from = range.from - to = range.to - } - } + const { $from, empty, ranges } = selection if (dispatch) { - tr.removeMark(from, to, type) + if (empty) { + let { from, to } = selection + const range = getMarkRange($from, type) + + if (range) { + from = range.from + to = range.to + } + + tr.removeMark(from, to, type) + } else { + ranges.forEach(range => { + tr.removeMark(range.$from.pos, range.$to.pos, type) + }) + } + tr.removeStoredMark(type) }