From 6f8632f64369c3634540b19f3d781a3df91b81b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Mon, 30 Nov 2020 21:31:57 +0100 Subject: [PATCH] fix toggleMark --- packages/core/src/commands/toggleMark.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/core/src/commands/toggleMark.ts b/packages/core/src/commands/toggleMark.ts index b3714d83..39de0dcf 100644 --- a/packages/core/src/commands/toggleMark.ts +++ b/packages/core/src/commands/toggleMark.ts @@ -1,4 +1,3 @@ -import { toggleMark as originalToggleMark } from 'prosemirror-commands' import { MarkType } from 'prosemirror-model' import { Command } from '../types' import getMarkType from '../helpers/getMarkType' @@ -7,16 +6,13 @@ import markIsActive from '../helpers/markIsActive' /** * Toggle a mark on and off. */ -export const toggleMark = (typeOrName: string | MarkType, attributes?: {}): Command => ({ state, dispatch, commands }) => { +export const toggleMark = (typeOrName: string | MarkType, attributes?: {}): Command => ({ state, commands }) => { const type = getMarkType(typeOrName, state.schema) + const isActive = markIsActive(state, type, attributes) - const hasMarkWithDifferentAttributes = attributes - && markIsActive(state, type) - && !markIsActive(state, type, attributes) - - if (attributes && hasMarkWithDifferentAttributes) { - return commands.setMark(type, attributes) + if (isActive) { + return commands.unsetMark(type) } - return originalToggleMark(type, attributes)(state, dispatch) + return commands.setMark(type, attributes) }