(editor: Editor, alignment: string)
| 1 | import type { Editor } from '@tiptap/core'; |
| 2 | |
| 3 | export function setTextAlignment(editor: Editor, alignment: string) { |
| 4 | const { from, to } = editor.state.selection; |
| 5 | const tr = editor.state.tr; |
| 6 | editor.state.doc.nodesBetween(from, to, (node, pos) => { |
| 7 | if (node.isTextblock) { |
| 8 | const prop = 'align' in node.attrs ? 'align' : 'alignment'; |
| 9 | tr.setNodeMarkup(pos, null, { ...node.attrs, [prop]: alignment }); |
| 10 | } |
| 11 | }); |
| 12 | editor.view.dispatch(tr); |
| 13 | } |
no test coverage detected