diff --git a/src/CmpInput.svelte b/src/CmpInput.svelte index 85b6d98..aa759a4 100644 --- a/src/CmpInput.svelte +++ b/src/CmpInput.svelte @@ -1,7 +1,8 @@ - +{inputValue} - {debouncedValue} import CmpInput from "./CmpInput.svelte" import CmpResultInFile from "./CmpResultInFile.svelte" -import { excerptAfter, type SearchMatch } from "./globals" -import { modal, plugin, resultNotes } from "./stores" +import { excerptAfter, type ResultNote, type SearchMatch } from "./globals" +import { modal, plugin } from "./stores" import { loopIndex } from "./utils" import { tick } from "svelte" import { MarkdownView } from "obsidian" -import CmpModalVault from "./CmpModalVault.svelte" -import { OmnisearchModal } from "./modal" +import { getSuggestions } from "./search" export let canGoBack = false - -let matches: SearchMatch[] = [] +export let singleFilePath = "" let groupedOffsets: number[] = [] let selectedIndex = 0 +let searchQuery: string +let note: ResultNote | null = null + +$: { + note = getSuggestions(searchQuery, { singleFilePath })[0] ?? null + selectedIndex = 0 + scrollIntoView() +} -$: note = $resultNotes[0] $: { if (note) { - matches = note.matches - const groups = getGroups() + const groups = getGroups(note.matches) groupedOffsets = groups.map((group) => Math.round((group.first()!.offset + group.last()!.offset) / 2) ) @@ -27,20 +31,11 @@ $: { // console.log(groupedOffsets) } } -$: { - if (canGoBack) { - $modal.onClose = () => { - if (canGoBack) { - new OmnisearchModal($plugin).open() - } - } - } -} /** * Group together close */ -function getGroups(): SearchMatch[][] { +function getGroups(matches: SearchMatch[]): SearchMatch[][] { const groups: SearchMatch[][] = [] let lastOffset = -1 while (true) { @@ -99,6 +94,7 @@ function openSelection(): void { moveIndex(-1)} on:arrow-down={() => moveIndex(1)} diff --git a/src/CmpModalVault.svelte b/src/CmpModalVault.svelte index 2473091..7188c87 100644 --- a/src/CmpModalVault.svelte +++ b/src/CmpModalVault.svelte @@ -1,26 +1,39 @@