From f3b4fc0732d313eb5d38276e160f917305002ec1 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Mon, 23 Sep 2019 11:07:59 -0700 Subject: [PATCH] Fix interaction between mouse and keyboard (#3070) --- core/gesture.js | 3 +++ core/keyboard_nav/navigation.js | 24 ++++++++++++++++++------ core/toolbox.js | 6 ++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/core/gesture.js b/core/gesture.js index 9b727d26b..2baff66c4 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -663,6 +663,9 @@ Blockly.Gesture.prototype.handleWsStart = function(e, ws) { this.setStartWorkspace_(ws); this.mostRecentEvent_ = e; this.doStart(e); + if (Blockly.keyboardAccessibilityMode) { + Blockly.navigation.setState(Blockly.navigation.STATE_WS); + } }; /** diff --git a/core/keyboard_nav/navigation.js b/core/keyboard_nav/navigation.js index 2ad77a5d5..74f8de14a 100644 --- a/core/keyboard_nav/navigation.js +++ b/core/keyboard_nav/navigation.js @@ -107,6 +107,15 @@ Blockly.navigation.removeMark_ = function() { Blockly.getMainWorkspace().getMarker().hide(); }; +/** + * Set the current navigation state. + * @param {number} newState The new navigation state. + * @package + */ +Blockly.navigation.setState = function(newState) { + Blockly.navigation.currentState_ = newState; +}; + /** * Gets the top node on a block. * This is either the previous connection, output connection or the block. @@ -133,20 +142,23 @@ Blockly.navigation.getTopNode = function(block) { /************************/ /** - * Set the state to the toolbox state and the current category as the first + * If a toolbox exists, set the navigation state to toolbox and select the first + * category in the toolbox. * category. * @private */ Blockly.navigation.focusToolbox_ = function() { - Blockly.navigation.resetFlyout_(false /* shouldHide */); - Blockly.navigation.currentState_ = Blockly.navigation.STATE_TOOLBOX; var workspace = Blockly.getMainWorkspace(); var toolbox = workspace.getToolbox(); + if (toolbox) { + Blockly.navigation.currentState_ = Blockly.navigation.STATE_TOOLBOX; + Blockly.navigation.resetFlyout_(false /* shouldHide */); - if (!Blockly.getMainWorkspace().getMarker().getCurNode()) { - Blockly.navigation.markAtCursor_(); + if (!Blockly.getMainWorkspace().getMarker().getCurNode()) { + Blockly.navigation.markAtCursor_(); + } + toolbox.selectFirstCategory(); } - toolbox.selectFirstCategory(); }; /***********************/ diff --git a/core/toolbox.js b/core/toolbox.js index 207ab225e..5a01affec 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -260,9 +260,15 @@ Blockly.Toolbox.prototype.handleAfterTreeSelected_ = function( if (this.lastCategory_ != newNode) { this.flyout_.scrollToStart(); } + if (Blockly.keyboardAccessibilityMode) { + Blockly.navigation.setState(Blockly.navigation.STATE_TOOLBOX); + } } else { // Hide the flyout. this.flyout_.hide(); + if (Blockly.keyboardAccessibilityMode) { + Blockly.navigation.setState(Blockly.navigation.STATE_WS); + } } if (oldNode != newNode && oldNode != this) { var event = new Blockly.Events.Ui(null, 'category',