This commit is contained in:
Simon Cambier
2022-10-27 19:01:59 +02:00
parent cb8de1ad8d
commit 22ff4eec03
3 changed files with 18 additions and 17 deletions

View File

@@ -1,7 +1,3 @@
<script context="module" lang="ts">
let lastSearch = ''
</script>
<script lang="ts">
import InputSearch from './InputSearch.svelte'
import {
@@ -26,17 +22,17 @@
export let modal: OmnisearchInFileModal
export let parent: OmnisearchVaultModal | null = null
export let singleFilePath = ''
export let searchQuery: string
export let previousQuery: string | undefined
let searchQuery: string
let groupedOffsets: number[] = []
let selectedIndex = 0
let note: ResultNote | undefined
let query: Query
$: searchQuery = previousQuery ?? ''
onMount(() => {
if (lastSearch && !searchQuery) {
searchQuery = lastSearch
}
eventBus.enable('infile')
eventBus.on('infile', 'enter', openSelection)
@@ -52,8 +48,12 @@
$: (async () => {
if (searchQuery) {
query = new Query(searchQuery)
note = (await SearchEngine.getEngine().getSuggestions(query, { singleFilePath }))[0] ?? null
lastSearch = searchQuery
note =
(
await SearchEngine.getEngine().getSuggestions(query, {
singleFilePath,
})
)[0] ?? null
}
selectedIndex = 0
await scrollIntoView()
@@ -138,7 +138,7 @@
}
function switchToVaultModal(): void {
new OmnisearchVaultModal(app).open()
new OmnisearchVaultModal(app, previousQuery).open()
modal.close()
}
</script>
@@ -146,7 +146,7 @@
<InputSearch
on:input="{e => (searchQuery = e.detail)}"
placeholder="Omnisearch - File"
initialValue="{searchQuery}" />
initialValue="{previousQuery}" />
<ModalContainer>
{#if groupedOffsets.length && note}

View File

@@ -18,15 +18,15 @@
import { cacheManager } from '../cache-manager'
export let modal: OmnisearchVaultModal
export let previousQuery: string | undefined
let selectedIndex = 0
let historySearchIndex = 0
let searchQuery: string | undefined
let previousQuery: string | undefined
let resultNotes: ResultNote[] = []
let query: Query
$: selectedNote = resultNotes[selectedIndex]
$: searchQuery = previousQuery
$: searchQuery = searchQuery ?? previousQuery
$: if (searchQuery) {
updateResults()
} else {
@@ -163,7 +163,7 @@
function switchToInFileModal(): void {
// Do nothing if the selectedNote is a PDF,
// or if there is 0 match (e.g indexing in progress)
if (selectedNote?.path.endsWith('.pdf') || !selectedNote.matches.length) {
if (selectedNote?.path.endsWith('.pdf') || !selectedNote?.matches.length) {
return
}

View File

@@ -117,12 +117,13 @@ abstract class OmnisearchModal extends Modal {
}
export class OmnisearchVaultModal extends OmnisearchModal {
constructor(app: App) {
constructor(app: App, query?: string) {
super(app)
const cmp = new ModalVault({
target: this.modalEl,
props: {
modal: this,
previousQuery: query
},
})
@@ -149,7 +150,7 @@ export class OmnisearchInFileModal extends OmnisearchModal {
modal: this,
singleFilePath: file.path,
parent: parent,
searchQuery,
previousQuery: searchQuery,
},
})