Debounce search input

This commit is contained in:
Simon Cambier
2022-04-17 10:30:41 +02:00
parent db396af9c3
commit 34c771cc31
2 changed files with 6 additions and 3 deletions

View File

@@ -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"

View File

@@ -2,7 +2,6 @@ import type { CachedMetadata } from 'obsidian'
import {
isSearchMatch,
regexLineSplit,
regexWikilink,
regexYaml,
} from './globals'
import type { SearchMatch } from './globals'