diff --git a/packages/core/src/commands/addMark.ts b/packages/core/src/commands/setMark.ts similarity index 91% rename from packages/core/src/commands/addMark.ts rename to packages/core/src/commands/setMark.ts index cc093923c..705f48635 100644 --- a/packages/core/src/commands/addMark.ts +++ b/packages/core/src/commands/setMark.ts @@ -6,7 +6,7 @@ import getMarkAttributes from '../utils/getMarkAttributes' /** * Add a mark with new attributes. */ -export const addMark = (typeOrName: string | MarkType, attributes?: {}): Command => ({ tr, state, dispatch }) => { +export const setMark = (typeOrName: string | MarkType, attributes?: {}): Command => ({ tr, state, dispatch }) => { const { selection } = tr const { from, to, empty } = selection const type = getMarkType(typeOrName, state.schema) diff --git a/packages/core/src/commands/toggleMark.ts b/packages/core/src/commands/toggleMark.ts index 0b3571bbe..72aab77d2 100644 --- a/packages/core/src/commands/toggleMark.ts +++ b/packages/core/src/commands/toggleMark.ts @@ -15,7 +15,7 @@ export const toggleMark = (typeOrName: string | MarkType, attributes?: {}): Comm && !markIsActive(state, type, attributes) if (attributes && hasMarkWithDifferentAttributes) { - return commands.addMark(type, attributes) + return commands.setMark(type, attributes) } return originalToggleMark(type, attributes)(state, dispatch) diff --git a/packages/core/src/extensions/commands.ts b/packages/core/src/extensions/commands.ts index 02e968977..c8b6ebc70 100644 --- a/packages/core/src/extensions/commands.ts +++ b/packages/core/src/extensions/commands.ts @@ -1,5 +1,5 @@ import { Extension } from '../Extension' -import * as addMark from '../commands/addMark' +import * as setMark from '../commands/setMark' import * as blur from '../commands/blur' import * as clearContent from '../commands/clearContent' import * as command from '../commands/command' @@ -34,7 +34,7 @@ import * as wrapInList from '../commands/wrapInList' export const Commands = Extension.create({ addCommands() { return { - ...addMark, + ...setMark, ...blur, ...clearContent, ...clearNodes, diff --git a/packages/extension-bold/src/index.ts b/packages/extension-bold/src/index.ts index 023563587..88143ce77 100644 --- a/packages/extension-bold/src/index.ts +++ b/packages/extension-bold/src/index.ts @@ -49,7 +49,7 @@ const Bold = Mark.create({ * Set a bold mark */ setBold: (): Command => ({ commands }) => { - return commands.addMark('bold') + return commands.setMark('bold') }, /** * Toggle a bold mark diff --git a/packages/extension-code/src/index.ts b/packages/extension-code/src/index.ts index 33b3a547e..182ee32ca 100644 --- a/packages/extension-code/src/index.ts +++ b/packages/extension-code/src/index.ts @@ -39,7 +39,7 @@ const Code = Mark.create({ * Set a code mark */ setCode: (): Command => ({ commands }) => { - return commands.addMark('code') + return commands.setMark('code') }, /** * Toggle inline code @@ -51,7 +51,7 @@ const Code = Mark.create({ * Unset a code mark */ unsetCode: (): Command => ({ commands }) => { - return commands.addMark('code') + return commands.removeMark('code') }, } }, diff --git a/packages/extension-font-family/src/index.ts b/packages/extension-font-family/src/index.ts index c29cad735..629f45b2f 100644 --- a/packages/extension-font-family/src/index.ts +++ b/packages/extension-font-family/src/index.ts @@ -42,7 +42,7 @@ const FontFamily = Extension.create({ */ setFontFamily: (fontFamily: string): Command => ({ chain }) => { return chain() - .addMark('textStyle', { fontFamily }) + .setMark('textStyle', { fontFamily }) .run() }, /** @@ -50,7 +50,7 @@ const FontFamily = Extension.create({ */ unsetFontFamily: (): Command => ({ chain }) => { return chain() - .addMark('textStyle', { fontFamily: null }) + .setMark('textStyle', { fontFamily: null }) .removeEmptyTextStyle() .run() }, diff --git a/packages/extension-highlight/src/index.ts b/packages/extension-highlight/src/index.ts index 9a92a029d..0b5e75eb9 100644 --- a/packages/extension-highlight/src/index.ts +++ b/packages/extension-highlight/src/index.ts @@ -62,7 +62,7 @@ const Highlight = Mark.create({ * Set a highlight mark */ setHighlight: (attributes?: { color: string }): Command => ({ commands }) => { - return commands.addMark('highlight', attributes) + return commands.setMark('highlight', attributes) }, /** * Toggle a highlight mark diff --git a/packages/extension-italic/src/index.ts b/packages/extension-italic/src/index.ts index a76b78e68..c8e331747 100644 --- a/packages/extension-italic/src/index.ts +++ b/packages/extension-italic/src/index.ts @@ -48,7 +48,7 @@ const Italic = Mark.create({ * Set an italic mark */ setItalic: (): Command => ({ commands }) => { - return commands.addMark('italic') + return commands.setMark('italic') }, /** * Toggle an italic mark @@ -60,7 +60,7 @@ const Italic = Mark.create({ * Unset an italic mark */ unsetItalic: (): Command => ({ commands }) => { - return commands.addMark('italic') + return commands.removeMark('italic') }, } }, diff --git a/packages/extension-link/src/index.ts b/packages/extension-link/src/index.ts index 4325639e8..8d464aabb 100644 --- a/packages/extension-link/src/index.ts +++ b/packages/extension-link/src/index.ts @@ -50,7 +50,7 @@ const Link = Mark.create({ * Set a link mark */ setLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => { - return commands.addMark('link', attributes) + return commands.setMark('link', attributes) }, /** * Toggle a link mark diff --git a/packages/extension-strike/src/index.ts b/packages/extension-strike/src/index.ts index f7ebaf085..583f1a744 100644 --- a/packages/extension-strike/src/index.ts +++ b/packages/extension-strike/src/index.ts @@ -48,7 +48,7 @@ const Strike = Mark.create({ * Set a strike mark */ setStrike: (): Command => ({ commands }) => { - return commands.addMark('strike') + return commands.setMark('strike') }, /** * Toggle a strike mark @@ -60,7 +60,7 @@ const Strike = Mark.create({ * Unset a strike mark */ unsetStrike: (): Command => ({ commands }) => { - return commands.addMark('strike') + return commands.removeMark('strike') }, } }, diff --git a/packages/extension-underline/src/index.ts b/packages/extension-underline/src/index.ts index adcff4e1a..763290cf9 100644 --- a/packages/extension-underline/src/index.ts +++ b/packages/extension-underline/src/index.ts @@ -34,7 +34,7 @@ const Underline = Mark.create({ * Set an underline mark */ setUnderline: (): Command => ({ commands }) => { - return commands.addMark('underline') + return commands.setMark('underline') }, /** * Toggle an underline mark @@ -46,7 +46,7 @@ const Underline = Mark.create({ * Unset an underline mark */ unsetUnderline: (): Command => ({ commands }) => { - return commands.addMark('underline') + return commands.removeMark('underline') }, } },