diff --git a/src/components/treemode/TreeMode.svelte b/src/components/treemode/TreeMode.svelte index 2c48d4d..4133514 100644 --- a/src/components/treemode/TreeMode.svelte +++ b/src/components/treemode/TreeMode.svelte @@ -12,8 +12,7 @@ STATE_EXPANDED, STATE_LIMIT, SCROLL_DURATION, - SIMPLE_MODAL_OPTIONS, - SEARCH_PROGRESS_THROTTLE + SIMPLE_MODAL_OPTIONS } from '../../constants.js' import { createHistory } from '../../logic/history.js' import JSONNode from './JSONNode.svelte' @@ -33,7 +32,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, throttle } from 'lodash-es' + import { last, initial, cloneDeep, uniqueId } 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' @@ -80,8 +79,6 @@ findRootPath searchResult = updateSearchResult(doc, results, searchResult) } - const handleSearchProgressDebounced = throttle(handleSearchProgress, SEARCH_PROGRESS_THROTTLE) - function handleSearchDone (results) { searchResult = updateSearchResult(doc, results, searchResult) searching = false @@ -123,7 +120,7 @@ findRootPath searching = true searchHandler = searchAsync(searchText, doc, { - onProgress: handleSearchProgressDebounced, + onProgress: handleSearchProgress, onDone: handleSearchDone }) } diff --git a/src/constants.js b/src/constants.js index 3f16c8e..3fda96e 100644 --- a/src/constants.js +++ b/src/constants.js @@ -8,7 +8,6 @@ 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 diff --git a/src/logic/search.js b/src/logic/search.js index 602da42..36fa22d 100644 --- a/src/logic/search.js +++ b/src/logic/search.js @@ -117,6 +117,7 @@ export function searchAsync (searchText, doc, { onProgress, onDone }, yieldAfter let cancelled = false const results = [] + let newResults = false async function executeSearch () { if (!searchText || searchText === '') { @@ -129,9 +130,14 @@ export function searchAsync (searchText, doc, { onProgress, onDone }, yieldAfter next = search.next() if (next.value) { results.push(next.value) // TODO: make this immutable? - onProgress(results) + newResults = true } else { - // FIXME: don't tick on every search result, only after a pause of x milliseconds? + // time for a small break, give the browser space to do stuff + if (newResults) { + newResults = false + onProgress(results) + } + await tick() } diff --git a/src/utils/domUtils.js b/src/utils/domUtils.js index c5a9f40..ff5a129 100644 --- a/src/utils/domUtils.js +++ b/src/utils/domUtils.js @@ -190,7 +190,6 @@ export function isContentEditableDiv (element) { // test whether a DOM element is an "input" with type "text" export function isTextInput (element) { - console.log('element', element) return (element.nodeName === 'INPUT' && element.type && element.type.toLowerCase() === 'text') }