From 2eeee8b9af6eeb27c360fbbe41029cd659dd5b01 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 23 Apr 2018 11:39:38 -0700 Subject: [PATCH 1/4] 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; }; /** From e06807155d18e26553d61bf533da5bbd0e045b58 Mon Sep 17 00:00:00 2001 From: DD Date: Tue, 7 Aug 2018 17:55:45 -0400 Subject: [PATCH 2/4] Add todo per code review --- core/blockly.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/blockly.js b/core/blockly.js index b2c31a127..974e39d11 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -168,10 +168,12 @@ Blockly.svgResize = function(workspace) { }; /** - * Handle a key-down on SVG drawing surface. + * Handle a key-down on SVG drawing surface. Does nothing if the main workspace is not visible. * @param {!Event} e Key down event. * @private */ + // TODO handle cases where there are multiple workspaces and non-main workspaces are able to accept + // input. Blockly.onKeyDown_ = function(e) { if (Blockly.mainWorkspace.options.readOnly || Blockly.utils.isTargetInput(e) || (Blockly.mainWorkspace.rendered && !Blockly.mainWorkspace.isVisible)) { From 8d3dea4c741f3fa7cdaff5a43c0a8e0c120e4194 Mon Sep 17 00:00:00 2001 From: DD Date: Wed, 8 Aug 2018 20:44:23 -0400 Subject: [PATCH 3/4] Add issue to todo and getter for isVisible on workspace --- core/blockly.js | 6 +++--- core/workspace_svg.js | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index 974e39d11..81c0a7377 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -172,11 +172,11 @@ Blockly.svgResize = function(workspace) { * @param {!Event} e Key down event. * @private */ - // TODO handle cases where there are multiple workspaces and non-main workspaces are able to accept - // input. + // TODO (https://github.com/google/blockly/issues/1998) handle cases where there are multiple workspaces + // and non-main workspaces are able to accept input. Blockly.onKeyDown_ = function(e) { if (Blockly.mainWorkspace.options.readOnly || Blockly.utils.isTargetInput(e) - || (Blockly.mainWorkspace.rendered && !Blockly.mainWorkspace.isVisible)) { + || (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 diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 6ab972d44..ce6e91174 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -139,11 +139,11 @@ Blockly.WorkspaceSvg.prototype.rendered = true; /** * Whether the workspace is visible. False if the workspace has been hidden - * by calling `setVisisble(false)`. + * by calling `setVisible(false)`. * @type {boolean} - * @package + * @private */ -Blockly.WorkspaceSvg.prototype.isVisible = true; +Blockly.WorkspaceSvg.prototype.isVisible_ = true; /** * Is this workspace the surface for a flyout? @@ -342,6 +342,15 @@ Blockly.WorkspaceSvg.prototype.updateInverseScreenCTM = function() { this.inverseScreenCTMDirty_ = true; }; +/** + * Getter for isVisible + * @return {boolean} Whether the workspace is visible. False if the workspace has been hidden + * by calling `setVisible(false)`. + */ +Blockly.WorkspaceSvg.prototype.isVisible = function() { + return this.isVisible_; +}; + /** * Return the absolute coordinates of the top-left corner of this element, * scales that after canvas SVG element, if it's a descendant. @@ -890,7 +899,7 @@ Blockly.WorkspaceSvg.prototype.setVisible = function(isVisible) { } else { Blockly.hideChaff(true); } - this.isVisible = isVisible; + this.isVisible_ = isVisible; }; /** From 4a34663d496ef56ae9a505cb5223df375b2eb262 Mon Sep 17 00:00:00 2001 From: DD Date: Wed, 8 Aug 2018 20:59:30 -0400 Subject: [PATCH 4/4] Fix lint --- core/blockly.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index 81c0a7377..af39f3fe5 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -172,8 +172,8 @@ Blockly.svgResize = function(workspace) { * @param {!Event} e Key down event. * @private */ - // TODO (https://github.com/google/blockly/issues/1998) handle cases where there are multiple workspaces - // and non-main workspaces are able to accept input. +// TODO (https://github.com/google/blockly/issues/1998) handle cases where there are +// multiple workspaces and non-main workspaces are able to accept input. Blockly.onKeyDown_ = function(e) { if (Blockly.mainWorkspace.options.readOnly || Blockly.utils.isTargetInput(e) || (Blockly.mainWorkspace.rendered && !Blockly.mainWorkspace.isVisible())) {