fix toggleMark
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import { toggleMark as originalToggleMark } from 'prosemirror-commands'
|
|
||||||
import { MarkType } from 'prosemirror-model'
|
import { MarkType } from 'prosemirror-model'
|
||||||
import { Command } from '../types'
|
import { Command } from '../types'
|
||||||
import getMarkType from '../helpers/getMarkType'
|
import getMarkType from '../helpers/getMarkType'
|
||||||
@@ -7,16 +6,13 @@ import markIsActive from '../helpers/markIsActive'
|
|||||||
/**
|
/**
|
||||||
* Toggle a mark on and off.
|
* Toggle a mark on and off.
|
||||||
*/
|
*/
|
||||||
export const toggleMark = (typeOrName: string | MarkType, attributes?: {}): Command => ({ state, dispatch, commands }) => {
|
export const toggleMark = (typeOrName: string | MarkType, attributes?: {}): Command => ({ state, commands }) => {
|
||||||
const type = getMarkType(typeOrName, state.schema)
|
const type = getMarkType(typeOrName, state.schema)
|
||||||
|
const isActive = markIsActive(state, type, attributes)
|
||||||
|
|
||||||
const hasMarkWithDifferentAttributes = attributes
|
if (isActive) {
|
||||||
&& markIsActive(state, type)
|
return commands.unsetMark(type)
|
||||||
&& !markIsActive(state, type, attributes)
|
|
||||||
|
|
||||||
if (attributes && hasMarkWithDifferentAttributes) {
|
|
||||||
return commands.setMark(type, attributes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return originalToggleMark(type, attributes)(state, dispatch)
|
return commands.setMark(type, attributes)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user