Skip to content

Commit 8bcb664

Browse files
fix(ui): stop dragging when user clicks mmb once
This has been an issue for a long time. I suspect it wasn't noticed until now because it's finicky to trigger - you have to click and release very quickly, without moving the mouse at all.
1 parent 0ee360b commit 8bcb664

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

invokeai/frontend/web/src/features/controlLayers/konva/CanvasStageModule.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,14 @@ export class CanvasStageModule extends CanvasModuleBase {
125125
this.konva.stage.on('dragmove', this.onStageDragMove);
126126
this.konva.stage.on('dragend', this.onStageDragEnd);
127127

128-
// Start dragging the stage when the middle mouse button is clicked. We do not need to listen for 'pointerdown' to
129-
// do cleanup - that is done in onStageDragEnd.
128+
// Start dragging the stage when the middle mouse button is clicked and stop dragging when it's released.
129+
// We _also_ stop dragging on dragend - but in case the user doesn't actually start a drag (just clicks MMB once),
130+
// we still need to stop dragging.
131+
//
132+
// Why start dragging on pointerdown instead of dragstart? Because it allows us to immediately show the cursor as
133+
// grabbing, instead of waiting for the user to actually move the mouse to start the drag. Minor UX affordance.
130134
this.konva.stage.on('pointerdown', this.onStagePointerDown);
135+
this.konva.stage.on('pointerup', this.onStagePointerUp);
131136

132137
this.subscriptions.add(() => this.konva.stage.off('wheel', this.onStageMouseWheel));
133138
this.subscriptions.add(() => this.konva.stage.off('dragmove', this.onStageDragMove));
@@ -438,6 +443,13 @@ export class CanvasStageModule extends CanvasModuleBase {
438443
}
439444
};
440445

446+
onStagePointerUp = (e: KonvaEventObject<PointerEvent>) => {
447+
// If the middle mouse button is released and we are dragging, stop dragging the stage
448+
if (e.evt.button === 1) {
449+
this.stopDragging();
450+
}
451+
};
452+
441453
/**
442454
* Forcibly starts dragging the stage. This is useful when you want to start dragging the stage programmatically.
443455
*/

0 commit comments

Comments
 (0)