refactoring
This commit is contained in:
@@ -15,7 +15,11 @@ declare module '../Editor' {
|
|||||||
export const toggleMark: ToggleMarkCommand = (typeOrName, attrs) => ({ state, dispatch, commands }) => {
|
export const toggleMark: ToggleMarkCommand = (typeOrName, attrs) => ({ state, dispatch, commands }) => {
|
||||||
const type = getMarkType(typeOrName, state.schema)
|
const type = getMarkType(typeOrName, state.schema)
|
||||||
|
|
||||||
if (markIsActive(state, type) && !markIsActive(state, type, attrs)) {
|
const hasMarkWithDifferentAttributes = attrs
|
||||||
|
&& markIsActive(state, type)
|
||||||
|
&& !markIsActive(state, type, attrs)
|
||||||
|
|
||||||
|
if (hasMarkWithDifferentAttributes) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return commands.updateMark(type, attrs)
|
return commands.updateMark(type, attrs)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,14 @@ import { EditorState } from 'prosemirror-state'
|
|||||||
import { MarkType } from 'prosemirror-model'
|
import { MarkType } from 'prosemirror-model'
|
||||||
import getMarkAttrs from './getMarkAttrs'
|
import getMarkAttrs from './getMarkAttrs'
|
||||||
|
|
||||||
export default function markHasAttributes(state: EditorState, type: MarkType, attrs?: Object) {
|
export default function markHasAttributes(state: EditorState, type: MarkType, attrs?: { [key: string]: any }) {
|
||||||
return attrs === undefined || JSON.stringify(attrs) === JSON.stringify(
|
if (attrs === undefined) {
|
||||||
getMarkAttrs(state, type),
|
return true
|
||||||
)
|
}
|
||||||
|
|
||||||
|
const originalAttrs: { [key: string]: any } = getMarkAttrs(state, type)
|
||||||
|
|
||||||
|
return Object.keys(attrs).filter((key: string) => {
|
||||||
|
return attrs[key] === originalAttrs[key]
|
||||||
|
}).length
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user