mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-15 02:59:01 +08:00
Merge pull request #830 from Chrissi2812/issue-827
fix: link command on multi cell selections
This commit is contained in:
commit
6714faf8e8
@ -2,25 +2,36 @@ import { getMarkRange } from 'tiptap-utils'
|
|||||||
|
|
||||||
export default function (type, attrs) {
|
export default function (type, attrs) {
|
||||||
return (state, dispatch) => {
|
return (state, dispatch) => {
|
||||||
const { tr, selection, doc } = state
|
const {
|
||||||
let { from, to } = selection
|
tr,
|
||||||
const { $from, empty } = selection
|
selection,
|
||||||
|
doc,
|
||||||
|
} = state
|
||||||
|
|
||||||
|
const {
|
||||||
|
ranges,
|
||||||
|
empty,
|
||||||
|
} = selection
|
||||||
|
|
||||||
if (empty) {
|
if (empty) {
|
||||||
const range = getMarkRange($from, type)
|
const { from, to } = getMarkRange(selection.$from, type)
|
||||||
|
if (doc.rangeHasMark(from, to, type)) {
|
||||||
|
tr.removeMark(from, to, type)
|
||||||
|
}
|
||||||
|
|
||||||
from = range.from
|
tr.addMark(from, to, type.create(attrs))
|
||||||
to = range.to
|
} else {
|
||||||
|
ranges.forEach(ref$1 => {
|
||||||
|
const { $to, $from } = ref$1
|
||||||
|
|
||||||
|
if (doc.rangeHasMark($from.pos, $to.pos, type)) {
|
||||||
|
tr.removeMark($from.pos, $to.pos, type)
|
||||||
|
}
|
||||||
|
|
||||||
|
tr.addMark($from.pos, $to.pos, 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)
|
return dispatch(tr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user