@@ -19,8 +19,8 @@ type ExactlyOneKey<T, K extends keyof T = keyof T> = {
1919/** Represents a directional change in the grid, either by row or by column. */
2020type Delta = ExactlyOneKey < { row : - 1 | 1 ; col : - 1 | 1 } > ;
2121
22- /** */
23- export const Direction : Record < 'Up' | 'Down' | 'Left' | 'Right' , Delta > = {
22+ /** Constants for the four cardinal directions. */
23+ export const direction : Record < 'Up' | 'Down' | 'Left' | 'Right' , Delta > = {
2424 Up : { row : - 1 } ,
2525 Down : { row : 1 } ,
2626 Left : { col : - 1 } ,
@@ -67,13 +67,17 @@ export class GridNavigation<T extends GridNavigationCell> {
6767 return this . inputs . gridFocus . focusCoordinates ( coords ) ;
6868 }
6969
70- /** */
70+ /**
71+ * Gets the coordinates of the next focusable cell in a given direction, without changing focus.
72+ */
7173 peek ( direction : Delta , fromCoords : RowCol ) : RowCol | undefined {
7274 const wrap = direction . row !== undefined ? this . inputs . rowWrap ( ) : this . inputs . colWrap ( ) ;
7375 return this . _peekDirectional ( direction , fromCoords , wrap ) ;
7476 }
7577
76- /** */
78+ /**
79+ * Navigates to the next focusable cell in a given direction.
80+ */
7781 advance ( direction : Delta ) : boolean {
7882 const nextCoords = this . peek ( direction , this . inputs . gridFocus . activeCoords ( ) ) ;
7983 return ! ! nextCoords && this . gotoCoords ( nextCoords ) ;
@@ -89,8 +93,8 @@ export class GridNavigation<T extends GridNavigationCell> {
8993 col : - 1 ,
9094 } ;
9195 return row === undefined
92- ? this . _peekDirectional ( Direction . Right , fromCoords , 'continuous' )
93- : this . _peekDirectional ( Direction . Right , fromCoords , 'nowrap' ) ;
96+ ? this . _peekDirectional ( direction . Right , fromCoords , 'continuous' )
97+ : this . _peekDirectional ( direction . Right , fromCoords , 'nowrap' ) ;
9498 }
9599
96100 /**
@@ -112,8 +116,8 @@ export class GridNavigation<T extends GridNavigationCell> {
112116 col : this . inputs . grid . maxColCount ( ) ,
113117 } ;
114118 return row === undefined
115- ? this . _peekDirectional ( Direction . Left , fromCoords , 'continuous' )
116- : this . _peekDirectional ( Direction . Left , fromCoords , 'nowrap' ) ;
119+ ? this . _peekDirectional ( direction . Left , fromCoords , 'continuous' )
120+ : this . _peekDirectional ( direction . Left , fromCoords , 'nowrap' ) ;
117121 }
118122
119123 /**
@@ -138,7 +142,6 @@ export class GridNavigation<T extends GridNavigationCell> {
138142 const maxColCount = this . inputs . grid . maxColCount ( ) ;
139143 const rowDelta = delta . row ?? 0 ;
140144 const colDelta = delta . col ?? 0 ;
141- const generalDelta = delta . row ?? delta . col ;
142145 let nextCoords = { ...fromCoords } ;
143146
144147 for ( let step = 0 ; step < this . _maxSteps ( ) ; step ++ ) {
@@ -151,6 +154,7 @@ export class GridNavigation<T extends GridNavigationCell> {
151154 if ( wrap === 'nowrap' && isWrapping ) return ;
152155
153156 if ( wrap === 'continuous' ) {
157+ const generalDelta = delta . row ?? delta . col ;
154158 const rowStep = isWrapping ? generalDelta : rowDelta ;
155159 const colStep = isWrapping ? generalDelta : colDelta ;
156160
0 commit comments