Skip to content

Commit 7999188

Browse files
committed
fix directory scroll into view
1 parent affd846 commit 7999188

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

frontend/app/view/preview/directorypreview.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -493,18 +493,21 @@ function TableBody({
493493
const viewportHeight = viewport.offsetHeight;
494494
const rowElement = rowRefs.current[focusIndex];
495495
const rowRect = rowElement.getBoundingClientRect();
496-
const parentRect = bodyRef.current.getBoundingClientRect();
496+
const parentRect = viewport.getBoundingClientRect();
497497
const viewportScrollTop = viewport.scrollTop;
498-
499-
const rowTopRelativeToViewport = rowRect.top - parentRect.top;
500-
const rowBottomRelativeToViewport = rowRect.bottom - parentRect.top;
501-
502-
if (rowTopRelativeToViewport < viewportScrollTop) {
498+
const rowTopRelativeToViewport = rowRect.top - parentRect.top + viewport.scrollTop;
499+
const rowBottomRelativeToViewport = rowRect.bottom - parentRect.top + viewport.scrollTop;
500+
if (rowTopRelativeToViewport - 30 < viewportScrollTop) {
503501
// Row is above the visible area
504-
viewport.scrollTo({ top: rowTopRelativeToViewport });
505-
} else if (rowBottomRelativeToViewport > viewportScrollTop + viewportHeight) {
502+
let topVal = rowTopRelativeToViewport - 30;
503+
if (topVal < 0) {
504+
topVal = 0;
505+
}
506+
viewport.scrollTo({ top: topVal });
507+
} else if (rowBottomRelativeToViewport + 5 > viewportScrollTop + viewportHeight) {
506508
// Row is below the visible area
507-
viewport.scrollTo({ top: rowBottomRelativeToViewport - viewportHeight });
509+
const topVal = rowBottomRelativeToViewport - viewportHeight + 5;
510+
viewport.scrollTo({ top: topVal });
508511
}
509512
}
510513
// setIndexChangedFromClick(false);
@@ -772,6 +775,14 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) {
772775
setFocusIndex((idx) => Math.min(idx + 1, filteredData.length - 1));
773776
return true;
774777
}
778+
if (checkKeyPressed(waveEvent, "PageUp")) {
779+
setFocusIndex((idx) => Math.max(idx - 20, 0));
780+
return true;
781+
}
782+
if (checkKeyPressed(waveEvent, "PageDown")) {
783+
setFocusIndex((idx) => Math.min(idx + 20, filteredData.length - 1));
784+
return true;
785+
}
775786
if (checkKeyPressed(waveEvent, "Enter")) {
776787
if (filteredData.length == 0) {
777788
return;

0 commit comments

Comments
 (0)