Merge pull request from fsih/keyWhenVisible

Only take keypresses when visible
This commit is contained in:
DD Liu 2018-08-09 13:14:48 -04:00 committed by GitHub
commit 968088e7bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 4 deletions

View file

@ -175,14 +175,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;

View file

@ -127,12 +127,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}
@ -316,6 +324,15 @@ Blockly.WorkspaceSvg.prototype.getInverseScreenCTM = function() {
return this.inverseScreenCTM_;
};
/**
* 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_;
};
/**
* Mark the inverse screen CTM as dirty.
*/
@ -865,6 +882,7 @@ Blockly.WorkspaceSvg.prototype.setVisible = function(isVisible) {
Blockly.hideChaff(true);
Blockly.DropDownDiv.hideWithoutAnimation();
}
this.isVisible_ = isVisible;
};
/**