fix: Don't select shadow blocks on click (#9538)

* fix: Don't select shadow blocks on click

* test: Verify that clicked shadow blocks do not become selected

* chore: Run formatter
This commit is contained in:
Aaron Dodson
2026-01-13 14:23:08 -08:00
committed by GitHub
parent a4d97c2f18
commit 43ea4161c0
2 changed files with 39 additions and 5 deletions

View File

@@ -773,13 +773,11 @@ export class Gesture {
this.setStartWorkspace(ws);
this.mostRecentEvent = e;
if (!this.startBlock && !this.startBubble && !this.startComment) {
if (!this.targetBlock && !this.startBubble && !this.startComment) {
// Ensure the workspace is selected if nothing else should be. Note that
// this is focusNode() instead of focusTree() because if any active node
// is focused in the workspace it should be defocused.
getFocusManager().focusNode(ws);
} else if (this.startBlock) {
getFocusManager().focusNode(this.startBlock);
}
this.doStart(e);

View File

@@ -12,6 +12,7 @@ import {
sharedTestSetup,
sharedTestTeardown,
} from './test_helpers/setup_teardown.js';
import {getProperSimpleJson} from './test_helpers/toolbox_definitions.js';
import {dispatchPointerEvent} from './test_helpers/user_input.js';
suite('Gesture', function () {
@@ -54,8 +55,12 @@ suite('Gesture', function () {
setup(function () {
sharedTestSetup.call(this);
defineBasicBlockWithField();
const toolbox = document.getElementById('gesture-test-toolbox');
this.workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
const toolbox = getProperSimpleJson();
toolbox.contents.unshift({
'kind': 'block',
'type': 'test_field_block',
});
this.workspace = Blockly.inject('blocklyDiv', {toolbox});
});
teardown(function () {
@@ -94,4 +99,35 @@ suite('Gesture', function () {
const block = getTopFlyoutBlock(flyout);
testGestureIsFieldClick(block, true, this.eventsFireStub);
});
test('Clicking on shadow block does not select it', function () {
const flyout = this.workspace.getFlyout(true);
flyout.createBlock(
flyout.getWorkspace().getBlocksByType('logic_compare')[0],
);
const block = this.workspace.getBlocksByType('logic_compare')[0];
const shadowBlock = block.getInput('A').connection.targetBlock();
this.eventsFireStub.resetHistory();
const eventTarget = shadowBlock.getSvgRoot();
dispatchPointerEvent(eventTarget, 'pointerdown');
dispatchPointerEvent(eventTarget, 'pointerup');
dispatchPointerEvent(eventTarget, 'click');
// The shadow block should not be selected, even though it was clicked.
assertEventNotFired(
this.eventsFireStub,
Blockly.Events.Selected,
{newElementId: shadowBlock.id, type: EventType.SELECTED},
this.workspace.id,
);
// Its parent block should be selected, however.
assertEventFired(
this.eventsFireStub,
Blockly.Events.Selected,
{newElementId: block.id, type: EventType.SELECTED},
this.workspace.id,
);
});
});