Re-trigger the search when the query or singleFileSearch change
This commit is contained in:
@@ -30,6 +30,6 @@ function cleanContent(content: string): string {
|
||||
|
||||
<div class="suggestion-item omnisearch-result">
|
||||
<div class="omnisearch-result__body">
|
||||
{cleanContent(note?.content ?? '')}
|
||||
{@html cleanContent(note?.content ?? '')}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,8 +10,8 @@ const dispatch = createEventDispatcher()
|
||||
onMount(async () => {
|
||||
await tick()
|
||||
elInput.focus()
|
||||
elInput.select()
|
||||
elInput.value = $searchQuery
|
||||
elInput.select()
|
||||
})
|
||||
|
||||
const debouncedOnInput = debounce(() => $searchQuery = inputValue, 100)
|
||||
|
||||
@@ -1,18 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { onMount, tick } from "svelte"
|
||||
import CmpInput from "./CmpInput.svelte"
|
||||
import CmpNoteInternalResult from "./CmpInfileResult.svelte"
|
||||
import CmpNoteResult from "./CmpNoteResult.svelte"
|
||||
import type { ResultNote } from "./globals"
|
||||
import { openNote } from "./notes"
|
||||
import { getSuggestions } from "./search"
|
||||
import {
|
||||
inFileSearch,
|
||||
modal,
|
||||
plugin,
|
||||
resultNotes,
|
||||
searchQuery,
|
||||
selectedNote,
|
||||
} from "./stores"
|
||||
|
||||
$: firstResult = $resultNotes[0]
|
||||
|
||||
@@ -3,7 +3,7 @@ import MiniSearch, { type SearchResult } from 'minisearch'
|
||||
import type { IndexedNote, ResultNote, SearchMatch } from './globals'
|
||||
import {
|
||||
indexedNotes,
|
||||
inFileSearch,
|
||||
inFileSearch as singleFileSearch,
|
||||
plugin,
|
||||
resultNotes,
|
||||
searchQuery,
|
||||
@@ -75,15 +75,20 @@ function search(query: string): SearchResult[] {
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to the searchQuery store,
|
||||
* and automatically triggers a search when the query changes
|
||||
* Automatically re-trigger the search when the query or the
|
||||
* inFileSearch changes
|
||||
*/
|
||||
function subscribeToQuery(): void {
|
||||
searchQuery.subscribe(async q => {
|
||||
singleFileSearch.subscribe(async file => {
|
||||
triggerQuery(get(searchQuery))
|
||||
})
|
||||
searchQuery.subscribe(triggerQuery)
|
||||
|
||||
async function triggerQuery(q: string): Promise<void> {
|
||||
// If we're in "single file" mode, the search results array
|
||||
// will contain a single result, related to this file
|
||||
const results = get(inFileSearch)
|
||||
? getSuggestions(q, { singleFile: get(inFileSearch) })
|
||||
const results = get(singleFileSearch)
|
||||
? getSuggestions(q, { singleFile: get(singleFileSearch) })
|
||||
: getSuggestions(q)
|
||||
console.log(results)
|
||||
|
||||
@@ -96,7 +101,7 @@ function subscribeToQuery(): void {
|
||||
await tick()
|
||||
selectedNote.set(firstResult)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user