Rebuild review panel entries when the editor viewport changes (#19962)

GitOrigin-RevId: af144a278a3338bffb58e40a91ddbeb204959dee
This commit is contained in:
Alf Eaton 2024-08-15 11:22:14 +01:00 committed by Copybot
parent ad7abee39a
commit acba1b8956
2 changed files with 27 additions and 4 deletions

View file

@ -29,6 +29,7 @@ import { positionItems } from '../utils/position-items'
import { canAggregate } from '../utils/can-aggregate' import { canAggregate } from '../utils/can-aggregate'
import { isInViewport } from '../utils/is-in-viewport' import { isInViewport } from '../utils/is-in-viewport'
import ReviewPanelEmptyState from './review-panel-empty-state' import ReviewPanelEmptyState from './review-panel-empty-state'
import useEventListener from '@/shared/hooks/use-event-listener'
type Positions = Map<string, number> type Positions = Map<string, number>
type Aggregates = Map<string, Change<DeleteOperation>> type Aggregates = Map<string, Change<DeleteOperation>>
@ -97,7 +98,7 @@ const ReviewPanelCurrentFile: FC = () => {
return () => { return () => {
window.clearTimeout(timer) window.clearTimeout(timer)
} }
}, [state, updatePositions, view.viewport.from, view.viewport.to]) }, [state, updatePositions])
useEffect(() => { useEffect(() => {
const element = containerRef.current const element = containerRef.current
@ -111,7 +112,7 @@ const ReviewPanelCurrentFile: FC = () => {
} }
}, [view, updatePositions]) }, [view, updatePositions])
useEffect(() => { const buildEntries = useCallback(() => {
if (ranges) { if (ranges) {
view.requestMeasure({ view.requestMeasure({
key: 'review-panel-position', key: 'review-panel-position',
@ -175,7 +176,13 @@ const ReviewPanelCurrentFile: FC = () => {
}, },
}) })
} }
}, [view, threads, ranges, screenPosition, containerRef]) }, [screenPosition, threads, view, ranges])
useEffect(() => {
buildEntries()
}, [buildEntries])
useEventListener('editor:viewport-changed', buildEntries)
if (!rangesWithPositions) { if (!rangesWithPositions) {
return null return null

View file

@ -161,7 +161,23 @@ export const trackChanges = (
}, },
} }
}) })
: [], : ViewPlugin.define(view => {
let timer: number
return {
update(update) {
if (update.viewportChanged) {
if (timer) {
window.clearTimeout(timer)
}
timer = window.setTimeout(() => {
dispatchEvent(new Event('editor:viewport-changed'))
}, 25)
}
},
}
}),
// draw change decorations // draw change decorations
ViewPlugin.define< ViewPlugin.define<