@@ -42,7 +42,7 @@ export function addGlobalKeyboardShortcuts(): void {
4242 return ;
4343 }
4444
45- // Super tab :)
45+ // Super tab :(
4646 if (
4747 ( commandOrCtrl && key === 'F6' ) ||
4848 ( commandOrCtrl && ! shiftKey && ( key === 't' || key === 'T' ) )
@@ -55,10 +55,7 @@ export function addGlobalKeyboardShortcuts(): void {
5555 const focusedIndexes : Array < number > = [ ] ;
5656
5757 targets . forEach ( ( target , index ) => {
58- if (
59- ( focusedElement != null && target === focusedElement ) ||
60- target . contains ( focusedElement )
61- ) {
58+ if ( target . contains ( focusedElement ) ) {
6259 focusedIndexes . push ( index ) ;
6360 }
6461 } ) ;
@@ -76,20 +73,13 @@ export function addGlobalKeyboardShortcuts(): void {
7673 const focusedIndex = focusedIndexes . at ( - 1 ) ?? - 1 ;
7774
7875 const lastIndex = targets . length - 1 ;
79- const increment = shiftKey ? - 1 : 1 ;
8076
81- let index ;
82- if ( focusedIndex < 0 || focusedIndex >= lastIndex ) {
83- index = 0 ;
77+ let index : number | undefined ;
78+ if ( focusedIndex < 0 ) {
79+ index = shiftKey ? lastIndex : 0 ;
8480 } else {
85- index = focusedIndex + increment ;
86- }
87-
88- while ( ! targets [ index ] ) {
89- index += increment ;
90- if ( index > lastIndex || index < 0 ) {
91- index = 0 ;
92- }
81+ const increment = shiftKey ? lastIndex : 1 ;
82+ index = ( focusedIndex + increment ) % targets . length ;
9383 }
9484
9585 const node = targets [ index ] ;
@@ -98,12 +88,15 @@ export function addGlobalKeyboardShortcuts(): void {
9888 if ( firstFocusableElement ) {
9989 firstFocusableElement . focus ( ) ;
10090 } else {
101- const nodeInfo = Array . from ( node . attributes )
102- . map ( attr => `${ attr . name } =${ attr . value } ` )
103- . join ( ',' ) ;
104- log . warn (
105- `supertab: could not find focus for DOM node ${ node . nodeName } <${ nodeInfo } >`
106- ) ;
91+ if ( node ) {
92+ const nodeInfo = Array . from ( node . attributes )
93+ . map ( attr => `${ attr . name } =${ attr . value } ` )
94+ . join ( ',' ) ;
95+ log . warn (
96+ `supertab: could not find focus for DOM node ${ node . nodeName } <${ nodeInfo } >`
97+ ) ;
98+ }
99+
107100 window . enterMouseMode ( ) ;
108101 const { activeElement } = document ;
109102 if (
0 commit comments