fix updating marks for multiple table cells, fix #186

This commit is contained in:
Philipp Kühn 2021-03-28 21:07:56 +02:00
parent bb1dad7560
commit 9595a23eb8
2 changed files with 21 additions and 14 deletions

View File

@ -16,7 +16,7 @@ declare module '@tiptap/core' {
export const setMark: RawCommands['setMark'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
const { selection } = tr
const { from, to, empty } = selection
const { empty, ranges } = selection
const type = getMarkType(typeOrName, state.schema)
const oldAttributes = getMarkAttributes(state, type)
const newAttributes = {
@ -28,7 +28,9 @@ export const setMark: RawCommands['setMark'] = (typeOrName, attributes = {}) =>
if (empty) {
tr.addStoredMark(type.create(newAttributes))
} else {
tr.addMark(from, to, type.create(newAttributes))
ranges.forEach(range => {
tr.addMark(range.$from.pos, range.$to.pos, type.create(newAttributes))
})
}
}

View File

@ -17,20 +17,25 @@ declare module '@tiptap/core' {
export const unsetMark: RawCommands['unsetMark'] = typeOrName => ({ tr, state, dispatch }) => {
const { selection } = tr
const type = getMarkType(typeOrName, state.schema)
let { from, to } = selection
const { $from, empty } = selection
if (empty) {
const range = getMarkRange($from, type)
if (range) {
from = range.from
to = range.to
}
}
const { $from, empty, ranges } = selection
if (dispatch) {
tr.removeMark(from, to, type)
if (empty) {
let { from, to } = selection
const range = getMarkRange($from, type)
if (range) {
from = range.from
to = range.to
}
tr.removeMark(from, to, type)
} else {
ranges.forEach(range => {
tr.removeMark(range.$from.pos, range.$to.pos, type)
})
}
tr.removeStoredMark(type)
}