diff --git a/web/src/lib/components/editor/Editor.svelte b/web/src/lib/components/editor/Editor.svelte index 941e570d..817aa18f 100644 --- a/web/src/lib/components/editor/Editor.svelte +++ b/web/src/lib/components/editor/Editor.svelte @@ -475,10 +475,47 @@ slashOpen = true; } + type ListItemTypeName = 'listItem' | 'taskItem'; + + function getActiveListItemType(): ListItemTypeName | null { + if (!editor) return null; + const selectionAnchor = editor.state.selection.$from; + for (let depth = selectionAnchor.depth; depth > 0; depth--) { + const typeName = selectionAnchor.node(depth).type.name; + if (typeName === 'listItem' || typeName === 'taskItem') return typeName; + } + return null; + } + + function canIndentListItem(type: ListItemTypeName | null): boolean { + if (!editor || !type) return false; + return editor.can().chain().focus().sinkListItem(type).run(); + } + + function canOutdentListItem(type: ListItemTypeName | null): boolean { + if (!editor || !type) return false; + return editor.can().chain().focus().liftListItem(type).run(); + } + + function indentCurrentListItem() { + const type = getActiveListItemType(); + if (!editor || !type) return; + editor.chain().focus().sinkListItem(type).run(); + } + + function outdentCurrentListItem() { + const type = getActiveListItemType(); + if (!editor || !type) return; + editor.chain().focus().liftListItem(type).run(); + } + {#if isMobile && keyboardVisible && editor} {@const _tick = editorTick} + {@const listItemType = getActiveListItemType()} + {@const canIndent = canIndentListItem(listItemType)} + {@const canOutdent = canOutdentListItem(listItemType)}