Cancelable search query
This commit is contained in:
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@@ -58,7 +58,7 @@ devDependencies:
|
|||||||
esbuild-plugin-copy: 1.3.0_esbuild@0.14.0
|
esbuild-plugin-copy: 1.3.0_esbuild@0.14.0
|
||||||
esbuild-svelte: 0.7.1_wvi5wuag3veo5vm52k3h7pgaae
|
esbuild-svelte: 0.7.1_wvi5wuag3veo5vm52k3h7pgaae
|
||||||
jest: 27.5.1
|
jest: 27.5.1
|
||||||
obsidian: 1.1.1
|
obsidian: 1.2.8
|
||||||
prettier: 2.8.1
|
prettier: 2.8.1
|
||||||
prettier-plugin-svelte: 2.8.1_sro2v6ld777payjtkjtiuogcxi
|
prettier-plugin-svelte: 2.8.1_sro2v6ld777payjtkjtiuogcxi
|
||||||
svelte: 3.54.0
|
svelte: 3.54.0
|
||||||
@@ -4119,8 +4119,8 @@ packages:
|
|||||||
object-keys: 1.1.1
|
object-keys: 1.1.1
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/obsidian/1.1.1:
|
/obsidian/1.2.8:
|
||||||
resolution: {integrity: sha512-GcxhsHNkPEkwHEjeyitfYNBcQuYGeAHFs1pEpZIv0CnzSfui8p8bPLm2YKLgcg20B764770B1sYGtxCvk9ptxg==}
|
resolution: {integrity: sha512-HrC+feA8o0tXspj4lEAqxb1btwLwHD2oHXSwbbN+CdRHURqbCkuIDLld+nkuyJ1w1c9uvVDRVk8BoeOnWheOrQ==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
'@codemirror/state': ^6.0.0
|
'@codemirror/state': ^6.0.0
|
||||||
'@codemirror/view': ^6.0.0
|
'@codemirror/view': ^6.0.0
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
export function setInputValue(v: string): void {
|
export function setInputValue(v: string): void {
|
||||||
console.log('setinput')
|
|
||||||
value = v
|
value = v
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +41,7 @@
|
|||||||
// the next time we open the modal, the search field will be empty
|
// the next time we open the modal, the search field will be empty
|
||||||
cacheManager.addToSearchHistory('')
|
cacheManager.addToSearchHistory('')
|
||||||
dispatch('input', value)
|
dispatch('input', value)
|
||||||
}, 250)
|
}, 300)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="omnisearch-input-container">
|
<div class="omnisearch-input-container">
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
import * as NotesIndex from '../notes-index'
|
import * as NotesIndex from '../notes-index'
|
||||||
import { cacheManager } from '../cache-manager'
|
import { cacheManager } from '../cache-manager'
|
||||||
import { searchEngine } from 'src/search/omnisearch'
|
import { searchEngine } from 'src/search/omnisearch'
|
||||||
|
import { cancelable, CancelablePromise } from 'cancelable-promise'
|
||||||
|
|
||||||
export let modal: OmnisearchVaultModal
|
export let modal: OmnisearchVaultModal
|
||||||
let previousQuery: string | undefined
|
let previousQuery: string | undefined
|
||||||
@@ -112,9 +113,20 @@
|
|||||||
refInput?.setInputValue(searchQuery)
|
refInput?.setInputValue(searchQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let cancelableQuery: CancelablePromise<ResultNote[]> | null = null
|
||||||
async function updateResults() {
|
async function updateResults() {
|
||||||
|
// If search is already in progress, cancel it and start a new one
|
||||||
|
if (cancelableQuery) {
|
||||||
|
cancelableQuery.cancel()
|
||||||
|
cancelableQuery = null
|
||||||
|
}
|
||||||
query = new Query(searchQuery)
|
query = new Query(searchQuery)
|
||||||
resultNotes = await searchEngine.getSuggestions(query)
|
cancelableQuery = cancelable(
|
||||||
|
new Promise(resolve => {
|
||||||
|
resolve(searchEngine.getSuggestions(query))
|
||||||
|
})
|
||||||
|
)
|
||||||
|
resultNotes = await cancelableQuery
|
||||||
selectedIndex = 0
|
selectedIndex = 0
|
||||||
await scrollIntoView()
|
await scrollIntoView()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user