Skip to content

Commit 968088e

Browse files
authored
Merge pull request #1674 from fsih/keyWhenVisible
Only take keypresses when visible
2 parents 6f14a2b + 4eec9df commit 968088e

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

core/blockly.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,19 @@ Blockly.svgResize = function(workspace) {
175175
};
176176

177177
/**
178-
* Handle a key-down on SVG drawing surface.
178+
* Handle a key-down on SVG drawing surface. Does nothing if the main workspace is not visible.
179179
* @param {!Event} e Key down event.
180180
* @private
181181
*/
182+
// TODO (https://github.com/google/blockly/issues/1998) handle cases where there are multiple workspaces
183+
// and non-main workspaces are able to accept input.
182184
Blockly.onKeyDown_ = function(e) {
183-
if (Blockly.mainWorkspace.options.readOnly || Blockly.utils.isTargetInput(e)) {
185+
if (Blockly.mainWorkspace.options.readOnly || Blockly.utils.isTargetInput(e)
186+
|| (Blockly.mainWorkspace.rendered && !Blockly.mainWorkspace.isVisible())) {
184187
// No key actions on readonly workspaces.
185188
// When focused on an HTML text input widget, don't trap any keys.
189+
// Ignore keypresses on rendered workspaces that have been explicitly
190+
// hidden.
186191
return;
187192
}
188193
var deleteBlock = false;

core/workspace_svg.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,20 @@ Blockly.WorkspaceSvg.prototype.resizeHandlerWrapper_ = null;
127127

128128
/**
129129
* The render status of an SVG workspace.
130-
* Returns `true` for visible workspaces and `false` for non-visible,
131-
* or headless, workspaces.
130+
* Returns `false` for headless workspaces and true for instances of
131+
* `Blockly.WorkspaceSvg`.
132132
* @type {boolean}
133133
*/
134134
Blockly.WorkspaceSvg.prototype.rendered = true;
135135

136+
/**
137+
* Whether the workspace is visible. False if the workspace has been hidden
138+
* by calling `setVisible(false)`.
139+
* @type {boolean}
140+
* @private
141+
*/
142+
Blockly.WorkspaceSvg.prototype.isVisible_ = true;
143+
136144
/**
137145
* Is this workspace the surface for a flyout?
138146
* @type {boolean}
@@ -316,6 +324,15 @@ Blockly.WorkspaceSvg.prototype.getInverseScreenCTM = function() {
316324
return this.inverseScreenCTM_;
317325
};
318326

327+
/**
328+
* Getter for isVisible
329+
* @return {boolean} Whether the workspace is visible. False if the workspace has been hidden
330+
* by calling `setVisible(false)`.
331+
*/
332+
Blockly.WorkspaceSvg.prototype.isVisible = function() {
333+
return this.isVisible_;
334+
};
335+
319336
/**
320337
* Mark the inverse screen CTM as dirty.
321338
*/
@@ -865,6 +882,7 @@ Blockly.WorkspaceSvg.prototype.setVisible = function(isVisible) {
865882
Blockly.hideChaff(true);
866883
Blockly.DropDownDiv.hideWithoutAnimation();
867884
}
885+
this.isVisible_ = isVisible;
868886
};
869887

870888
/**

0 commit comments

Comments
 (0)