Editor: Auto-Fokus beim Wechsel in den Edit-Modus #140

Merged
fable-5 merged 1 commits from editor-autofocus into main 2026-07-19 11:56:38 +02:00
Showing only changes of commit 4ba4ca7ba9 - Show all commits

View File

@ -209,6 +209,22 @@ function PageEditor({
editor?.setEditable(canEdit); editor?.setEditable(canEdit);
}, [editor, 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 // Active plugins feed the section-style stylesheets (read + edit mode) and
// the toolbar's style picker (#75). Offline the query fails silently and // the toolbar's style picker (#75). Offline the query fails silently and
// sections render with neutral styling — content stays intact. // sections render with neutral styling — content stays intact.