@@ -108,6 +108,9 @@ export class Toolbox
108108 /** The workspace this toolbox is on. */
109109 protected readonly workspace_ : WorkspaceSvg ;
110110
111+ /** Whether the mouse is currently being clicked. */
112+ private mouseDown = false ;
113+
111114 /** @param workspace The workspace in which to create new blocks. */
112115 constructor ( workspace : WorkspaceSvg ) {
113116 super ( ) ;
@@ -243,6 +246,16 @@ export class Toolbox
243246 ) ;
244247 this . boundEvents_ . push ( clickEvent ) ;
245248
249+ const mouseUpEvent = browserEvents . bind (
250+ container ,
251+ 'pointerup' ,
252+ this ,
253+ ( ) => {
254+ this . mouseDown = false ;
255+ } ,
256+ ) ;
257+ this . boundEvents_ . push ( mouseUpEvent ) ;
258+
246259 const keyDownEvent = browserEvents . conditionalBind (
247260 contentsContainer ,
248261 'keydown' ,
@@ -259,6 +272,7 @@ export class Toolbox
259272 * @param e Click event to handle.
260273 */
261274 protected onClick_ ( e : PointerEvent ) {
275+ this . mouseDown = true ;
262276 if ( browserEvents . isRightButton ( e ) || e . target === this . HtmlDiv ) {
263277 // Close flyout.
264278 ( common . getMainWorkspace ( ) as WorkspaceSvg ) . hideChaff ( false ) ;
@@ -1134,7 +1148,10 @@ export class Toolbox
11341148 ) : void {
11351149 if ( node !== this ) {
11361150 // Only select the item if it isn't already selected so as to not toggle.
1137- if ( this . getSelectedItem ( ) !== node ) {
1151+ // Also require that the mouse not be down, i.e. that the focusing of
1152+ // the toolbox was keyboard-driven, to avoid opening the flyout when
1153+ // clicking on an empty part of the toolbox.
1154+ if ( this . getSelectedItem ( ) !== node && ! this . mouseDown ) {
11381155 this . setSelectedItem ( node as IToolboxItem ) ;
11391156 }
11401157 } else {
0 commit comments