fix: prevent middle-click paste duplicating workflow on Linux (#8259)

## Summary

Adds `auxclick` event listener to prevent the browser's default
middle-click paste behavior on Linux systems.

**Problem:** On Linux, middle-clicking anywhere triggers a paste from
the PRIMARY clipboard. When middle-dragging to pan the canvas, this
causes the entire workflow to be duplicated as new nodes on mouse
release.

**Solution:** Add `auxclick` event listener with `preventDefault()` to
the graph canvas, blocking the paste while preserving pan functionality.

## Changes

- Add `auxclick` event listener in `bindEvents()` 
- Add corresponding `removeEventListener` in `unbindEvents()`

## Test Plan

- [ ] On Linux: Middle-drag to pan canvas - should pan without
duplicating nodes
- [ ] On Linux: Verify left/right click behaviors unchanged
- [ ] On Windows/macOS: Verify no regression (auxclick should have no
effect)

Fixes #4464

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-8259-fix-prevent-middle-click-paste-duplicating-workflow-on-Linux-2f16d73d3650812b98f9cada699f5508)
by [Unito](https://www.unito.io)

---------

Co-authored-by: bymyself <cbyrne@comfy.org>
This commit is contained in:
Gregorius Bima Kharisma Wicaksana
2026-03-13 07:23:42 +07:00
committed by GitHub
parent 113a2b5d92
commit 4337b8d6c6

View File

@@ -1951,6 +1951,11 @@ export class LGraphCanvas implements CustomEventDispatcher<LGraphCanvasEventMap>
return false
}
/** Prevents default for middle-click auxclick only. */
_preventMiddleAuxClick(e: MouseEvent): void {
if (e.button === 1) e.preventDefault()
}
/** Captures an event and prevents default - returns true. */
_doReturnTrue(e: Event): boolean {
e.preventDefault()
@@ -1986,6 +1991,8 @@ export class LGraphCanvas implements CustomEventDispatcher<LGraphCanvasEventMap>
canvas.addEventListener('pointercancel', this._mousecancel_callback, true)
canvas.addEventListener('contextmenu', this._doNothing)
// Prevent middle-click paste (PRIMARY clipboard on Linux) - fixes #4464
canvas.addEventListener('auxclick', this._preventMiddleAuxClick)
// Keyboard
this._key_callback = this.processKey.bind(this)
@@ -2024,6 +2031,7 @@ export class LGraphCanvas implements CustomEventDispatcher<LGraphCanvasEventMap>
canvas.removeEventListener('keydown', this._key_callback!)
document.removeEventListener('keyup', this._key_callback!)
canvas.removeEventListener('contextmenu', this._doNothing)
canvas.removeEventListener('auxclick', this._preventMiddleAuxClick)
canvas.removeEventListener('dragenter', this._doReturnTrue)
this._mousedown_callback = undefined