Remove throttling, report onProgress less often
This commit is contained in:
parent
df853f6370
commit
a20359c6a8
|
@ -12,8 +12,7 @@
|
||||||
STATE_EXPANDED,
|
STATE_EXPANDED,
|
||||||
STATE_LIMIT,
|
STATE_LIMIT,
|
||||||
SCROLL_DURATION,
|
SCROLL_DURATION,
|
||||||
SIMPLE_MODAL_OPTIONS,
|
SIMPLE_MODAL_OPTIONS
|
||||||
SEARCH_PROGRESS_THROTTLE
|
|
||||||
} from '../../constants.js'
|
} from '../../constants.js'
|
||||||
import { createHistory } from '../../logic/history.js'
|
import { createHistory } from '../../logic/history.js'
|
||||||
import JSONNode from './JSONNode.svelte'
|
import JSONNode from './JSONNode.svelte'
|
||||||
|
@ -33,7 +32,7 @@ findRootPath
|
||||||
import { keyComboFromEvent } from '../../utils/keyBindings.js'
|
import { keyComboFromEvent } from '../../utils/keyBindings.js'
|
||||||
import { searchAsync, searchNext, searchPrevious, updateSearchResult } from '../../logic/search.js'
|
import { searchAsync, searchNext, searchPrevious, updateSearchResult } from '../../logic/search.js'
|
||||||
import { immutableJSONPatch } from '../../utils/immutableJSONPatch'
|
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 jump from '../../assets/jump.js/src/jump.js'
|
||||||
import { expandPath, syncState, patchProps } from '../../logic/documentState.js'
|
import { expandPath, syncState, patchProps } from '../../logic/documentState.js'
|
||||||
import Menu from './Menu.svelte'
|
import Menu from './Menu.svelte'
|
||||||
|
@ -80,8 +79,6 @@ findRootPath
|
||||||
searchResult = updateSearchResult(doc, results, searchResult)
|
searchResult = updateSearchResult(doc, results, searchResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSearchProgressDebounced = throttle(handleSearchProgress, SEARCH_PROGRESS_THROTTLE)
|
|
||||||
|
|
||||||
function handleSearchDone (results) {
|
function handleSearchDone (results) {
|
||||||
searchResult = updateSearchResult(doc, results, searchResult)
|
searchResult = updateSearchResult(doc, results, searchResult)
|
||||||
searching = false
|
searching = false
|
||||||
|
@ -123,7 +120,7 @@ findRootPath
|
||||||
searching = true
|
searching = true
|
||||||
|
|
||||||
searchHandler = searchAsync(searchText, doc, {
|
searchHandler = searchAsync(searchText, doc, {
|
||||||
onProgress: handleSearchProgressDebounced,
|
onProgress: handleSearchProgress,
|
||||||
onDone: handleSearchDone
|
onDone: handleSearchDone
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ export const VALIDATION_ERROR = Symbol('validation:error')
|
||||||
|
|
||||||
export const SCROLL_DURATION = 300 // ms
|
export const SCROLL_DURATION = 300 // ms
|
||||||
export const DEBOUNCE_DELAY = 300
|
export const DEBOUNCE_DELAY = 300
|
||||||
export const SEARCH_PROGRESS_THROTTLE = 300 // ms
|
|
||||||
export const DEFAULT_LIMIT = 100
|
export const DEFAULT_LIMIT = 100
|
||||||
export const MAX_PREVIEW_CHARACTERS = 20e3 // characters
|
export const MAX_PREVIEW_CHARACTERS = 20e3 // characters
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,7 @@ export function searchAsync (searchText, doc, { onProgress, onDone }, yieldAfter
|
||||||
|
|
||||||
let cancelled = false
|
let cancelled = false
|
||||||
const results = []
|
const results = []
|
||||||
|
let newResults = false
|
||||||
|
|
||||||
async function executeSearch () {
|
async function executeSearch () {
|
||||||
if (!searchText || searchText === '') {
|
if (!searchText || searchText === '') {
|
||||||
|
@ -129,9 +130,14 @@ export function searchAsync (searchText, doc, { onProgress, onDone }, yieldAfter
|
||||||
next = search.next()
|
next = search.next()
|
||||||
if (next.value) {
|
if (next.value) {
|
||||||
results.push(next.value) // TODO: make this immutable?
|
results.push(next.value) // TODO: make this immutable?
|
||||||
onProgress(results)
|
newResults = true
|
||||||
} else {
|
} 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()
|
await tick()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,6 @@ export function isContentEditableDiv (element) {
|
||||||
|
|
||||||
// test whether a DOM element is an "input" with type "text"
|
// test whether a DOM element is an "input" with type "text"
|
||||||
export function isTextInput (element) {
|
export function isTextInput (element) {
|
||||||
console.log('element', element)
|
|
||||||
return (element.nodeName === 'INPUT' && element.type && element.type.toLowerCase() === 'text')
|
return (element.nodeName === 'INPUT' && element.type && element.type.toLowerCase() === 'text')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue