MCPcopy Index your code
hub / github.com/resend/react-email / setTextAlignment

Function setTextAlignment

packages/editor/src/utils/set-text-alignment.ts:3–13  ·  view source on GitHub ↗
(editor: Editor, alignment: string)

Source from the content-addressed store, hash-verified

1import type { Editor } from '@tiptap/core';
2
3export 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}

Callers 4

BubbleMenuAlignRightFunction · 0.90
BubbleMenuAlignCenterFunction · 0.90
BubbleMenuAlignLeftFunction · 0.90

Calls 1

dispatchMethod · 0.80

Tested by

no test coverage detected