diff --git a/apps/mobile/app/screens/editor/index.tsx b/apps/mobile/app/screens/editor/index.tsx index db32689f1..766a3305e 100755 --- a/apps/mobile/app/screens/editor/index.tsx +++ b/apps/mobile/app/screens/editor/index.tsx @@ -167,7 +167,7 @@ const Editor = React.memo( globalThis.noToolbar=${noToolbar}; globalThis.noHeader=${noHeader}; `} - injectedJavaScript={`globalThis.sessionId="${editor.sessionId}";`} + useSharedProcessPool={false} javaScriptEnabled={true} focusable={true} onContentProcessDidTerminate={onError} diff --git a/apps/mobile/app/screens/editor/tiptap/commands.ts b/apps/mobile/app/screens/editor/tiptap/commands.ts index c22df0cfe..5eb97def9 100644 --- a/apps/mobile/app/screens/editor/tiptap/commands.ts +++ b/apps/mobile/app/screens/editor/tiptap/commands.ts @@ -113,7 +113,7 @@ typeof globalThis.statusBar !== "undefined" && statusBar.current.set({date:"",sa }; setSessionId = async (id: string | null) => - await this.doAsync(`globalThis.sessionId = "${id}"`); + await this.doAsync(`globalThis.sessionId = "${id}";`); setStatus = async (date: string | undefined, saved: string) => await this.doAsync( diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor-events.ts b/apps/mobile/app/screens/editor/tiptap/use-editor-events.ts index 751b2da6d..8f8bfde34 100644 --- a/apps/mobile/app/screens/editor/tiptap/use-editor-events.ts +++ b/apps/mobile/app/screens/editor/tiptap/use-editor-events.ts @@ -205,7 +205,6 @@ export const useEditorEvents = ( fullscreen, isPremium, readonly, - editor.sessionId, editor.loading, deviceMode, tools, @@ -229,6 +228,8 @@ export const useEditorEvents = ( logger.info("editor handled back event", editorHandledBack); return; } + editorState().currentlyEditing = false; + editor.reset(); setTimeout(async () => { if (deviceMode !== "mobile" && fullscreen) { if (fullscreen) { @@ -241,14 +242,10 @@ export const useEditorEvents = ( editorState().movedAway = true; tabBarRef.current?.goToPage(0); } - setImmediate(() => { - useEditorStore.getState().setCurrentlyEditingNote(null); - setTimeout(() => { - Navigation.queueRoutesForUpdate(); - }, 500); - }); - editorState().currentlyEditing = false; - editor.reset(); + + setTimeout(() => { + Navigation.queueRoutesForUpdate(); + }, 500); }, 1); }, [editor, deviceMode, fullscreen]); @@ -344,8 +341,12 @@ export const useEditorEvents = ( }); } + if (editorMessage.type === EventTypes.back) { + return onBackPress(); + } + if ( - editorMessage.sessionId !== editor.sessionId && + editorMessage.sessionId !== editor.sessionId.current && editorMessage.type !== EditorEvents.status ) { return; @@ -431,9 +432,6 @@ export const useEditorEvents = ( editorState().isFullscreen = true; eSendEvent(eOpenFullscreenEditor); break; - case EventTypes.back: - onBackPress(); - break; case EventTypes.link: openLinkInBrowser(editorMessage.value as string); break; diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor.ts b/apps/mobile/app/screens/editor/tiptap/use-editor.ts index 17658a110..ea0085b74 100644 --- a/apps/mobile/app/screens/editor/tiptap/use-editor.ts +++ b/apps/mobile/app/screens/editor/tiptap/use-editor.ts @@ -63,8 +63,7 @@ export const useEditor = ( const theme = useThemeEngineStore((state) => state.theme); const [loading, setLoading] = useState(false); - const [sessionId, setSessionId] = useState(makeSessionId()); - const sessionIdRef = useRef(sessionId); + const sessionIdRef = useRef(makeSessionId()); const editorRef = useRef(null); const currentNote = useRef(); const currentContent = useRef(); @@ -99,10 +98,6 @@ export const useEditor = ( postMessage(EditorEvents.theme, theme); }, [theme, postMessage]); - useEffect(() => { - sessionIdRef.current = sessionId; - }, [sessionId]); - useEffect(() => { commands.setTags(currentNote.current); }, [commands, tags]); @@ -142,6 +137,7 @@ export const useEditor = ( clearTimeout(timers.current["loading-images"]); sessionHistoryId.current = undefined; saveCount.current = 0; + loadingState.current = undefined; lock.current = false; useEditorStore.getState().setReadonly(false); resetContent && postMessage(EditorEvents.title, ""); @@ -151,8 +147,8 @@ export const useEditor = ( if (resetState) { const newSessionId = makeSessionId(); + sessionIdRef.current = newSessionId; await commands.setSessionId(newSessionId); - setSessionId(newSessionId); isDefaultEditor && useEditorStore.getState().setCurrentlyEditingNote(null); @@ -363,7 +359,6 @@ export const useEditor = ( if (item && item.type === "new") { currentNote.current && (await reset()); const nextSessionId = makeSessionId(item as NoteType); - setSessionId(nextSessionId); sessionIdRef.current = nextSessionId; sessionHistoryId.current = Date.now(); await commands.setSessionId(nextSessionId); @@ -405,12 +400,10 @@ export const useEditor = ( } lastContentChangeTime.current = item.dateEdited; const nextSessionId = makeSessionId(item as NoteType); + sessionIdRef.current = nextSessionId; lockedSessionId.current = nextSessionId; sessionHistoryId.current = Date.now(); - setSessionId(nextSessionId); - - commands.setSessionId(nextSessionId); - sessionIdRef.current = nextSessionId; + await commands.setSessionId(nextSessionId); currentNote.current = item as NoteType; await commands.setStatus(getFormattedDate(item.dateEdited), "Saved"); await postMessage(EditorEvents.title, item.title); @@ -638,7 +631,7 @@ export const useEditor = ( useEffect(() => { state.current.saveCount = 0; - }, [sessionId, loading]); + }, [loading]); const onReady = useCallback(async () => { if (!(await isEditorLoaded(editorRef, sessionIdRef.current))) { @@ -690,8 +683,7 @@ export const useEditor = ( loading, setLoading, state, - sessionId, - setSessionId, + sessionId: sessionIdRef, note: currentNote, onReady, saveContent,