mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-15 02:59:01 +08:00
remove mark before add mark, fix #452
This commit is contained in:
parent
4f3260d685
commit
7a56da6315
@ -2,8 +2,9 @@ import { getMarkRange } from 'tiptap-utils'
|
||||
|
||||
export default function (type) {
|
||||
return (state, dispatch) => {
|
||||
let { from, to } = state.selection
|
||||
const { $from, empty } = state.selection
|
||||
const { tr, selection } = state
|
||||
let { from, to } = selection
|
||||
const { $from, empty } = selection
|
||||
|
||||
if (empty) {
|
||||
const range = getMarkRange($from, type)
|
||||
@ -12,6 +13,8 @@ export default function (type) {
|
||||
to = range.to
|
||||
}
|
||||
|
||||
return dispatch(state.tr.removeMark(from, to, type))
|
||||
tr.removeMark(from, to, type)
|
||||
|
||||
return dispatch(tr)
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,9 @@ import { getMarkRange } from 'tiptap-utils'
|
||||
|
||||
export default function (type, attrs) {
|
||||
return (state, dispatch) => {
|
||||
let { from, to } = state.selection
|
||||
const { $from, empty } = state.selection
|
||||
const { tr, selection, doc } = state
|
||||
let { from, to } = selection
|
||||
const { $from, empty } = selection
|
||||
|
||||
if (empty) {
|
||||
const range = getMarkRange($from, type)
|
||||
@ -12,6 +13,14 @@ export default function (type, attrs) {
|
||||
to = range.to
|
||||
}
|
||||
|
||||
return dispatch(state.tr.addMark(from, to, type.create(attrs)))
|
||||
const hasMark = doc.rangeHasMark(from, to, type)
|
||||
|
||||
if (hasMark) {
|
||||
tr.removeMark(from, to, type)
|
||||
}
|
||||
|
||||
tr.addMark(from, to, type.create(attrs))
|
||||
|
||||
return dispatch(tr)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user