Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions core/blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,19 @@ 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 (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)) {
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;
Expand Down
22 changes: 20 additions & 2 deletions core/workspace_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 `setVisible(false)`.
* @type {boolean}
* @private
*/
Blockly.WorkspaceSvg.prototype.isVisible_ = true;

/**
* Is this workspace the surface for a flyout?
* @type {boolean}
Expand Down Expand Up @@ -334,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.
Expand Down Expand Up @@ -882,6 +899,7 @@ Blockly.WorkspaceSvg.prototype.setVisible = function(isVisible) {
} else {
Blockly.hideChaff(true);
}
this.isVisible_ = isVisible;
};

/**
Expand Down