rename updateMark and setNodeAttributes, fix #38

This commit is contained in:
Philipp Kühn
2020-11-05 21:59:04 +01:00
parent 73822bd6c9
commit 3ce0e791f6
6 changed files with 29 additions and 29 deletions

View File

@@ -79,7 +79,7 @@ Have a look at all of the core commands listed below. They should give you a goo
### Nodes & Marks ### Nodes & Marks
| Command | Description | | Command | Description |
| ---------------------- | ------------------------------------------ | | ----------------------- | ------------------------------------------ |
| .clearNodes() | | | .clearNodes() | |
| .removeMark() | | | .removeMark() | |
| .removeMark() | Remove a mark in the current selection. | | .removeMark() | Remove a mark in the current selection. |
@@ -88,14 +88,13 @@ Have a look at all of the core commands listed below. They should give you a goo
| .resetNodeAttributes() | | | .resetNodeAttributes() | |
| .selectParentNode() | Select the parent node. | | .selectParentNode() | Select the parent node. |
| .setBlockType() | Replace a given range with a node. | | .setBlockType() | Replace a given range with a node. |
| .setNodeAttributes() | | | .updateNoteAttributes() | |
| .splitBlock() | Forks a new node from an existing node. | | .splitBlock() | Forks a new node from an existing node. |
| .toggleBlockType() | Toggle a node with another node. | | .toggleBlockType() | Toggle a node with another node. |
| .toggleMark() | | | .toggleMark() | |
| .toggleMark() | Toggle a mark on and off. | | .toggleMark() | Toggle a mark on and off. |
| .toggleWrap() | | | .toggleWrap() | |
| .updateMark() | | | .updateMarkAttributes() | Update a mark with new attributes. |
| .updateMark() | Update a mark with new attributes. |
### Lists ### Lists
| Command | Description | | Command | Description |

View File

@@ -4,7 +4,7 @@ import getMarkType from '../utils/getMarkType'
import getMarkRange from '../utils/getMarkRange' import getMarkRange from '../utils/getMarkRange'
export default (typeOrName: string | MarkType, attrs: {}): Command => ({ tr, state, dispatch }) => { export default (typeOrName: string | MarkType, attrs: {}): Command => ({ tr, state, dispatch }) => {
const { selection, doc } = tr const { selection } = tr
let { from, to } = selection let { from, to } = selection
const { $from, empty } = selection const { $from, empty } = selection
const type = getMarkType(typeOrName, state.schema) 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) { // if (hasMark && dispatch) {
tr.removeMark(from, to, type) // tr.removeMark(from, to, type)
} // }
if (dispatch) { if (dispatch) {
tr.addMark(from, to, type.create(attrs)) tr.addMark(from, to, type.create(attrs))

View File

@@ -15,7 +15,6 @@ import selectAll from '../commands/selectAll'
import selectParentNode from '../commands/selectParentNode' import selectParentNode from '../commands/selectParentNode'
import setBlockType from '../commands/setBlockType' import setBlockType from '../commands/setBlockType'
import setContent from '../commands/setContent' import setContent from '../commands/setContent'
import setNodeAttributes from '../commands/setNodeAttributes'
import sinkListItem from '../commands/sinkListItem' import sinkListItem from '../commands/sinkListItem'
import splitBlock from '../commands/splitBlock' import splitBlock from '../commands/splitBlock'
import splitListItem from '../commands/splitListItem' import splitListItem from '../commands/splitListItem'
@@ -24,7 +23,8 @@ import toggleList from '../commands/toggleList'
import toggleMark from '../commands/toggleMark' import toggleMark from '../commands/toggleMark'
import toggleWrap from '../commands/toggleWrap' import toggleWrap from '../commands/toggleWrap'
import tryCommand from '../commands/try' 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' import wrapInList from '../commands/wrapInList'
export const Commands = createExtension({ export const Commands = createExtension({
@@ -46,7 +46,6 @@ export const Commands = createExtension({
selectParentNode, selectParentNode,
setBlockType, setBlockType,
setContent, setContent,
setNodeAttributes,
sinkListItem, sinkListItem,
splitBlock, splitBlock,
splitListItem, splitListItem,
@@ -55,7 +54,8 @@ export const Commands = createExtension({
toggleMark, toggleMark,
toggleWrap, toggleWrap,
try: tryCommand, try: tryCommand,
updateMark, updateMarkAttributes,
updateNodeAttributes,
wrapInList, wrapInList,
} }
}, },

View File

@@ -50,7 +50,7 @@ const Link = createMark({
return commands.removeMark('link') return commands.removeMark('link')
} }
return commands.updateMark('link', options) return commands.updateMarkAttributes('link', options)
}, },
} }
}, },

View File

@@ -39,7 +39,7 @@ const TextAlign = createExtension({
return false return false
} }
return commands.setNodeAttributes({ textAlign: alignment }) return commands.updateNodeAttributes({ textAlign: alignment })
}, },
} }
}, },