diff --git a/apps/mobile/app/components/sheets/link-note/index.tsx b/apps/mobile/app/components/sheets/link-note/index.tsx index 618b729b4..3e980c7f9 100644 --- a/apps/mobile/app/components/sheets/link-note/index.tsx +++ b/apps/mobile/app/components/sheets/link-note/index.tsx @@ -219,7 +219,7 @@ export default function LinkNote(props: { @@ -311,6 +311,7 @@ export default function LinkNote(props: { style={{ marginTop: 10 }} + keyboardShouldPersistTaps="handled" windowSize={3} keyExtractor={(item) => item.id} data={nodes} @@ -324,6 +325,7 @@ export default function LinkNote(props: { onSelectNote={onSelectNote} /> )} + keyboardShouldPersistTaps="handled" style={{ marginTop: 10 }} diff --git a/apps/mobile/app/screens/editor/index.tsx b/apps/mobile/app/screens/editor/index.tsx index 704607e2a..159ac7afa 100755 --- a/apps/mobile/app/screens/editor/index.tsx +++ b/apps/mobile/app/screens/editor/index.tsx @@ -51,7 +51,11 @@ import { EditorProps, useEditorType } from "./tiptap/types"; import { useEditor } from "./tiptap/use-editor"; import { useEditorEvents } from "./tiptap/use-editor-events"; import { syncTabs, useTabStore } from "./tiptap/use-tab-store"; -import { editorController, editorState } from "./tiptap/utils"; +import { + editorController, + editorState, + openInternalLink +} from "./tiptap/utils"; const style: ViewStyle = { height: "100%", @@ -61,7 +65,10 @@ const style: ViewStyle = { backgroundColor: "transparent" }; const onShouldStartLoadWithRequest = (request: ShouldStartLoadRequest) => { - if (request.url.includes("https")) { + if (request.url.includes("nn://")) { + openInternalLink(request.url); + return false; + } else if (request.url.includes("https")) { if (Platform.OS === "ios" && !request.isTopFrame) return true; openLinkInBrowser(request.url); return false; diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx b/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx index 1266be16b..e18b2d3f7 100644 --- a/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx +++ b/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx @@ -19,7 +19,6 @@ along with this program. If not, see . /* eslint-disable no-case-declarations */ /* eslint-disable @typescript-eslint/no-var-requires */ -import { parseInternalLink } from "@notesnook/core"; import { ItemReference } from "@notesnook/core/dist/types"; import type { Attachment } from "@notesnook/editor/dist/extensions/attachment/index"; import { getDefaultPresets } from "@notesnook/editor/dist/toolbar/tool-definitions"; @@ -37,6 +36,7 @@ import { WebViewMessageEvent } from "react-native-webview"; import { DatabaseLogger, db } from "../../../common/database"; import downloadAttachment from "../../../common/filesystem/download-attachment"; import EditorTabs from "../../../components/sheets/editor-tabs"; +import { Issue } from "../../../components/sheets/github/issue"; import LinkNote from "../../../components/sheets/link-note"; import ManageTagsSheet from "../../../components/sheets/manage-tags"; import { RelationsList } from "../../../components/sheets/relations-list"; @@ -75,8 +75,7 @@ import { useDragState } from "../../settings/editor/state"; import { EventTypes } from "./editor-events"; import { EditorMessage, EditorProps, useEditorType } from "./types"; import { useTabStore } from "./use-tab-store"; -import { EditorEvents, editorState } from "./utils"; -import { Issue } from "../../../components/sheets/github/issue"; +import { EditorEvents, editorState, openInternalLink } from "./utils"; const publishNote = async () => { const user = useUserStore.getState().user; @@ -519,27 +518,7 @@ export const useEditorEvents = ( break; case EventTypes.link: if (editorMessage.value.startsWith("nn://")) { - const data = parseInternalLink(editorMessage.value); - if (!data?.id) break; - if ( - data.id === - useTabStore - .getState() - .getNoteIdForTab(useTabStore.getState().currentTab) - ) { - if (data.params?.blockId) { - setTimeout(() => { - if (!data.params?.blockId) return; - editor.commands.scrollIntoViewById(data.params.blockId); - }, 150); - } - return; - } - - eSendEvent(eOnLoadNote, { - item: await db.notes.note(data?.id), - blockId: data.params?.blockId - }); + openInternalLink(editorMessage.value); console.log( "Opening note from internal link:", editorMessage.value diff --git a/apps/mobile/app/screens/editor/tiptap/utils.ts b/apps/mobile/app/screens/editor/tiptap/utils.ts index 964ca8ab8..455b3d70a 100644 --- a/apps/mobile/app/screens/editor/tiptap/utils.ts +++ b/apps/mobile/app/screens/editor/tiptap/utils.ts @@ -22,10 +22,15 @@ import { TextInput } from "react-native"; import WebView from "react-native-webview"; import { MMKV } from "../../../common/database/mmkv"; import { + eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from "../../../services/event-manager"; import { AppState, EditorState, useEditorType } from "./types"; +import { useTabStore } from "./use-tab-store"; +import { parseInternalLink } from "@notesnook/core"; +import { eOnLoadNote } from "../../../utils/events"; +import { db } from "../../../common/database"; export const textInput = createRef(); export const editorController = createRef() as MutableRefObject; @@ -176,3 +181,27 @@ export function clearAppState() { appState = undefined; MMKV.removeItem("appState"); } + +export async function openInternalLink(url: string) { + const data = parseInternalLink(url); + if (!data?.id) return false; + if ( + data.id === + useTabStore.getState().getNoteIdForTab(useTabStore.getState().currentTab) + ) { + if (data.params?.blockId) { + setTimeout(() => { + if (!data.params?.blockId) return; + editorController.current.commands.scrollIntoViewById( + data.params.blockId + ); + }, 150); + } + return; + } + + eSendEvent(eOnLoadNote, { + item: await db.notes.note(data?.id), + blockId: data.params?.blockId + }); +}