#25 - fixed matches algorithm

This commit is contained in:
Simon Cambier
2022-04-30 20:18:26 +02:00
parent f2938cde88
commit ca04ed80c9
6 changed files with 42 additions and 34 deletions

View File

@@ -9,14 +9,15 @@ import {
excerptAfter,
type ResultNote,
type SearchMatch,
} from "../globals"
import { loopIndex } from "../utils"
} from "src/globals"
import { loopIndex } from "src/utils"
import { onDestroy, onMount, tick } from "svelte"
import { MarkdownView } from "obsidian"
import { getSuggestions } from "../search"
import { getSuggestions } from "src/search"
import ModalContainer from "./ModalContainer.svelte"
import type { OmnisearchInFileModal, OmnisearchVaultModal } from "src/modals"
import ResultItemInFile from "./ResultItemInFile.svelte"
import { Query } from "src/query"
export let modal: OmnisearchInFileModal
export let parent: OmnisearchVaultModal | null = null
@@ -26,6 +27,7 @@ export let searchQuery: string
let groupedOffsets: number[] = []
let selectedIndex = 0
let note: ResultNote | null = null
let query: Query
onMount(() => {
if (lastSearch && !searchQuery) {
@@ -44,7 +46,8 @@ onDestroy(() => {
$: (async () => {
if (searchQuery) {
note = (await getSuggestions(searchQuery, { singleFilePath }))[0] ?? null
query = new Query(searchQuery)
note = (await getSuggestions(query, { singleFilePath }))[0] ?? null
lastSearch = searchQuery
}
selectedIndex = 0

View File

@@ -7,17 +7,19 @@ import { TFile } from "obsidian"
import { onMount, tick } from "svelte"
import InputSearch from "./InputSearch.svelte"
import ModalContainer from "./ModalContainer.svelte"
import { eventBus, type ResultNote } from "../globals"
import { createNote, openNote } from "../notes"
import { getSuggestions } from "../search"
import { loopIndex } from "../utils"
import { eventBus, type ResultNote } from "src/globals"
import { createNote, openNote } from "src/notes"
import { getSuggestions } from "src/search"
import { loopIndex } from "src/utils"
import { OmnisearchInFileModal, type OmnisearchVaultModal } from "src/modals"
import ResultItemVault from "./ResultItemVault.svelte"
import { Query } from "src/query"
export let modal: OmnisearchVaultModal
let selectedIndex = 0
let searchQuery: string
let resultNotes: ResultNote[] = []
let query: Query
$: selectedNote = resultNotes[selectedIndex]
$: if (searchQuery) {
@@ -37,7 +39,8 @@ onMount(() => {
})
async function updateResults() {
resultNotes = await getSuggestions(searchQuery)
query = new Query(searchQuery)
resultNotes = await getSuggestions(query)
lastSearch = searchQuery
selectedIndex = 0
scrollIntoView()

View File

@@ -1,4 +1,5 @@
<script lang="ts">
import type { Query } from "src/query";
import type { ResultNote } from "../globals"
import { getMatches } from "../search"
import { highlighter, makeExcerpt, stringsToRegex } from "../utils"