diff --git a/packages/core/src/commands/toggleMark.ts b/packages/core/src/commands/toggleMark.ts index 98010f19..4de80b8c 100644 --- a/packages/core/src/commands/toggleMark.ts +++ b/packages/core/src/commands/toggleMark.ts @@ -15,7 +15,11 @@ declare module '../Editor' { export const toggleMark: ToggleMarkCommand = (typeOrName, attrs) => ({ state, dispatch, commands }) => { const type = getMarkType(typeOrName, state.schema) - if (markIsActive(state, type) && !markIsActive(state, type, attrs)) { + const hasMarkWithDifferentAttributes = attrs + && markIsActive(state, type) + && !markIsActive(state, type, attrs) + + if (hasMarkWithDifferentAttributes) { // @ts-ignore return commands.updateMark(type, attrs) } diff --git a/packages/core/src/utils/markHasAttributes.ts b/packages/core/src/utils/markHasAttributes.ts index 76f7a67f..a598c26c 100644 --- a/packages/core/src/utils/markHasAttributes.ts +++ b/packages/core/src/utils/markHasAttributes.ts @@ -2,8 +2,14 @@ import { EditorState } from 'prosemirror-state' import { MarkType } from 'prosemirror-model' import getMarkAttrs from './getMarkAttrs' -export default function markHasAttributes(state: EditorState, type: MarkType, attrs?: Object) { - return attrs === undefined || JSON.stringify(attrs) === JSON.stringify( - getMarkAttrs(state, type), - ) +export default function markHasAttributes(state: EditorState, type: MarkType, attrs?: { [key: string]: any }) { + if (attrs === undefined) { + return true + } + + const originalAttrs: { [key: string]: any } = getMarkAttrs(state, type) + + return Object.keys(attrs).filter((key: string) => { + return attrs[key] === originalAttrs[key] + }).length }