Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/features/sidebar/ui/SidebarSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export function SidebarSearch({
variant="ghost"
size="icon"
className="h-8 w-8 shrink-0"
onClick={onNewNote}
onClick={(e) => {
e.currentTarget.blur()
onNewNote()
}}
>
<Plus className="h-4 w-4" />
</Button>
Expand Down
25 changes: 20 additions & 5 deletions src/shared/hooks/useCursorMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ export function useCursorMemory({ editorRef, noteId }: UseCursorMemoryOptions) {
})
}, [editorStore])

/** Persists the in-memory position map to the store (fire-and-forget). */
/**
* Persists the in-memory position map to the tauri-plugin-store.
* Errors are logged but not propagated (fire-and-forget).
*/
const persistPositions = useCallback(() => {
editorStore
.set('cursorPositions', { ...positionsRef.current })
Expand All @@ -75,7 +78,12 @@ export function useCursorMemory({ editorRef, noteId }: UseCursorMemoryOptions) {
})
}, [editorStore])

/** Persists the currently focused block ID for the given note. */
/**
* Reads the currently focused block ID from the editor and stores it
* under the given note ID. Triggers an async persist to the store.
*
* @param targetNoteId - The note ID to associate the cursor position with.
*/
const saveCursorPosition = useCallback(
(targetNoteId: string) => {
const editor = editorRef.current?.editor
Expand All @@ -90,9 +98,10 @@ export function useCursorMemory({ editorRef, noteId }: UseCursorMemoryOptions) {
[editorRef, persistPositions]
)

/** Focuses the editor on the next animation frame. */
/** Focuses the editor after layout and paint are complete. */
const focusEditor = useCallback(
(editor: BlockNoteEditor) => requestAnimationFrame(() => editor.focus()),
(editor: BlockNoteEditor) =>
requestAnimationFrame(() => requestAnimationFrame(() => editor.focus())),
[]
)

Expand All @@ -115,7 +124,13 @@ export function useCursorMemory({ editorRef, noteId }: UseCursorMemoryOptions) {
[focusEditor]
)

/** Restores the cursor to the saved block for the current note. */
/**
* Restores the cursor to the previously saved block for the current note.
* Falls back to the first block when the saved block no longer exists.
* On the first invocation (app startup), waits for the splash screen to
* be removed before focusing; on subsequent invocations, focuses after
* a single frame delay.
*/
const restoreCursorPosition = useCallback(() => {
const editor = editorRef.current?.editor
if (!editor) return
Expand Down
Loading