#70 - Correctly toggling and saving settings.showContext

This commit is contained in:
Simon Cambier
2022-09-20 12:53:37 +02:00
parent 31aab49c54
commit 35110f488d
4 changed files with 35 additions and 27 deletions

View File

@@ -11,7 +11,7 @@
import ResultItemVault from './ResultItemVault.svelte'
import { Query } from 'src/query'
import { saveSearchHistory, searchHistory } from 'src/search-history'
import { SearchContextType, settings } from 'src/settings'
import { settings } from 'src/settings'
export let modal: OmnisearchVaultModal
let selectedIndex = 0
@@ -29,7 +29,6 @@
}
onMount(async () => {
console.log('mount')
await reindexNotes()
searchQuery = searchHistory[historySearchIndex]
eventBus.enable('vault')
@@ -42,7 +41,6 @@
eventBus.on('vault', 'arrow-down', () => moveIndex(1))
eventBus.on('vault', 'prev-search-history', prevSearchHistory)
eventBus.on('vault', 'next-search-history', nextSearchHistory)
eventBus.on('vault', 'toggle-context', toggleContext)
})
onDestroy(() => {
@@ -62,16 +60,6 @@
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(
@@ -108,7 +96,6 @@
async function createNoteAndCloseModal(opt?: {
newLeaf: boolean
}): Promise<void> {
console.log(opt)
try {
await createNote(searchQuery, opt?.newLeaf)
} catch (e) {
@@ -203,8 +190,8 @@
<span class="prompt-instruction-command">↑↓</span><span>to navigate</span>
</div>
<div class="prompt-instruction">
<span class="prompt-instruction-command">alt ↑↓</span><span
>to cycle history</span>
<span class="prompt-instruction-command">alt ↑↓</span>
<span>to cycle history</span>
</div>
<div class="prompt-instruction">
<span class="prompt-instruction-command"></span><span>to open</span>
@@ -236,8 +223,8 @@
<span>to insert a link</span>
</div>
<div class="prompt-instruction">
<span class="prompt-instruction-command">ctrl+h</span><span
>to toggle context</span>
<span class="prompt-instruction-command">ctrl+h</span>
<span>to toggle context</span>
</div>
<div class="prompt-instruction">
<span class="prompt-instruction-command">esc</span><span>to close</span>

View File

@@ -1,6 +1,6 @@
<script lang="ts">
import { getNoteFromCache } from 'src/notes'
import { SearchContextType, settings } from 'src/settings'
import { settings } from 'src/settings'
import type { ResultNote } from '../globals'
import { getMatches } from '../search'
import { highlighter, makeExcerpt, stringsToRegex } from '../utils'
@@ -29,7 +29,7 @@
{/if}
</div>
{#if $settings.showContext !== SearchContextType.None}
{#if $settings.showContext}
<div class="omnisearch-result__body">
{@html cleanedContent.replace(reg, highlighter)}
</div>