Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ export default function Toolbar({
? "Heading: H2 → H3"
: editor?.isActive("heading", { level: 3 })
? "Heading: H3 → Normal"
: "Heading: Normal → H1"
: editor?.isActive("bulletList") || editor?.isActive("orderedList") || editor?.isActive("taskList")
? "Heading: List → H1"
: "Heading: Normal → H1"
}
icon={<Heading size={ICON_SIZE} strokeWidth={1.9} />}
/>
Expand Down
16 changes: 16 additions & 0 deletions src/features/editor/editorCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,22 @@ export function setCodeBlockLanguage(editor: Editor, language: string): void {
}

export function cycleHeading(editor: Editor): void {
// If the cursor is inside a list item, first remove the list formatting,
// then convert the lifted paragraph to H1.
if (editor.isActive("bulletList")) {
editor.chain().focus().toggleBulletList().setHeading({ level: 1 }).run();
return;
}
if (editor.isActive("orderedList")) {
editor.chain().focus().toggleOrderedList().setHeading({ level: 1 }).run();
return;
}
if (editor.isActive("taskList")) {
// taskList has no built-in toggle command, so we use liftListItem directly.
editor.chain().focus().liftListItem("taskItem").setHeading({ level: 1 }).run();
return;
}

if (editor.isActive("heading", { level: 1 })) {
editor.chain().focus().setHeading({ level: 2 }).run();
} else if (editor.isActive("heading", { level: 2 })) {
Expand Down