From f445a963f928f7ff02c73f00468432f1cceb6571 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Fri, 25 Jul 2025 12:44:55 +0500 Subject: [PATCH] mobile: improve ux when clicking empty area in editor --- .../editor-mobile/src/components/editor.tsx | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/editor-mobile/src/components/editor.tsx b/packages/editor-mobile/src/components/editor.tsx index e7f77bb2f..bcaca732e 100644 --- a/packages/editor-mobile/src/components/editor.tsx +++ b/packages/editor-mobile/src/components/editor.tsx @@ -25,6 +25,7 @@ import { toBlobURL, usePermissionHandler } from "@notesnook/editor"; +import { strings } from "@notesnook/intl"; import { useThemeColors } from "@notesnook/theme"; import FingerprintIcon from "mdi-react/FingerprintIcon"; import { @@ -47,7 +48,6 @@ import StatusBar from "./statusbar"; import Tags from "./tags"; import TiptapEditorWrapper from "./tiptap"; import Title from "./title"; -import { strings } from "@notesnook/intl"; globalThis.toBlobURL = toBlobURL as typeof globalThis.toBlobURL; @@ -380,11 +380,14 @@ const Tiptap = ({ const editor = editors[tab.id]; - const firstChild = editor?.state.doc.firstChild; - const isParagraph = firstChild?.type.name === "paragraph"; - const isFirstChildEmpty = - !firstChild?.textContent || firstChild?.textContent?.length === 0; - if (isParagraph && isFirstChildEmpty) { + const firstChildNodeType = editor?.state.doc.firstChild?.type.name; + const isSimpleNode = + firstChildNodeType !== "image" && + firstChildNodeType !== "embed" && + firstChildNodeType !== "attachment" && + firstChildNodeType !== "mathBlock" && + firstChildNodeType !== "horizontalRule"; + if (isSimpleNode) { editor?.commands.focus("end"); return; } @@ -405,11 +408,14 @@ const Tiptap = ({ const editor = editors[tab.id]; const docSize = editor?.state.doc.content.size; if (!docSize) return; - const lastChild = editor?.state.doc.lastChild; - const isParagraph = lastChild?.type.name === "paragraph"; - const isLastChildEmpty = - !lastChild?.textContent || lastChild?.textContent?.length === 0; - if (isParagraph && isLastChildEmpty) { + const lastChildNodeType = editor?.state.doc.lastChild?.type.name; + const isSimpleNode = + lastChildNodeType !== "image" && + lastChildNodeType !== "embed" && + lastChildNodeType !== "attachment" && + lastChildNodeType !== "mathBlock" && + lastChildNodeType !== "horizontalRule"; + if (isSimpleNode) { editor?.commands.focus("end"); return; } @@ -544,6 +550,7 @@ const Tiptap = ({