Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
a14b1772ca
commit
1377af9576
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user