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
19 changes: 18 additions & 1 deletion core/toolbox/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export class Toolbox
/** The workspace this toolbox is on. */
protected readonly workspace_: WorkspaceSvg;

/** Whether the mouse is currently being clicked. */
private mouseDown = false;

/** @param workspace The workspace in which to create new blocks. */
constructor(workspace: WorkspaceSvg) {
super();
Expand Down Expand Up @@ -243,6 +246,16 @@ export class Toolbox
);
this.boundEvents_.push(clickEvent);

const mouseUpEvent = browserEvents.bind(
container,
'pointerup',
this,
() => {
this.mouseDown = false;
},
);
this.boundEvents_.push(mouseUpEvent);

const keyDownEvent = browserEvents.conditionalBind(
contentsContainer,
'keydown',
Expand All @@ -259,6 +272,7 @@ export class Toolbox
* @param e Click event to handle.
*/
protected onClick_(e: PointerEvent) {
this.mouseDown = true;
if (browserEvents.isRightButton(e) || e.target === this.HtmlDiv) {
// Close flyout.
(common.getMainWorkspace() as WorkspaceSvg).hideChaff(false);
Expand Down Expand Up @@ -1134,7 +1148,10 @@ export class Toolbox
): void {
if (node !== this) {
// Only select the item if it isn't already selected so as to not toggle.
if (this.getSelectedItem() !== node) {
// Also require that the mouse not be down, i.e. that the focusing of
// the toolbox was keyboard-driven, to avoid opening the flyout when
// clicking on an empty part of the toolbox.
if (this.getSelectedItem() !== node && !this.mouseDown) {
this.setSelectedItem(node as IToolboxItem);
}
} else {
Expand Down
9 changes: 9 additions & 0 deletions tests/browser/test/toolbox_drag_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,13 @@ suite('Open toolbox categories', function () {
);
await openCategories(this.browser, testCategories, screenDirection.RTL);
});

test('clicking the toolbox itself does not open the flyout', async function () {
this.browser = await testSetup(testFileLocations.PLAYGROUND);
await this.browser.$('.blocklyToolbox').click();
const flyoutOpen = await this.browser.execute(() => {
return Blockly.getMainWorkspace().getFlyout().isVisible();
});
chai.assert.isFalse(flyoutOpen);
});
});
Loading