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