Skip to content

Commit eca0228

Browse files
authored
fix: Prevent workspace click handlers in minimap. (#2133)
1 parent 5dd2ced commit eca0228

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

plugins/workspace-minimap/src/minimap.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,24 @@ export class Minimap {
9797
}
9898
});
9999

100+
// The mousedown handler needs to take precedent over other mouse handlers
101+
// in the workspace, such as the handler that opens comments, which means it
102+
// needs to be attached in the capture phase. Blockly's built-in event
103+
// binding does not let us use the capture phase so we reimplement it here.
104+
const mouseDownFunc = (event: Event) =>
105+
this.onClickDown(event as PointerEvent);
106+
this.minimapWorkspace.svgGroup_.addEventListener(
107+
'pointerdown',
108+
mouseDownFunc,
109+
/* usecapture */ true,
110+
);
111+
this.onMouseDownWrapper = [
112+
[this.minimapWorkspace.svgGroup_, 'pointerdown', mouseDownFunc],
113+
];
114+
100115
// The mouseup binds to the parent container div instead of the minimap
101116
// because if a drag begins on the minimap and ends outside of it the
102117
// mousemove should still unbind.
103-
this.onMouseDownWrapper = Blockly.browserEvents.bind(
104-
this.minimapWorkspace.svgGroup_,
105-
'mousedown',
106-
this,
107-
this.onClickDown,
108-
);
109118
this.onMouseUpWrapper = Blockly.browserEvents.bind(
110119
primaryInjectParentDiv,
111120
'mouseup',
@@ -242,6 +251,10 @@ export class Minimap {
242251
*/
243252
private onClickDown(event: PointerEvent): void {
244253
if (this.minimapWorkspace) {
254+
// Stop any other click event handlers in the workspace from handling
255+
// this event.
256+
event.stopImmediatePropagation();
257+
245258
this.onMouseMoveWrapper = Blockly.browserEvents.bind(
246259
this.minimapWorkspace.svgGroup_,
247260
'mousemove',

0 commit comments

Comments
 (0)