diff --git a/src/components/treemode/TreeMode.svelte b/src/components/treemode/TreeMode.svelte index 4133514..2c48d4d 100644 --- a/src/components/treemode/TreeMode.svelte +++ b/src/components/treemode/TreeMode.svelte @@ -12,7 +12,8 @@ STATE_EXPANDED, STATE_LIMIT, SCROLL_DURATION, - SIMPLE_MODAL_OPTIONS + SIMPLE_MODAL_OPTIONS, + SEARCH_PROGRESS_THROTTLE } from '../../constants.js' import { createHistory } from '../../logic/history.js' import JSONNode from './JSONNode.svelte' @@ -32,7 +33,7 @@ findRootPath import { keyComboFromEvent } from '../../utils/keyBindings.js' import { searchAsync, searchNext, searchPrevious, updateSearchResult } from '../../logic/search.js' import { immutableJSONPatch } from '../../utils/immutableJSONPatch' - import { last, initial, cloneDeep, uniqueId } from 'lodash-es' + import { last, initial, cloneDeep, uniqueId, throttle } from 'lodash-es' import jump from '../../assets/jump.js/src/jump.js' import { expandPath, syncState, patchProps } from '../../logic/documentState.js' import Menu from './Menu.svelte' @@ -79,6 +80,8 @@ findRootPath searchResult = updateSearchResult(doc, results, searchResult) } + const handleSearchProgressDebounced = throttle(handleSearchProgress, SEARCH_PROGRESS_THROTTLE) + function handleSearchDone (results) { searchResult = updateSearchResult(doc, results, searchResult) searching = false @@ -120,7 +123,7 @@ findRootPath searching = true searchHandler = searchAsync(searchText, doc, { - onProgress: handleSearchProgress, + onProgress: handleSearchProgressDebounced, onDone: handleSearchDone }) } diff --git a/src/constants.js b/src/constants.js index 3fda96e..3f16c8e 100644 --- a/src/constants.js +++ b/src/constants.js @@ -8,6 +8,7 @@ export const VALIDATION_ERROR = Symbol('validation:error') export const SCROLL_DURATION = 300 // ms export const DEBOUNCE_DELAY = 300 +export const SEARCH_PROGRESS_THROTTLE = 300 // ms export const DEFAULT_LIMIT = 100 export const MAX_PREVIEW_CHARACTERS = 20e3 // characters