tiptap/packages/core/src/commands/updateNodeAttributes.ts

18 lines
389 B
TypeScript
Raw Normal View History

2020-11-17 04:42:35 +08:00
import { Command } from '../types'
2020-11-05 05:38:52 +08:00
export default (attributes: {}): Command => ({ tr, state, dispatch }) => {
const { selection } = tr
const { from, to } = selection
state.doc.nodesBetween(from, to, (node, pos) => {
if (!node.type.isText && dispatch) {
tr.setNodeMarkup(pos, undefined, {
...node.attrs,
...attributes,
})
2020-11-05 05:38:52 +08:00
}
})
return true
}