Merge branch 'main' into feature/new-highlight-extension
# Conflicts: # docs/src/docPages/api/extensions.md # docs/src/links.yaml # packages/core/src/extensions/toggleMark.ts
This commit is contained in:
19
packages/core/src/commands/toggleMark.ts
Normal file
19
packages/core/src/commands/toggleMark.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { toggleMark } from 'prosemirror-commands'
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../Editor'
|
||||
import getMarkType from '../utils/getMarkType'
|
||||
import markIsActive from '../utils/markIsActive'
|
||||
|
||||
export default (typeOrName: string | MarkType, attrs?: {}): Command => ({ state, dispatch, commands }) => {
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
|
||||
const hasMarkWithDifferentAttributes = attrs
|
||||
&& markIsActive(state, type)
|
||||
&& !markIsActive(state, type, attrs)
|
||||
|
||||
if (attrs && hasMarkWithDifferentAttributes) {
|
||||
return commands.updateMark(type, attrs)
|
||||
}
|
||||
|
||||
return toggleMark(type)(state, dispatch)
|
||||
}
|
||||
Reference in New Issue
Block a user