diff --git a/src/components/forms/custom-form-builder.tsx b/src/components/forms/custom-form-builder.tsx index 638baf8..b135bb9 100644 --- a/src/components/forms/custom-form-builder.tsx +++ b/src/components/forms/custom-form-builder.tsx @@ -356,19 +356,39 @@ export function CustomFormBuilder() { const INDENT_STEP = 36; // ~0.5" + const activeIndentNode = (): "heading" | "paragraph" | null => { + if (!editor) return null; + if (editor.isActive("heading")) return "heading"; + if (editor.isActive("paragraph")) return "paragraph"; + return null; + }; + const indent = () => { if (!editor) return; - const cur = Number(editor.getAttributes("paragraph").indent ?? 0); - editor.chain().focus().updateAttributes("paragraph", { indent: cur + INDENT_STEP }).run(); + // Lists: nest the item instead of changing padding + if (editor.isActive("listItem")) { + editor.chain().focus().sinkListItem("listItem").run(); + return; + } + const node = activeIndentNode(); + if (!node) return; + const cur = Number(editor.getAttributes(node).indent ?? 0); + editor.chain().focus().updateAttributes(node, { indent: cur + INDENT_STEP }).run(); }; const outdent = () => { if (!editor) return; - const cur = Number(editor.getAttributes("paragraph").indent ?? 0); + if (editor.isActive("listItem")) { + editor.chain().focus().liftListItem("listItem").run(); + return; + } + const node = activeIndentNode(); + if (!node) return; + const cur = Number(editor.getAttributes(node).indent ?? 0); editor .chain() .focus() - .updateAttributes("paragraph", { indent: Math.max(0, cur - INDENT_STEP) }) + .updateAttributes(node, { indent: Math.max(0, cur - INDENT_STEP) }) .run(); };