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
4 changes: 1 addition & 3 deletions core/gesture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,13 +777,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);
Expand Down
40 changes: 38 additions & 2 deletions tests/mocha/gesture_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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,
);
});
});
Loading