Skip to content

Commit 43ea416

Browse files
authored
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
1 parent a4d97c2 commit 43ea416

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

core/gesture.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,13 +773,11 @@ export class Gesture {
773773
this.setStartWorkspace(ws);
774774
this.mostRecentEvent = e;
775775

776-
if (!this.startBlock && !this.startBubble && !this.startComment) {
776+
if (!this.targetBlock && !this.startBubble && !this.startComment) {
777777
// Ensure the workspace is selected if nothing else should be. Note that
778778
// this is focusNode() instead of focusTree() because if any active node
779779
// is focused in the workspace it should be defocused.
780780
getFocusManager().focusNode(ws);
781-
} else if (this.startBlock) {
782-
getFocusManager().focusNode(this.startBlock);
783781
}
784782

785783
this.doStart(e);

tests/mocha/gesture_test.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
sharedTestSetup,
1313
sharedTestTeardown,
1414
} from './test_helpers/setup_teardown.js';
15+
import {getProperSimpleJson} from './test_helpers/toolbox_definitions.js';
1516
import {dispatchPointerEvent} from './test_helpers/user_input.js';
1617

1718
suite('Gesture', function () {
@@ -54,8 +55,12 @@ suite('Gesture', function () {
5455
setup(function () {
5556
sharedTestSetup.call(this);
5657
defineBasicBlockWithField();
57-
const toolbox = document.getElementById('gesture-test-toolbox');
58-
this.workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
58+
const toolbox = getProperSimpleJson();
59+
toolbox.contents.unshift({
60+
'kind': 'block',
61+
'type': 'test_field_block',
62+
});
63+
this.workspace = Blockly.inject('blocklyDiv', {toolbox});
5964
});
6065

6166
teardown(function () {
@@ -94,4 +99,35 @@ suite('Gesture', function () {
9499
const block = getTopFlyoutBlock(flyout);
95100
testGestureIsFieldClick(block, true, this.eventsFireStub);
96101
});
102+
103+
test('Clicking on shadow block does not select it', function () {
104+
const flyout = this.workspace.getFlyout(true);
105+
flyout.createBlock(
106+
flyout.getWorkspace().getBlocksByType('logic_compare')[0],
107+
);
108+
const block = this.workspace.getBlocksByType('logic_compare')[0];
109+
const shadowBlock = block.getInput('A').connection.targetBlock();
110+
111+
this.eventsFireStub.resetHistory();
112+
const eventTarget = shadowBlock.getSvgRoot();
113+
dispatchPointerEvent(eventTarget, 'pointerdown');
114+
dispatchPointerEvent(eventTarget, 'pointerup');
115+
dispatchPointerEvent(eventTarget, 'click');
116+
117+
// The shadow block should not be selected, even though it was clicked.
118+
assertEventNotFired(
119+
this.eventsFireStub,
120+
Blockly.Events.Selected,
121+
{newElementId: shadowBlock.id, type: EventType.SELECTED},
122+
this.workspace.id,
123+
);
124+
125+
// Its parent block should be selected, however.
126+
assertEventFired(
127+
this.eventsFireStub,
128+
Blockly.Events.Selected,
129+
{newElementId: block.id, type: EventType.SELECTED},
130+
this.workspace.id,
131+
);
132+
});
97133
});

0 commit comments

Comments
 (0)