#105 - Fixed search input automatic selection

This commit is contained in:
Simon Cambier
2022-10-22 13:36:12 +02:00
parent dbd66b43c7
commit 8696f1381d
2 changed files with 20 additions and 13 deletions

View File

@@ -1,22 +1,27 @@
<script lang="ts">
import { debounce } from 'obsidian'
import { toggleInputComposition } from 'src/globals'
import { createEventDispatcher, onMount, tick } from 'svelte'
import { createEventDispatcher, tick } from 'svelte'
export let value = ''
export let initialValue = ''
export let placeholder = ''
let value = ''
let elInput: HTMLInputElement
const dispatch = createEventDispatcher()
let elInput: HTMLInputElement
$: {
if (initialValue) {
value = initialValue
selectInput()
}
}
onMount(async () => {
await tick()
async function selectInput() {
elInput.focus()
setTimeout(() => {
// tick() is not working here?
await tick()
elInput.select()
}, 0)
})
await tick()
}
const debouncedOnInput = debounce(() => {
dispatch('input', value)

View File

@@ -18,6 +18,7 @@
let selectedIndex = 0
let historySearchIndex = 0
let searchQuery: string
let previousQuery: string
let resultNotes: ResultNote[] = []
let query: Query
$: selectedNote = resultNotes[selectedIndex]
@@ -30,7 +31,8 @@
onMount(async () => {
await NotesIndex.refreshIndex()
searchQuery = searchHistory[historySearchIndex]
previousQuery = searchHistory[historySearchIndex]
searchQuery = previousQuery
eventBus.enable('vault')
eventBus.on('vault', 'enter', openNoteAndCloseModal)
eventBus.on('vault', 'create-note', createNoteAndCloseModal)
@@ -181,7 +183,7 @@
</script>
<InputSearch
value="{searchQuery}"
initialValue="{previousQuery}"
on:input="{e => (searchQuery = e.detail)}"
placeholder="Omnisearch - Vault">
{#if settings.showCreateButton}