Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix: retain focus after creating a memo

tianma-ifd4dc353b9c16
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsx
index 5eb78235..ac2d74cc 100644
--- a/apps/web/src/components/EditorPane.tsx
+++ b/apps/web/src/components/EditorPane.tsx
@@ -1287,13 +1287,27 @@ const RichEditorPane = ({
}
const currentEditor = editorRef.current;
- if (!isMobileViewport) {
- if (isEditorReady(currentEditor) && hydratedMemoIdRef.current === memo.id) {
- currentEditor.commands.focus("end");
- onMobileDefaultEditConsumed();
- return;
+ if (!isMobileViewport) {
+ if (isEditorReady(currentEditor) && hydratedMemoIdRef.current === memo.id) {
+ currentEditor.commands.focus("end");
+ onMobileDefaultEditConsumed();
+ // Consuming the create request updates the parent and can
+ // briefly blur the editor during that rerender. Restore the
+ // caret after the update has committed so a new note is
+ // immediately ready for typing.
+ window.setTimeout(() => {
+ if (cancelled || memoRef.current?.id !== memo.id) {
+ return;
+ }
+
+ const activeEditor = editorRef.current;
+ if (isEditorReady(activeEditor)) {
+ activeEditor.commands.focus("end");
+ }
+ }, 0);
+ return;
+ }
}
- }
// The editor is mounted before its memo hydration/edit session
// finishes. Keep retrying across that async boundary so a newly