Files
tolaria/src/utils/autoSave.ts
lucaronin 3e05a9425a test: add Playwright smoke test for exact-match search ranking
Verifies that searching "Writing" in Quick Open shows the exact title
match first, followed by prefix matches. Also adds Refactoring test
entries to mock data and demo vault.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:53:00 +01:00

29 lines
982 B
TypeScript

import { persistContent } from '../hooks/useSaveNote'
export interface FlushDeps {
savePendingForPath: (path: string) => Promise<boolean>
getTabContent: (path: string) => string | undefined
isUnsaved: (path: string) => boolean
onSaved?: (path: string, content: string) => void
}
/**
* Flush unsaved editor content to disk for a given path before a destructive action.
*
* 1. Try flushing the pending content ref (handles the currently-editing note).
* 2. If nothing was pending, check if the tab has unsaved content (either newly
* created or modified in the editor) and persist it directly.
*/
export async function flushEditorContent(path: string, deps: FlushDeps): Promise<void> {
const flushed = await deps.savePendingForPath(path)
if (flushed) return
const tabContent = deps.getTabContent(path)
if (tabContent === undefined) return
if (deps.isUnsaved(path)) {
await persistContent(path, tabContent)
deps.onSaved?.(path, tabContent)
}
}