diff --git a/docs/src/docPages/api/commands.md b/docs/src/docPages/api/commands.md index 83d495ad..3dc0c916 100644 --- a/docs/src/docPages/api/commands.md +++ b/docs/src/docPages/api/commands.md @@ -78,24 +78,23 @@ Have a look at all of the core commands listed below. They should give you a goo | .setContent() | Replace the whole document with new content. | ### Nodes & Marks -| Command | Description | -| ---------------------- | ------------------------------------------ | -| .clearNodes() | | -| .removeMark() | | -| .removeMark() | Remove a mark in the current selection. | -| .removeMarks() | | -| .removeMarks() | Remove all marks in the current selection. | -| .resetNodeAttributes() | | -| .selectParentNode() | Select the parent node. | -| .setBlockType() | Replace a given range with a node. | -| .setNodeAttributes() | | -| .splitBlock() | Forks a new node from an existing node. | -| .toggleBlockType() | Toggle a node with another node. | -| .toggleMark() | | -| .toggleMark() | Toggle a mark on and off. | -| .toggleWrap() | | -| .updateMark() | | -| .updateMark() | Update a mark with new attributes. | +| Command | Description | +| ----------------------- | ------------------------------------------ | +| .clearNodes() | | +| .removeMark() | | +| .removeMark() | Remove a mark in the current selection. | +| .removeMarks() | | +| .removeMarks() | Remove all marks in the current selection. | +| .resetNodeAttributes() | | +| .selectParentNode() | Select the parent node. | +| .setBlockType() | Replace a given range with a node. | +| .updateNoteAttributes() | | +| .splitBlock() | Forks a new node from an existing node. | +| .toggleBlockType() | Toggle a node with another node. | +| .toggleMark() | | +| .toggleMark() | Toggle a mark on and off. | +| .toggleWrap() | | +| .updateMarkAttributes() | Update a mark with new attributes. | ### Lists | Command | Description | diff --git a/packages/core/src/commands/updateMark.ts b/packages/core/src/commands/updateMarkAttributes.ts similarity index 77% rename from packages/core/src/commands/updateMark.ts rename to packages/core/src/commands/updateMarkAttributes.ts index a4cb3e92..fb96235c 100644 --- a/packages/core/src/commands/updateMark.ts +++ b/packages/core/src/commands/updateMarkAttributes.ts @@ -4,7 +4,7 @@ import getMarkType from '../utils/getMarkType' import getMarkRange from '../utils/getMarkRange' export default (typeOrName: string | MarkType, attrs: {}): Command => ({ tr, state, dispatch }) => { - const { selection, doc } = tr + const { selection } = tr let { from, to } = selection const { $from, empty } = selection const type = getMarkType(typeOrName, state.schema) @@ -18,11 +18,12 @@ export default (typeOrName: string | MarkType, attrs: {}): Command => ({ tr, sta } } - const hasMark = doc.rangeHasMark(from, to, type) + // TODO: toggleMark? + // const hasMark = doc.rangeHasMark(from, to, type) - if (hasMark && dispatch) { - tr.removeMark(from, to, type) - } + // if (hasMark && dispatch) { + // tr.removeMark(from, to, type) + // } if (dispatch) { tr.addMark(from, to, type.create(attrs)) diff --git a/packages/core/src/commands/setNodeAttributes.ts b/packages/core/src/commands/updateNodeAttributes.ts similarity index 100% rename from packages/core/src/commands/setNodeAttributes.ts rename to packages/core/src/commands/updateNodeAttributes.ts diff --git a/packages/core/src/extensions/commands.ts b/packages/core/src/extensions/commands.ts index 094c6245..4b945ac3 100644 --- a/packages/core/src/extensions/commands.ts +++ b/packages/core/src/extensions/commands.ts @@ -15,7 +15,6 @@ import selectAll from '../commands/selectAll' import selectParentNode from '../commands/selectParentNode' import setBlockType from '../commands/setBlockType' import setContent from '../commands/setContent' -import setNodeAttributes from '../commands/setNodeAttributes' import sinkListItem from '../commands/sinkListItem' import splitBlock from '../commands/splitBlock' import splitListItem from '../commands/splitListItem' @@ -24,7 +23,8 @@ import toggleList from '../commands/toggleList' import toggleMark from '../commands/toggleMark' import toggleWrap from '../commands/toggleWrap' import tryCommand from '../commands/try' -import updateMark from '../commands/updateMark' +import updateMarkAttributes from '../commands/updateMarkAttributes' +import updateNodeAttributes from '../commands/updateNodeAttributes' import wrapInList from '../commands/wrapInList' export const Commands = createExtension({ @@ -46,7 +46,6 @@ export const Commands = createExtension({ selectParentNode, setBlockType, setContent, - setNodeAttributes, sinkListItem, splitBlock, splitListItem, @@ -55,7 +54,8 @@ export const Commands = createExtension({ toggleMark, toggleWrap, try: tryCommand, - updateMark, + updateMarkAttributes, + updateNodeAttributes, wrapInList, } }, diff --git a/packages/extension-link/index.ts b/packages/extension-link/index.ts index 42e261c9..d31faa3b 100644 --- a/packages/extension-link/index.ts +++ b/packages/extension-link/index.ts @@ -50,7 +50,7 @@ const Link = createMark({ return commands.removeMark('link') } - return commands.updateMark('link', options) + return commands.updateMarkAttributes('link', options) }, } }, diff --git a/packages/extension-text-align/index.ts b/packages/extension-text-align/index.ts index dcf499eb..a237d470 100644 --- a/packages/extension-text-align/index.ts +++ b/packages/extension-text-align/index.ts @@ -39,7 +39,7 @@ const TextAlign = createExtension({ return false } - return commands.setNodeAttributes({ textAlign: alignment }) + return commands.updateNodeAttributes({ textAlign: alignment }) }, } },