Throttle range rebuilding on edits (#23193)

GitOrigin-RevId: 86d9465af663c346805445cd57dd6f6e06049d7b
This commit is contained in:
Alf Eaton
2025-01-29 09:18:40 +00:00
committed by Copybot
parent 90aec12e84
commit 1ca47334f7
@@ -21,6 +21,7 @@ import { postJSON } from '@/infrastructure/fetch-json'
import { useIdeReactContext } from '@/features/ide-react/context/ide-react-context'
import { useConnectionContext } from '@/features/ide-react/context/connection-context'
import useSocketListener from '@/features/ide-react/hooks/use-socket-listener'
import { throttle } from 'lodash'
export type Ranges = {
docId: string
@@ -97,11 +98,15 @@ export const RangesProvider: FC = ({ children }) => {
useEffect(() => {
if (currentDoc) {
const listener = () => {
window.setTimeout(() => {
setRanges(buildRanges(currentDoc))
})
}
const listener = throttle(
() => {
window.setTimeout(() => {
setRanges(buildRanges(currentDoc))
})
},
500,
{ leading: true, trailing: true }
)
// currentDoc.on('ranges:clear.cm6', listener)
currentDoc.on('ranges:redraw.cm6', listener)