rename addMark to setMark

This commit is contained in:
Philipp Kühn 2020-11-18 17:36:00 +01:00
parent 1b45acd5d5
commit e3a3d99c51
11 changed files with 17 additions and 17 deletions

View File

@ -6,7 +6,7 @@ import getMarkAttributes from '../utils/getMarkAttributes'
/** /**
* Add a mark with new attributes. * 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 { selection } = tr
const { from, to, empty } = selection const { from, to, empty } = selection
const type = getMarkType(typeOrName, state.schema) const type = getMarkType(typeOrName, state.schema)

View File

@ -15,7 +15,7 @@ export const toggleMark = (typeOrName: string | MarkType, attributes?: {}): Comm
&& !markIsActive(state, type, attributes) && !markIsActive(state, type, attributes)
if (attributes && hasMarkWithDifferentAttributes) { if (attributes && hasMarkWithDifferentAttributes) {
return commands.addMark(type, attributes) return commands.setMark(type, attributes)
} }
return originalToggleMark(type, attributes)(state, dispatch) return originalToggleMark(type, attributes)(state, dispatch)

View File

@ -1,5 +1,5 @@
import { Extension } from '../Extension' import { Extension } from '../Extension'
import * as addMark from '../commands/addMark' import * as setMark from '../commands/setMark'
import * as blur from '../commands/blur' import * as blur from '../commands/blur'
import * as clearContent from '../commands/clearContent' import * as clearContent from '../commands/clearContent'
import * as command from '../commands/command' import * as command from '../commands/command'
@ -34,7 +34,7 @@ import * as wrapInList from '../commands/wrapInList'
export const Commands = Extension.create({ export const Commands = Extension.create({
addCommands() { addCommands() {
return { return {
...addMark, ...setMark,
...blur, ...blur,
...clearContent, ...clearContent,
...clearNodes, ...clearNodes,

View File

@ -49,7 +49,7 @@ const Bold = Mark.create({
* Set a bold mark * Set a bold mark
*/ */
setBold: (): Command => ({ commands }) => { setBold: (): Command => ({ commands }) => {
return commands.addMark('bold') return commands.setMark('bold')
}, },
/** /**
* Toggle a bold mark * Toggle a bold mark

View File

@ -39,7 +39,7 @@ const Code = Mark.create({
* Set a code mark * Set a code mark
*/ */
setCode: (): Command => ({ commands }) => { setCode: (): Command => ({ commands }) => {
return commands.addMark('code') return commands.setMark('code')
}, },
/** /**
* Toggle inline code * Toggle inline code
@ -51,7 +51,7 @@ const Code = Mark.create({
* Unset a code mark * Unset a code mark
*/ */
unsetCode: (): Command => ({ commands }) => { unsetCode: (): Command => ({ commands }) => {
return commands.addMark('code') return commands.removeMark('code')
}, },
} }
}, },

View File

@ -42,7 +42,7 @@ const FontFamily = Extension.create({
*/ */
setFontFamily: (fontFamily: string): Command => ({ chain }) => { setFontFamily: (fontFamily: string): Command => ({ chain }) => {
return chain() return chain()
.addMark('textStyle', { fontFamily }) .setMark('textStyle', { fontFamily })
.run() .run()
}, },
/** /**
@ -50,7 +50,7 @@ const FontFamily = Extension.create({
*/ */
unsetFontFamily: (): Command => ({ chain }) => { unsetFontFamily: (): Command => ({ chain }) => {
return chain() return chain()
.addMark('textStyle', { fontFamily: null }) .setMark('textStyle', { fontFamily: null })
.removeEmptyTextStyle() .removeEmptyTextStyle()
.run() .run()
}, },

View File

@ -62,7 +62,7 @@ const Highlight = Mark.create({
* Set a highlight mark * Set a highlight mark
*/ */
setHighlight: (attributes?: { color: string }): Command => ({ commands }) => { setHighlight: (attributes?: { color: string }): Command => ({ commands }) => {
return commands.addMark('highlight', attributes) return commands.setMark('highlight', attributes)
}, },
/** /**
* Toggle a highlight mark * Toggle a highlight mark

View File

@ -48,7 +48,7 @@ const Italic = Mark.create({
* Set an italic mark * Set an italic mark
*/ */
setItalic: (): Command => ({ commands }) => { setItalic: (): Command => ({ commands }) => {
return commands.addMark('italic') return commands.setMark('italic')
}, },
/** /**
* Toggle an italic mark * Toggle an italic mark
@ -60,7 +60,7 @@ const Italic = Mark.create({
* Unset an italic mark * Unset an italic mark
*/ */
unsetItalic: (): Command => ({ commands }) => { unsetItalic: (): Command => ({ commands }) => {
return commands.addMark('italic') return commands.removeMark('italic')
}, },
} }
}, },

View File

@ -50,7 +50,7 @@ const Link = Mark.create({
* Set a link mark * Set a link mark
*/ */
setLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => { setLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => {
return commands.addMark('link', attributes) return commands.setMark('link', attributes)
}, },
/** /**
* Toggle a link mark * Toggle a link mark

View File

@ -48,7 +48,7 @@ const Strike = Mark.create({
* Set a strike mark * Set a strike mark
*/ */
setStrike: (): Command => ({ commands }) => { setStrike: (): Command => ({ commands }) => {
return commands.addMark('strike') return commands.setMark('strike')
}, },
/** /**
* Toggle a strike mark * Toggle a strike mark
@ -60,7 +60,7 @@ const Strike = Mark.create({
* Unset a strike mark * Unset a strike mark
*/ */
unsetStrike: (): Command => ({ commands }) => { unsetStrike: (): Command => ({ commands }) => {
return commands.addMark('strike') return commands.removeMark('strike')
}, },
} }
}, },

View File

@ -34,7 +34,7 @@ const Underline = Mark.create({
* Set an underline mark * Set an underline mark
*/ */
setUnderline: (): Command => ({ commands }) => { setUnderline: (): Command => ({ commands }) => {
return commands.addMark('underline') return commands.setMark('underline')
}, },
/** /**
* Toggle an underline mark * Toggle an underline mark
@ -46,7 +46,7 @@ const Underline = Mark.create({
* Unset an underline mark * Unset an underline mark
*/ */
unsetUnderline: (): Command => ({ commands }) => { unsetUnderline: (): Command => ({ commands }) => {
return commands.addMark('underline') return commands.removeMark('underline')
}, },
} }
}, },