#105 - Fixed search input automatic selection
This commit is contained in:
@@ -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)
|
||||
@@ -34,7 +39,7 @@
|
||||
type="text"
|
||||
class="prompt-input"
|
||||
{placeholder}
|
||||
spellcheck="false" />
|
||||
spellcheck="false"/>
|
||||
</div>
|
||||
<slot></slot>
|
||||
</div>
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user