#70 - Added a "toggle context" setting + settings is now a Svelte store

A bit more verbose, but allows for proper reactivity
This commit is contained in:
Simon Cambier
2022-09-10 21:23:12 +02:00
parent c74ed2892c
commit 66e1d2d334
4 changed files with 97 additions and 31 deletions

View File

@@ -10,7 +10,8 @@
import { OmnisearchInFileModal, type OmnisearchVaultModal } from 'src/modals'
import ResultItemVault from './ResultItemVault.svelte'
import { Query } from 'src/query'
import { saveSearchHistory, searchHistory } from 'src/search-history'
import { saveSearchHistory, searchHistory } from 'src/search-history'
import { SearchContextType, settings } from 'src/settings'
export let modal: OmnisearchVaultModal
let selectedIndex = 0
@@ -28,6 +29,7 @@ import { saveSearchHistory, searchHistory } from 'src/search-history'
}
onMount(async () => {
console.log('mount')
await reindexNotes()
searchQuery = searchHistory[historySearchIndex]
eventBus.enable('vault')
@@ -38,8 +40,9 @@ import { saveSearchHistory, searchHistory } from 'src/search-history'
eventBus.on('vault', 'tab', switchToInFileModal)
eventBus.on('vault', 'arrow-up', () => moveIndex(-1))
eventBus.on('vault', 'arrow-down', () => moveIndex(1))
eventBus.on('vault', 'prev-search-history', () => prevSearchHistory())
eventBus.on('vault', 'next-search-history', () => nextSearchHistory())
eventBus.on('vault', 'prev-search-history', prevSearchHistory)
eventBus.on('vault', 'next-search-history', nextSearchHistory)
eventBus.on('vault', 'toggle-context', toggleContext)
})
onDestroy(() => {
@@ -59,6 +62,16 @@ import { saveSearchHistory, searchHistory } from 'src/search-history'
searchQuery = searchHistory[historySearchIndex]
}
function toggleContext() {
settings.update(s => {
s.showContext =
s.showContext === SearchContextType.None
? SearchContextType.Simple
: SearchContextType.None
return s
})
}
async function updateResults() {
query = new Query(searchQuery)
resultNotes = (await getSuggestions(query)).sort(
@@ -212,4 +225,10 @@ import { saveSearchHistory, searchHistory } from 'src/search-history'
<div class="prompt-instruction">
<span class="prompt-instruction-command">esc</span><span>to close</span>
</div>
<br />
<div class="prompt-instruction">
<span class="prompt-instruction-command">ctrl+h</span><span
>to toggle context</span>
</div>
</div>