@@ -31,6 +31,8 @@ import { quote as shellQuote } from "shell-quote";
31
31
import { debounce } from "throttle-debounce" ;
32
32
import "./directorypreview.scss" ;
33
33
34
+ const PageJumpSize = 20 ;
35
+
34
36
declare module "@tanstack/react-table" {
35
37
interface TableMeta < TData extends RowData > {
36
38
updateName : ( path : string ) => void ;
@@ -493,18 +495,21 @@ function TableBody({
493
495
const viewportHeight = viewport . offsetHeight ;
494
496
const rowElement = rowRefs . current [ focusIndex ] ;
495
497
const rowRect = rowElement . getBoundingClientRect ( ) ;
496
- const parentRect = bodyRef . current . getBoundingClientRect ( ) ;
498
+ const parentRect = viewport . getBoundingClientRect ( ) ;
497
499
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 ) {
503
503
// 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 ) {
506
510
// Row is below the visible area
507
- viewport . scrollTo ( { top : rowBottomRelativeToViewport - viewportHeight } ) ;
511
+ const topVal = rowBottomRelativeToViewport - viewportHeight + 5 ;
512
+ viewport . scrollTo ( { top : topVal } ) ;
508
513
}
509
514
}
510
515
// setIndexChangedFromClick(false);
@@ -772,6 +777,14 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) {
772
777
setFocusIndex ( ( idx ) => Math . min ( idx + 1 , filteredData . length - 1 ) ) ;
773
778
return true ;
774
779
}
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
+ }
775
788
if ( checkKeyPressed ( waveEvent , "Enter" ) ) {
776
789
if ( filteredData . length == 0 ) {
777
790
return ;
0 commit comments