@@ -959,49 +959,52 @@ export class KeyboardNavigationController extends modules.ViewController {
959959
960960 private _editingCellTabHandler ( eventArgs , direction ) {
961961 const eventTarget = eventArgs . originalEvent . target ;
962- let $cell = this . _getCellElementFromTarget ( eventTarget ) ;
963- let isEditingAllowed ;
964- const $event = eventArgs . originalEvent ;
965- const elementType = this . _getElementType ( eventTarget ) ;
962+ const $targetCell = this . _getCellElementFromTarget ( eventTarget ) ;
963+ const isCommandCell = $targetCell . is ( COMMAND_CELL_SELECTOR ) ;
966964
967- if ( $cell . is ( COMMAND_CELL_SELECTOR ) ) {
965+ if ( isCommandCell ) {
968966 return ! this . _targetCellTabHandler ( eventArgs , direction ) ;
969967 }
970968
971- this . _updateFocusedCellPosition ( $cell ) ;
969+ this . _updateFocusedCellPosition ( $targetCell ) ;
970+
971+ const elementType = this . _getElementType ( eventTarget ) ;
972972 const nextCellInfo = this . _getNextCellByTabKey (
973- $event ,
973+ eventArgs . originalEvent ,
974974 direction ,
975975 elementType ,
976976 ) ;
977- $cell = nextCellInfo . $cell ;
977+ const $nextCell = nextCellInfo . $cell ;
978978
979- if ( ! $cell || this . _handleTabKeyOnMasterDetailCell ( $cell , direction ) ) {
979+ if ( ! $nextCell || this . _handleTabKeyOnMasterDetailCell ( $nextCell , direction ) ) {
980980 return false ;
981981 }
982982
983- const column = this . _getColumnByCellElement ( $cell ) ;
984- const $row = $cell . parent ( ) ;
985- const rowIndex = this . _getRowIndex ( $row ) ;
986- const row = this . _dataController . items ( ) [ rowIndex ] as any ;
987- const editingController = this . _editingController ;
983+ let isEditingAllowed = false ;
984+ const column = this . _getColumnByCellElement ( $nextCell ) ;
988985
989- if ( column && column . allowEditing ) {
986+ if ( column ?. allowEditing ) {
987+ const $row = $nextCell . parent ( ) ;
988+ const rowIndex = this . _getLocalRowIndex ( $row ) ;
989+ const row = this . _dataController . items ( ) [ rowIndex ] as any ;
990990 const isDataRow = ! row || row . rowType === 'data' ;
991- isEditingAllowed = editingController . allowUpdating ( { row } )
992- ? isDataRow
993- : row && row . isNewRow ;
991+
992+ isEditingAllowed = this . _editingController . allowUpdating ( { row } )
993+ ? isDataRow : row ? .isNewRow ;
994994 }
995995
996996 if ( ! isEditingAllowed ) {
997997 this . _closeEditCell ( ) ;
998998 }
999999
1000- if ( this . _focusCell ( $cell , ! nextCellInfo . isHighlighted ) ) {
1001- if ( ! this . _isRowEditMode ( ) && isEditingAllowed ) {
1000+ const nextCellFocused = this . _focusCell ( $nextCell , ! nextCellInfo . isHighlighted ) ;
1001+
1002+ if ( nextCellFocused ) {
1003+ const isRowMode = this . _isRowEditMode ( ) ;
1004+ if ( ! isRowMode && isEditingAllowed ) {
10021005 this . _editFocusedCell ( ) ;
10031006 } else {
1004- this . _focusInteractiveElement ( $cell , eventArgs . shift ) ;
1007+ this . _focusInteractiveElement ( $nextCell , eventArgs . shift ) ;
10051008 }
10061009 }
10071010
@@ -2345,11 +2348,14 @@ export class KeyboardNavigationController extends modules.ViewController {
23452348 columnIndex : number ,
23462349 ) : void {
23472350 const $cell = this . _getFocusedCell ( ) ;
2348- const rowIndex = this . _getRowIndex ( $cell ?. parent ( ) ) ;
2351+ const $row = $cell ?. parent ( ) ;
2352+
2353+ const rowIndex = this . getRowIndex ( ) ;
23492354 const localRowIndex = Math . min (
2350- rowIndex - this . _dataController . getRowIndexOffset ( ) ,
2355+ this . _getLocalRowIndex ( $row ) ,
23512356 this . _dataController . items ( ) . length - 1 ,
23522357 ) ;
2358+
23532359 const isEditingCell = this . _editingController . isEditCell (
23542360 localRowIndex ,
23552361 columnIndex ,
@@ -2491,8 +2497,8 @@ export class KeyboardNavigationController extends modules.ViewController {
24912497 }
24922498 }
24932499
2494- private _getRowIndex ( $row ) {
2495- let rowIndex = this . _rowsView . getRowIndex ( $row ) ;
2500+ private _getRowIndex ( $row ) : number {
2501+ let rowIndex = this . _getLocalRowIndex ( $row ) ;
24962502
24972503 if ( rowIndex >= 0 ) {
24982504 rowIndex += this . _dataController . getRowIndexOffset ( ) ;
@@ -2501,6 +2507,12 @@ export class KeyboardNavigationController extends modules.ViewController {
25012507 return rowIndex ;
25022508 }
25032509
2510+ protected _getLocalRowIndex ( $row ) : number {
2511+ const rowIndex = this . _rowsView . getRowIndex ( $row ) ;
2512+
2513+ return rowIndex ;
2514+ }
2515+
25042516 private _hasSkipRow ( $row ) {
25052517 const row = $row && $row . get ( 0 ) ;
25062518 return row && row . style . display === 'none' ;
0 commit comments