@@ -42,7 +42,7 @@ export function addGlobalKeyboardShortcuts(): void {
42
42
return ;
43
43
}
44
44
45
- // Super tab :)
45
+ // Super tab :(
46
46
if (
47
47
( commandOrCtrl && key === 'F6' ) ||
48
48
( commandOrCtrl && ! shiftKey && ( key === 't' || key === 'T' ) )
@@ -55,10 +55,7 @@ export function addGlobalKeyboardShortcuts(): void {
55
55
const focusedIndexes : Array < number > = [ ] ;
56
56
57
57
targets . forEach ( ( target , index ) => {
58
- if (
59
- ( focusedElement != null && target === focusedElement ) ||
60
- target . contains ( focusedElement )
61
- ) {
58
+ if ( target . contains ( focusedElement ) ) {
62
59
focusedIndexes . push ( index ) ;
63
60
}
64
61
} ) ;
@@ -76,20 +73,13 @@ export function addGlobalKeyboardShortcuts(): void {
76
73
const focusedIndex = focusedIndexes . at ( - 1 ) ?? - 1 ;
77
74
78
75
const lastIndex = targets . length - 1 ;
79
- const increment = shiftKey ? - 1 : 1 ;
80
76
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 ;
84
80
} 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 ;
93
83
}
94
84
95
85
const node = targets [ index ] ;
@@ -98,12 +88,15 @@ export function addGlobalKeyboardShortcuts(): void {
98
88
if ( firstFocusableElement ) {
99
89
firstFocusableElement . focus ( ) ;
100
90
} 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
+
107
100
window . enterMouseMode ( ) ;
108
101
const { activeElement } = document ;
109
102
if (
0 commit comments