Merge pull request #20475 from overleaf/dk-fix-positionItems

Change focused item index to be per docId in new review panel

GitOrigin-RevId: af4b91cdc7128302a75f25d11c2afc5a2861abdd
This commit is contained in:
David
2024-09-19 11:08:13 +01:00
committed by Copybot
parent ac197a0a57
commit e1222f2f4f
2 changed files with 19 additions and 10 deletions

View File

@@ -45,20 +45,26 @@ const ReviewPanelCurrentFile: FC = () => {
const [aggregatedRanges, setAggregatedRanges] = useState<AggregatedRanges>()
const containerRef = useRef<HTMLDivElement | null>(null)
const previousFocusedItem = useRef(0)
const previousFocusedItem = useRef(new Map<string, number>())
const updatePositions = useCallback(() => {
if (containerRef.current) {
const extents = positionItems(
const docId = ranges?.docId
if (containerRef.current && docId) {
const positioningRes = positionItems(
containerRef.current,
previousFocusedItem.current
previousFocusedItem.current.get(docId) || 0,
docId
)
if (extents) {
previousFocusedItem.current = extents.activeItemIndex
if (positioningRes) {
previousFocusedItem.current.set(
positioningRes.docId,
positioningRes.activeItemIndex
)
}
}
}, [])
}, [ranges?.docId])
useEffect(() => {
const timer = window.setTimeout(() => {

View File

@@ -4,7 +4,11 @@ const COLLAPSED_HEADER_HEIGHT = 75
const OFFSET_FOR_ENTRIES_ABOVE = 70
export const positionItems = debounce(
(element: HTMLDivElement, previousFocusedItemIndex: number) => {
(
element: HTMLDivElement,
previousFocusedItemIndex: number,
docId: string
) => {
const items = Array.from(
element.querySelectorAll<HTMLDivElement>('.review-panel-entry')
)
@@ -80,9 +84,8 @@ export const positionItems = debounce(
}
return {
docId,
activeItemIndex,
min: topLimit,
max: bottomLimit,
}
},
100,