remove updateMarkAttributes
This commit is contained in:
@@ -1,14 +1,24 @@
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import getMarkType from '../utils/getMarkType'
|
||||
import getMarkAttributes from '../utils/getMarkAttributes'
|
||||
|
||||
export default (typeOrName: string | MarkType, attributes?: {}): Command => ({ tr, state, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const { from, to, empty } = selection
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
const { from, to } = selection
|
||||
const oldAttributes = getMarkAttributes(state, type)
|
||||
const newAttributes = {
|
||||
...oldAttributes,
|
||||
...attributes,
|
||||
}
|
||||
|
||||
if (dispatch) {
|
||||
tr.addMark(from, to, type.create(attributes))
|
||||
if (empty) {
|
||||
tr.addStoredMark(type.create(newAttributes))
|
||||
} else {
|
||||
tr.addMark(from, to, type.create(newAttributes))
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
@@ -12,7 +12,7 @@ export default (typeOrName: string | MarkType, attributes?: {}): Command => ({ s
|
||||
&& !markIsActive(state, type, attributes)
|
||||
|
||||
if (attributes && hasMarkWithDifferentAttributes) {
|
||||
return commands.updateMarkAttributes(type, attributes)
|
||||
return commands.addMark(type, attributes)
|
||||
}
|
||||
|
||||
return toggleMark(type, attributes)(state, dispatch)
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import getMarkType from '../utils/getMarkType'
|
||||
import getMarkAttributes from '../utils/getMarkAttributes'
|
||||
|
||||
export default (typeOrName: string | MarkType, attributes: {}): Command => ({ tr, state, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const { from, to, empty } = selection
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
const oldAttributes = getMarkAttributes(state, type)
|
||||
const newAttributes = {
|
||||
...oldAttributes,
|
||||
...attributes,
|
||||
}
|
||||
|
||||
if (dispatch) {
|
||||
if (empty) {
|
||||
tr.addStoredMark(type.create(newAttributes))
|
||||
} else {
|
||||
tr.addMark(from, to, type.create(newAttributes))
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user