From 2eeee8b9af6eeb27c360fbbe41029cd659dd5b01 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 23 Apr 2018 11:39:38 -0700 Subject: [PATCH] Stop handling keypresses when the workspace is hidden. --- core/blockly.js | 5 ++++- core/workspace_svg.js | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index b673c9ebb..b2c31a127 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -173,9 +173,12 @@ Blockly.svgResize = function(workspace) { * @private */ Blockly.onKeyDown_ = function(e) { - if (Blockly.mainWorkspace.options.readOnly || Blockly.utils.isTargetInput(e)) { + if (Blockly.mainWorkspace.options.readOnly || Blockly.utils.isTargetInput(e) + || (Blockly.mainWorkspace.rendered && !Blockly.mainWorkspace.isVisible)) { // No key actions on readonly workspaces. // When focused on an HTML text input widget, don't trap any keys. + // Ignore keypresses on rendered workspaces that have been explicitly + // hidden. return; } var deleteBlock = false; diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 7f4d2a5eb..6ab972d44 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -131,12 +131,20 @@ Blockly.WorkspaceSvg.prototype.resizeHandlerWrapper_ = null; /** * The render status of an SVG workspace. - * Returns `true` for visible workspaces and `false` for non-visible, - * or headless, workspaces. + * Returns `false` for headless workspaces and true for instances of + * `Blockly.WorkspaceSvg`. * @type {boolean} */ Blockly.WorkspaceSvg.prototype.rendered = true; +/** + * Whether the workspace is visible. False if the workspace has been hidden + * by calling `setVisisble(false)`. + * @type {boolean} + * @package + */ +Blockly.WorkspaceSvg.prototype.isVisible = true; + /** * Is this workspace the surface for a flyout? * @type {boolean} @@ -882,6 +890,7 @@ Blockly.WorkspaceSvg.prototype.setVisible = function(isVisible) { } else { Blockly.hideChaff(true); } + this.isVisible = isVisible; }; /**