#90 - search history ok

This commit is contained in:
Simon Cambier
2022-09-10 15:30:05 +02:00
parent 417cc69483
commit 65ebe02f8a
5 changed files with 53 additions and 19 deletions

28
src/search-history.ts Normal file
View File

@@ -0,0 +1,28 @@
import { searchIndexFilePath } from './globals'
export let searchHistory: string[] = []
export async function loadSearchHistory(): Promise<void> {
if (await app.vault.adapter.exists(searchIndexFilePath)) {
try {
searchHistory = JSON.parse(
await app.vault.adapter.read(searchIndexFilePath)
)
// Keep the last 100 searches
searchHistory = searchHistory.slice(0, 100)
} catch (e) {
console.trace('Could not load search history from the file')
console.error(e)
searchHistory = []
}
} else {
searchHistory = []
}
}
export async function saveSearchHistory(): Promise<void> {
await app.vault.adapter.write(
searchIndexFilePath,
JSON.stringify(searchHistory)
)
}