Fixed #117
This commit is contained in:
@@ -1,7 +1,3 @@
|
|||||||
<script context="module" lang="ts">
|
|
||||||
let lastSearch = ''
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import InputSearch from './InputSearch.svelte'
|
import InputSearch from './InputSearch.svelte'
|
||||||
import {
|
import {
|
||||||
@@ -26,17 +22,17 @@
|
|||||||
export let modal: OmnisearchInFileModal
|
export let modal: OmnisearchInFileModal
|
||||||
export let parent: OmnisearchVaultModal | null = null
|
export let parent: OmnisearchVaultModal | null = null
|
||||||
export let singleFilePath = ''
|
export let singleFilePath = ''
|
||||||
export let searchQuery: string
|
export let previousQuery: string | undefined
|
||||||
|
|
||||||
|
let searchQuery: string
|
||||||
let groupedOffsets: number[] = []
|
let groupedOffsets: number[] = []
|
||||||
let selectedIndex = 0
|
let selectedIndex = 0
|
||||||
let note: ResultNote | undefined
|
let note: ResultNote | undefined
|
||||||
let query: Query
|
let query: Query
|
||||||
|
|
||||||
|
$: searchQuery = previousQuery ?? ''
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (lastSearch && !searchQuery) {
|
|
||||||
searchQuery = lastSearch
|
|
||||||
}
|
|
||||||
eventBus.enable('infile')
|
eventBus.enable('infile')
|
||||||
|
|
||||||
eventBus.on('infile', 'enter', openSelection)
|
eventBus.on('infile', 'enter', openSelection)
|
||||||
@@ -52,8 +48,12 @@
|
|||||||
$: (async () => {
|
$: (async () => {
|
||||||
if (searchQuery) {
|
if (searchQuery) {
|
||||||
query = new Query(searchQuery)
|
query = new Query(searchQuery)
|
||||||
note = (await SearchEngine.getEngine().getSuggestions(query, { singleFilePath }))[0] ?? null
|
note =
|
||||||
lastSearch = searchQuery
|
(
|
||||||
|
await SearchEngine.getEngine().getSuggestions(query, {
|
||||||
|
singleFilePath,
|
||||||
|
})
|
||||||
|
)[0] ?? null
|
||||||
}
|
}
|
||||||
selectedIndex = 0
|
selectedIndex = 0
|
||||||
await scrollIntoView()
|
await scrollIntoView()
|
||||||
@@ -138,7 +138,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function switchToVaultModal(): void {
|
function switchToVaultModal(): void {
|
||||||
new OmnisearchVaultModal(app).open()
|
new OmnisearchVaultModal(app, previousQuery).open()
|
||||||
modal.close()
|
modal.close()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -146,7 +146,7 @@
|
|||||||
<InputSearch
|
<InputSearch
|
||||||
on:input="{e => (searchQuery = e.detail)}"
|
on:input="{e => (searchQuery = e.detail)}"
|
||||||
placeholder="Omnisearch - File"
|
placeholder="Omnisearch - File"
|
||||||
initialValue="{searchQuery}" />
|
initialValue="{previousQuery}" />
|
||||||
|
|
||||||
<ModalContainer>
|
<ModalContainer>
|
||||||
{#if groupedOffsets.length && note}
|
{#if groupedOffsets.length && note}
|
||||||
|
|||||||
@@ -18,15 +18,15 @@
|
|||||||
import { cacheManager } from '../cache-manager'
|
import { cacheManager } from '../cache-manager'
|
||||||
|
|
||||||
export let modal: OmnisearchVaultModal
|
export let modal: OmnisearchVaultModal
|
||||||
|
export let previousQuery: string | undefined
|
||||||
let selectedIndex = 0
|
let selectedIndex = 0
|
||||||
let historySearchIndex = 0
|
let historySearchIndex = 0
|
||||||
let searchQuery: string | undefined
|
let searchQuery: string | undefined
|
||||||
let previousQuery: string | undefined
|
|
||||||
let resultNotes: ResultNote[] = []
|
let resultNotes: ResultNote[] = []
|
||||||
let query: Query
|
let query: Query
|
||||||
|
|
||||||
$: selectedNote = resultNotes[selectedIndex]
|
$: selectedNote = resultNotes[selectedIndex]
|
||||||
$: searchQuery = previousQuery
|
$: searchQuery = searchQuery ?? previousQuery
|
||||||
$: if (searchQuery) {
|
$: if (searchQuery) {
|
||||||
updateResults()
|
updateResults()
|
||||||
} else {
|
} else {
|
||||||
@@ -163,7 +163,7 @@
|
|||||||
function switchToInFileModal(): void {
|
function switchToInFileModal(): void {
|
||||||
// Do nothing if the selectedNote is a PDF,
|
// Do nothing if the selectedNote is a PDF,
|
||||||
// or if there is 0 match (e.g indexing in progress)
|
// 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,12 +117,13 @@ abstract class OmnisearchModal extends Modal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class OmnisearchVaultModal extends OmnisearchModal {
|
export class OmnisearchVaultModal extends OmnisearchModal {
|
||||||
constructor(app: App) {
|
constructor(app: App, query?: string) {
|
||||||
super(app)
|
super(app)
|
||||||
const cmp = new ModalVault({
|
const cmp = new ModalVault({
|
||||||
target: this.modalEl,
|
target: this.modalEl,
|
||||||
props: {
|
props: {
|
||||||
modal: this,
|
modal: this,
|
||||||
|
previousQuery: query
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -149,7 +150,7 @@ export class OmnisearchInFileModal extends OmnisearchModal {
|
|||||||
modal: this,
|
modal: this,
|
||||||
singleFilePath: file.path,
|
singleFilePath: file.path,
|
||||||
parent: parent,
|
parent: parent,
|
||||||
searchQuery,
|
previousQuery: searchQuery,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user