Debounce search input
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { debounce } from "obsidian";
|
||||
import { createEventDispatcher, onMount, tick } from "svelte"
|
||||
// import { throttle } from "lodash-es"
|
||||
import { searchQuery, selectedNote } from "./stores"
|
||||
|
||||
let input: HTMLInputElement
|
||||
let inputValue: string
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
onMount(async () => {
|
||||
@@ -12,6 +13,8 @@ onMount(async () => {
|
||||
input.select()
|
||||
})
|
||||
|
||||
const debouncedOnInput = debounce(() => $searchQuery = inputValue, 100)
|
||||
|
||||
// const throttledMoveNoteSelection = throttle(moveNoteSelection, 75)
|
||||
function moveNoteSelection(ev: KeyboardEvent): void {
|
||||
switch (ev.key) {
|
||||
@@ -57,7 +60,8 @@ function moveNoteSelection(ev: KeyboardEvent): void {
|
||||
|
||||
<input
|
||||
bind:this={input}
|
||||
bind:value={$searchQuery}
|
||||
bind:value={inputValue}
|
||||
on:input={debouncedOnInput}
|
||||
on:keydown={moveNoteSelection}
|
||||
type="text"
|
||||
class="prompt-input"
|
||||
|
||||
@@ -2,7 +2,6 @@ import type { CachedMetadata } from 'obsidian'
|
||||
import {
|
||||
isSearchMatch,
|
||||
regexLineSplit,
|
||||
regexWikilink,
|
||||
regexYaml,
|
||||
} from './globals'
|
||||
import type { SearchMatch } from './globals'
|
||||
|
||||
Reference in New Issue
Block a user