@@ -31,6 +31,8 @@ import { quote as shellQuote } from "shell-quote";
3131import { debounce } from "throttle-debounce" ;
3232import "./directorypreview.scss" ;
3333
34+ const PageJumpSize = 20 ;
35+
3436declare module "@tanstack/react-table" {
3537 interface TableMeta < TData extends RowData > {
3638 updateName : ( path : string ) => void ;
@@ -493,18 +495,21 @@ function TableBody({
493495 const viewportHeight = viewport . offsetHeight ;
494496 const rowElement = rowRefs . current [ focusIndex ] ;
495497 const rowRect = rowElement . getBoundingClientRect ( ) ;
496- const parentRect = bodyRef . current . getBoundingClientRect ( ) ;
498+ const parentRect = viewport . getBoundingClientRect ( ) ;
497499 const viewportScrollTop = viewport . scrollTop ;
498-
499- const rowTopRelativeToViewport = rowRect . top - parentRect . top ;
500- const rowBottomRelativeToViewport = rowRect . bottom - parentRect . top ;
501-
502- if ( rowTopRelativeToViewport < viewportScrollTop ) {
500+ const rowTopRelativeToViewport = rowRect . top - parentRect . top + viewport . scrollTop ;
501+ const rowBottomRelativeToViewport = rowRect . bottom - parentRect . top + viewport . scrollTop ;
502+ if ( rowTopRelativeToViewport - 30 < viewportScrollTop ) {
503503 // Row is above the visible area
504- viewport . scrollTo ( { top : rowTopRelativeToViewport } ) ;
505- } else if ( rowBottomRelativeToViewport > viewportScrollTop + viewportHeight ) {
504+ let topVal = rowTopRelativeToViewport - 30 ;
505+ if ( topVal < 0 ) {
506+ topVal = 0 ;
507+ }
508+ viewport . scrollTo ( { top : topVal } ) ;
509+ } else if ( rowBottomRelativeToViewport + 5 > viewportScrollTop + viewportHeight ) {
506510 // Row is below the visible area
507- viewport . scrollTo ( { top : rowBottomRelativeToViewport - viewportHeight } ) ;
511+ const topVal = rowBottomRelativeToViewport - viewportHeight + 5 ;
512+ viewport . scrollTo ( { top : topVal } ) ;
508513 }
509514 }
510515 // setIndexChangedFromClick(false);
@@ -772,6 +777,14 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) {
772777 setFocusIndex ( ( idx ) => Math . min ( idx + 1 , filteredData . length - 1 ) ) ;
773778 return true ;
774779 }
780+ if ( checkKeyPressed ( waveEvent , "PageUp" ) ) {
781+ setFocusIndex ( ( idx ) => Math . max ( idx - PageJumpSize , 0 ) ) ;
782+ return true ;
783+ }
784+ if ( checkKeyPressed ( waveEvent , "PageDown" ) ) {
785+ setFocusIndex ( ( idx ) => Math . min ( idx + PageJumpSize , filteredData . length - 1 ) ) ;
786+ return true ;
787+ }
775788 if ( checkKeyPressed ( waveEvent , "Enter" ) ) {
776789 if ( filteredData . length == 0 ) {
777790 return ;
0 commit comments