From 8ee564e952f7eac07dc526c711e117cd3b35e9e7 Mon Sep 17 00:00:00 2001 From: Aslam H Date: Tue, 22 Oct 2024 21:36:40 +0700 Subject: [PATCH] chore: editor focus between title and content --- .../_pages/_protected/pages/$pageId/index.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/web/app/routes/_layout/_pages/_protected/pages/$pageId/index.tsx b/web/app/routes/_layout/_pages/_protected/pages/$pageId/index.tsx index bb2d45fa..f097df78 100644 --- a/web/app/routes/_layout/_pages/_protected/pages/$pageId/index.tsx +++ b/web/app/routes/_layout/_pages/_protected/pages/$pageId/index.tsx @@ -224,8 +224,14 @@ const DetailPageForm = React.memo(({ page }: { page: PersonalPage }) => { handleKeyDown: handleTitleKeyDown, }, onCreate: ({ editor }) => { - if (page.title) editor.commands.setContent(`

${page.title}

`) + if (page.title) { + editor.commands.setContent(`

${page.title}

`) + } titleEditorRef.current = editor + + if (!page.title) { + editor.commands.focus() + } }, onBlur: ({ editor }) => handleUpdateTitle(editor), onUpdate: ({ editor }) => handleUpdateTitle(editor), @@ -237,8 +243,12 @@ const DetailPageForm = React.memo(({ page }: { page: PersonalPage }) => { editor.commands.setContent(page.content as Content) } contentEditorRef.current = editor + + if (page.title) { + editor.commands.focus() + } }, - [page.content], + [page.content, page.title], ) return (