From 6e64fe09600d0af53242bd0231c222991b9e571d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 19 Dec 2025 14:14:04 -0800 Subject: [PATCH 1/4] fix: Don't open the toolbox when clicking beneath the categories --- core/toolbox/toolbox.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/toolbox/toolbox.ts b/core/toolbox/toolbox.ts index f34034d3399..98dc5375c8c 100644 --- a/core/toolbox/toolbox.ts +++ b/core/toolbox/toolbox.ts @@ -108,6 +108,8 @@ export class Toolbox /** The workspace this toolbox is on. */ protected readonly workspace_: WorkspaceSvg; + private mouseDown = false; + /** @param workspace The workspace in which to create new blocks. */ constructor(workspace: WorkspaceSvg) { super(); @@ -243,6 +245,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', @@ -259,6 +271,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); @@ -1134,7 +1147,7 @@ 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) { + if (this.getSelectedItem() !== node && !this.mouseDown) { this.setSelectedItem(node as IToolboxItem); } } else { From a5608efa12f55d59ec9ea9f657fa7e55fb32e0bb Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 19 Dec 2025 14:16:40 -0800 Subject: [PATCH 2/4] chore: Add docstring --- core/toolbox/toolbox.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/core/toolbox/toolbox.ts b/core/toolbox/toolbox.ts index 98dc5375c8c..7a875e34239 100644 --- a/core/toolbox/toolbox.ts +++ b/core/toolbox/toolbox.ts @@ -108,6 +108,7 @@ 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. */ From 7d211bd5fd17e71481f12d4f1478c958d8f84445 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 23 Dec 2025 09:11:17 -0800 Subject: [PATCH 3/4] chore: Add test --- tests/browser/test/toolbox_drag_test.mjs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/browser/test/toolbox_drag_test.mjs b/tests/browser/test/toolbox_drag_test.mjs index 66b74d9e2c5..5687febbb83 100644 --- a/tests/browser/test/toolbox_drag_test.mjs +++ b/tests/browser/test/toolbox_drag_test.mjs @@ -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); + }); }); From 74aa33e878b75912bb25a843b94339bd9b1cfba6 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 23 Dec 2025 09:12:58 -0800 Subject: [PATCH 4/4] chore: Add comment clarifying selection logic --- core/toolbox/toolbox.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/toolbox/toolbox.ts b/core/toolbox/toolbox.ts index 7a875e34239..6f4daf4ed71 100644 --- a/core/toolbox/toolbox.ts +++ b/core/toolbox/toolbox.ts @@ -1148,6 +1148,9 @@ export class Toolbox ): void { if (node !== this) { // Only select the item if it isn't already selected so as to not toggle. + // 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); }