From 2df1c2e7bdf149b9b9c37e2a2b5d9bee2614c77d Mon Sep 17 00:00:00 2001 From: Mike Sawka Date: Wed, 19 Feb 2025 15:44:16 -0800 Subject: [PATCH] fix multi-input paste (#2000) a fix for #1862. so now when pasting information into a terminal when multi-input is active, the data will be sent to all terminals in the tab. --- frontend/app/view/term/termwrap.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/frontend/app/view/term/termwrap.ts b/frontend/app/view/term/termwrap.ts index 370312b09..19e632a54 100644 --- a/frontend/app/view/term/termwrap.ts +++ b/frontend/app/view/term/termwrap.ts @@ -152,6 +152,7 @@ export class TermWrap { sendDataHandler: (data: string) => void; onSearchResultsDidChange?: (result: { resultIndex: number; resultCount: number }) => void; private toDispose: TermTypes.IDisposable[] = []; + pasteActive: boolean = false; constructor( blockId: string, @@ -217,6 +218,19 @@ export class TermWrap { this.handleResize_debounced = debounce(50, this.handleResize.bind(this)); this.terminal.open(this.connectElem); this.handleResize(); + let pasteEventHandler = () => { + this.pasteActive = true; + setTimeout(() => { + this.pasteActive = false; + }, 30); + }; + pasteEventHandler = pasteEventHandler.bind(this); + this.connectElem.addEventListener("paste", pasteEventHandler, true); + this.toDispose.push({ + dispose: () => { + this.connectElem.removeEventListener("paste", pasteEventHandler, true); + }, + }); } async initTerminal() { @@ -263,6 +277,12 @@ export class TermWrap { if (!this.loaded) { return; } + if (this.pasteActive) { + this.pasteActive = false; + if (this.multiInputCallback) { + this.multiInputCallback(data); + } + } this.sendDataHandler?.(data); }