mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-29 08:19:34 +08:00
fix updating marks for multiple table cells, fix #186
This commit is contained in:
parent
bb1dad7560
commit
9595a23eb8
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
const { $from, empty, ranges } = selection
|
||||
|
||||
if (dispatch) {
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
if (dispatch) {
|
||||
tr.removeMark(from, to, type)
|
||||
tr.removeStoredMark(type)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user