From 85a1b5b19ed9615150cbd98e214cae6b9ed5caa6 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Mon, 20 Mar 2023 16:29:58 +0500 Subject: [PATCH] editor: fix focus last node on tap bottom area on mobile --- packages/editor-mobile/src/components/editor.tsx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/editor-mobile/src/components/editor.tsx b/packages/editor-mobile/src/components/editor.tsx index fd990fdd5..ac450d20e 100644 --- a/packages/editor-mobile/src/components/editor.tsx +++ b/packages/editor-mobile/src/components/editor.tsx @@ -155,7 +155,7 @@ const Tiptap = ({ const isFirstChildEmpty = !firstChild?.textContent || firstChild?.textContent?.length === 0; if (isParagraph && isFirstChildEmpty) { - globalThis.editor?.commands.focus(); + globalThis.editor?.commands.focus("end"); return; } globalThis.editor @@ -163,10 +163,8 @@ const Tiptap = ({ .insertContentAt(0, "

", { updateSelection: true }) + .focus("end") .run(); - setTimeout(() => { - globalThis.editor?.commands.focus(); - }, 1); } }, [] @@ -180,7 +178,7 @@ const Tiptap = ({ const isLastChildEmpty = !lastChild?.textContent || lastChild?.textContent?.length === 0; if (isParagraph && isLastChildEmpty) { - globalThis.editor?.commands.focus(); + globalThis.editor?.commands.focus("end"); return; } globalThis.editor @@ -188,10 +186,8 @@ const Tiptap = ({ .insertContentAt(docSize - 1, "

", { updateSelection: true }) + .focus("end") .run(); - setTimeout(() => { - globalThis.editor?.commands.focus(); - }, 1); }, []); return (