mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-25 10:10:08 +02:00
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:
@@ -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(() => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user