fix more commands for cell selections
This commit is contained in:
@@ -14,9 +14,10 @@ declare module '@tiptap/core' {
|
||||
|
||||
export const clearNodes: RawCommands['clearNodes'] = () => ({ state, tr, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const { from, to } = selection
|
||||
const { ranges } = selection
|
||||
|
||||
state.doc.nodesBetween(from, to, (node, pos) => {
|
||||
ranges.forEach(range => {
|
||||
state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
|
||||
if (!node.type.isText) {
|
||||
const fromPos = tr.doc.resolve(tr.mapping.map(pos + 1))
|
||||
const toPos = tr.doc.resolve(tr.mapping.map(pos + node.nodeSize - 1))
|
||||
@@ -35,6 +36,7 @@ export const clearNodes: RawCommands['clearNodes'] = () => ({ state, tr, dispatc
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -17,13 +17,15 @@ declare module '@tiptap/core' {
|
||||
export const resetNodeAttributes: RawCommands['resetNodeAttributes'] = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const { selection } = tr
|
||||
const { from, to } = selection
|
||||
const { ranges } = selection
|
||||
|
||||
state.doc.nodesBetween(from, to, (node, pos) => {
|
||||
ranges.forEach(range => {
|
||||
state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
|
||||
if (node.type === type && dispatch) {
|
||||
tr.setNodeMarkup(pos, undefined, deleteProps(node.attrs, attributes))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ declare module '@tiptap/core' {
|
||||
|
||||
export const unsetAllMarks: RawCommands['unsetAllMarks'] = () => ({ tr, state, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const { from, to, empty } = selection
|
||||
const { empty, ranges } = selection
|
||||
|
||||
if (empty) {
|
||||
return true
|
||||
@@ -23,7 +23,9 @@ export const unsetAllMarks: RawCommands['unsetAllMarks'] = () => ({ tr, state, d
|
||||
Object
|
||||
.entries(state.schema.marks)
|
||||
.forEach(([, mark]) => {
|
||||
tr.removeMark(from, to, mark as any)
|
||||
ranges.forEach(range => {
|
||||
tr.removeMark(range.$from.pos, range.$to.pos, mark as any)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,10 @@ declare module '@tiptap/core' {
|
||||
export const updateNodeAttributes: RawCommands['updateNodeAttributes'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const { selection } = tr
|
||||
const { from, to } = selection
|
||||
const { ranges } = selection
|
||||
|
||||
state.doc.nodesBetween(from, to, (node, pos) => {
|
||||
ranges.forEach(range => {
|
||||
state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
|
||||
if (node.type === type && dispatch) {
|
||||
tr.setNodeMarkup(pos, undefined, {
|
||||
...node.attrs,
|
||||
@@ -26,6 +27,7 @@ export const updateNodeAttributes: RawCommands['updateNodeAttributes'] = (typeOr
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user