mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-25 21:35:53 +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
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user