@@ -54,6 +54,7 @@ export class ArrowNavigation {
5454 shortcut : ShortcutRegistry . KeyboardShortcut ,
5555 ) : boolean => {
5656 const toolbox = workspace . getToolbox ( ) as Toolbox ;
57+ const flyout = workspace . getFlyout ( ) ;
5758 let isHandled = false ;
5859 switch ( this . navigation . getState ( workspace ) ) {
5960 case Constants . STATE . WORKSPACE :
@@ -70,7 +71,6 @@ export class ArrowNavigation {
7071 case Constants . STATE . TOOLBOX :
7172 // @ts -expect-error private method
7273 isHandled = toolbox && toolbox . selectChild ( ) ;
73- const flyout = workspace . getFlyout ( ) ;
7474 if ( ! isHandled && flyout ) {
7575 Blockly . getFocusManager ( ) . focusTree ( flyout . getWorkspace ( ) ) ;
7676 }
@@ -174,18 +174,22 @@ export class ArrowNavigation {
174174 }
175175 return isHandled ;
176176 case Constants . STATE . TOOLBOX :
177- if ( ! toolbox ) return false ;
178- if ( ! toolbox . getSelectedItem ( ) ) {
179- const firstItem = toolbox . getToolboxItems ( ) . find ( ( item ) => item . isSelectable ( ) ) ?? null ;
180- toolbox . setSelectedItem ( firstItem ) ;
181- isHandled = true ;
182- } else {
183- // @ts -expect-error private method
184- isHandled = toolbox . selectNext ( ) ;
185- }
186- const selectedItem = toolbox . getSelectedItem ( ) ;
187- if ( selectedItem ) {
188- Blockly . getFocusManager ( ) . focusNode ( selectedItem ) ;
177+ if ( toolbox ) {
178+ if ( ! toolbox . getSelectedItem ( ) ) {
179+ const firstItem =
180+ toolbox
181+ . getToolboxItems ( )
182+ . find ( ( item ) => item . isSelectable ( ) ) ?? null ;
183+ toolbox . setSelectedItem ( firstItem ) ;
184+ isHandled = true ;
185+ } else {
186+ // @ts -expect-error private method
187+ isHandled = toolbox . selectNext ( ) ;
188+ }
189+ const selectedItem = toolbox . getSelectedItem ( ) ;
190+ if ( selectedItem ) {
191+ Blockly . getFocusManager ( ) . focusNode ( selectedItem ) ;
192+ }
189193 }
190194 return isHandled ;
191195 default :
@@ -233,12 +237,13 @@ export class ArrowNavigation {
233237 }
234238 return isHandled ;
235239 case Constants . STATE . TOOLBOX :
236- if ( ! toolbox ) return false ;
237- // @ts -expect-error private method
238- isHandled = toolbox . selectPrevious ( ) ;
239- const selectedItem = toolbox . getSelectedItem ( ) ;
240- if ( selectedItem ) {
241- Blockly . getFocusManager ( ) . focusNode ( selectedItem ) ;
240+ if ( toolbox ) {
241+ // @ts -expect-error private method
242+ isHandled = toolbox . selectPrevious ( ) ;
243+ const selectedItem = toolbox . getSelectedItem ( ) ;
244+ if ( selectedItem ) {
245+ Blockly . getFocusManager ( ) . focusNode ( selectedItem ) ;
246+ }
242247 }
243248 return isHandled ;
244249 default :
0 commit comments