diff --git a/src/actions/arrow_navigation.ts b/src/actions/arrow_navigation.ts index e0eef938..31955884 100644 --- a/src/actions/arrow_navigation.ts +++ b/src/actions/arrow_navigation.ts @@ -69,11 +69,17 @@ export class ArrowNavigation { } return isHandled; case Constants.STATE.TOOLBOX: - // @ts-expect-error private method - isHandled = toolbox && toolbox.selectChild(); - if (!isHandled && flyout) { - Blockly.getFocusManager().focusTree(flyout.getWorkspace()); - this.navigation.defaultFlyoutCursorIfNeeded(workspace); + if (toolbox) { + const selectedItem = toolbox.getSelectedItem(); + // Don't auto-expand collapsible items. 'Enter' should be used. + if (selectedItem && !selectedItem.isCollapsible()) { + // @ts-expect-error private method + isHandled = toolbox.selectChild(); + } + if (!isHandled && flyout) { + Blockly.getFocusManager().focusTree(flyout.getWorkspace()); + this.navigation.defaultFlyoutCursorIfNeeded(workspace); + } } return true; default: diff --git a/src/actions/enter.ts b/src/actions/enter.ts index a9e069a9..ef1a41ff 100644 --- a/src/actions/enter.ts +++ b/src/actions/enter.ts @@ -19,7 +19,7 @@ import { FocusableTreeTraverser, } from 'blockly/core'; -import type {Block} from 'blockly/core'; +import type {Block, ICollapsibleToolboxItem, Toolbox} from 'blockly/core'; import * as Constants from '../constants'; import type {Navigation} from '../navigation'; @@ -62,6 +62,8 @@ export class EnterAction { let flyoutCursor; let curNode; + const toolbox = workspace.getToolbox() as Toolbox; + switch (this.navigation.getState(workspace)) { case Constants.STATE.WORKSPACE: this.handleEnterForWS(workspace); @@ -77,7 +79,16 @@ export class EnterAction { } else if (curNode instanceof FlyoutButton) { this.triggerButtonCallback(workspace); } - + return true; + case Constants.STATE.TOOLBOX: + if (toolbox) { + const selectedItem = toolbox.getSelectedItem(); + // Only navigate for collapsible items. + if (selectedItem && selectedItem.isCollapsible()) { + (selectedItem as ICollapsibleToolboxItem).toggleExpanded(); + toolbox.refreshSelection(); + } + } return true; default: return false;