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.
*/
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)

View File

@ -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)

View File

@ -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,

View File

@ -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

View File

@ -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')
},
}
},

View File

@ -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()
},

View File

@ -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

View File

@ -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')
},
}
},

View File

@ -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

View File

@ -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')
},
}
},

View File

@ -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')
},
}
},