#105 - Fixed search input automatic selection
This commit is contained in:
@@ -1,22 +1,27 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { debounce } from 'obsidian'
|
import { debounce } from 'obsidian'
|
||||||
import { toggleInputComposition } from 'src/globals'
|
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 = ''
|
export let placeholder = ''
|
||||||
|
let value = ''
|
||||||
|
let elInput: HTMLInputElement
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
let elInput: HTMLInputElement
|
$: {
|
||||||
|
if (initialValue) {
|
||||||
|
value = initialValue
|
||||||
|
selectInput()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
async function selectInput() {
|
||||||
await tick()
|
|
||||||
elInput.focus()
|
elInput.focus()
|
||||||
setTimeout(() => {
|
await tick()
|
||||||
// tick() is not working here?
|
elInput.select()
|
||||||
elInput.select()
|
await tick()
|
||||||
}, 0)
|
}
|
||||||
})
|
|
||||||
|
|
||||||
const debouncedOnInput = debounce(() => {
|
const debouncedOnInput = debounce(() => {
|
||||||
dispatch('input', value)
|
dispatch('input', value)
|
||||||
@@ -34,7 +39,7 @@
|
|||||||
type="text"
|
type="text"
|
||||||
class="prompt-input"
|
class="prompt-input"
|
||||||
{placeholder}
|
{placeholder}
|
||||||
spellcheck="false" />
|
spellcheck="false"/>
|
||||||
</div>
|
</div>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
let selectedIndex = 0
|
let selectedIndex = 0
|
||||||
let historySearchIndex = 0
|
let historySearchIndex = 0
|
||||||
let searchQuery: string
|
let searchQuery: string
|
||||||
|
let previousQuery: string
|
||||||
let resultNotes: ResultNote[] = []
|
let resultNotes: ResultNote[] = []
|
||||||
let query: Query
|
let query: Query
|
||||||
$: selectedNote = resultNotes[selectedIndex]
|
$: selectedNote = resultNotes[selectedIndex]
|
||||||
@@ -30,7 +31,8 @@
|
|||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await NotesIndex.refreshIndex()
|
await NotesIndex.refreshIndex()
|
||||||
searchQuery = searchHistory[historySearchIndex]
|
previousQuery = searchHistory[historySearchIndex]
|
||||||
|
searchQuery = previousQuery
|
||||||
eventBus.enable('vault')
|
eventBus.enable('vault')
|
||||||
eventBus.on('vault', 'enter', openNoteAndCloseModal)
|
eventBus.on('vault', 'enter', openNoteAndCloseModal)
|
||||||
eventBus.on('vault', 'create-note', createNoteAndCloseModal)
|
eventBus.on('vault', 'create-note', createNoteAndCloseModal)
|
||||||
@@ -181,7 +183,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<InputSearch
|
<InputSearch
|
||||||
value="{searchQuery}"
|
initialValue="{previousQuery}"
|
||||||
on:input="{e => (searchQuery = e.detail)}"
|
on:input="{e => (searchQuery = e.detail)}"
|
||||||
placeholder="Omnisearch - Vault">
|
placeholder="Omnisearch - Vault">
|
||||||
{#if settings.showCreateButton}
|
{#if settings.showCreateButton}
|
||||||
|
|||||||
Reference in New Issue
Block a user