Skip to content

Commit 2df1c2e

Browse files
authored
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.
1 parent 217ab4a commit 2df1c2e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

frontend/app/view/term/termwrap.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export class TermWrap {
152152
sendDataHandler: (data: string) => void;
153153
onSearchResultsDidChange?: (result: { resultIndex: number; resultCount: number }) => void;
154154
private toDispose: TermTypes.IDisposable[] = [];
155+
pasteActive: boolean = false;
155156

156157
constructor(
157158
blockId: string,
@@ -217,6 +218,19 @@ export class TermWrap {
217218
this.handleResize_debounced = debounce(50, this.handleResize.bind(this));
218219
this.terminal.open(this.connectElem);
219220
this.handleResize();
221+
let pasteEventHandler = () => {
222+
this.pasteActive = true;
223+
setTimeout(() => {
224+
this.pasteActive = false;
225+
}, 30);
226+
};
227+
pasteEventHandler = pasteEventHandler.bind(this);
228+
this.connectElem.addEventListener("paste", pasteEventHandler, true);
229+
this.toDispose.push({
230+
dispose: () => {
231+
this.connectElem.removeEventListener("paste", pasteEventHandler, true);
232+
},
233+
});
220234
}
221235

222236
async initTerminal() {
@@ -263,6 +277,12 @@ export class TermWrap {
263277
if (!this.loaded) {
264278
return;
265279
}
280+
if (this.pasteActive) {
281+
this.pasteActive = false;
282+
if (this.multiInputCallback) {
283+
this.multiInputCallback(data);
284+
}
285+
}
266286
this.sendDataHandler?.(data);
267287
}
268288

0 commit comments

Comments
 (0)