diff --git a/apps/web/src/pages/PageEditorPage.tsx b/apps/web/src/pages/PageEditorPage.tsx index 6747e93..68b2afb 100644 --- a/apps/web/src/pages/PageEditorPage.tsx +++ b/apps/web/src/pages/PageEditorPage.tsx @@ -209,6 +209,22 @@ function PageEditor({ editor?.setEditable(canEdit); }, [editor, canEdit]); + // Entering edit mode drops the caret straight into the content, so writing + // starts without an extra — and on empty pages pixel-precise — click. Skip + // when a text control (e.g. the title input) already holds focus: switching + // modes must not yank the caret out of it. + useEffect(() => { + if (!editor || !canEdit) return; + const active = document.activeElement; + if ( + active instanceof HTMLElement && + (active.tagName === 'INPUT' || active.tagName === 'TEXTAREA' || active.isContentEditable) + ) { + return; + } + editor.commands.focus(); + }, [editor, canEdit]); + // Active plugins feed the section-style stylesheets (read + edit mode) and // the toolbar's style picker (#75). Offline the query fails silently and // sections render with neutral styling — content stays intact.