Remove throttling, report onProgress less often
This commit is contained in:
parent
df853f6370
commit
a20359c6a8
|
@ -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
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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')
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue