From 4337b8d6c61a100e6362b41595c520a880e00829 Mon Sep 17 00:00:00 2001 From: Gregorius Bima Kharisma Wicaksana <51526537+bimakw@users.noreply.github.com> Date: Fri, 13 Mar 2026 07:23:42 +0700 Subject: [PATCH] fix: prevent middle-click paste duplicating workflow on Linux (#8259) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 --- src/lib/litegraph/src/LGraphCanvas.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/litegraph/src/LGraphCanvas.ts b/src/lib/litegraph/src/LGraphCanvas.ts index 16295d56ae..fb9d878cc6 100644 --- a/src/lib/litegraph/src/LGraphCanvas.ts +++ b/src/lib/litegraph/src/LGraphCanvas.ts @@ -1951,6 +1951,11 @@ export class LGraphCanvas implements CustomEventDispatcher 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 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 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