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.
This commit is contained in:
Mike Sawka 2025-02-19 15:44:16 -08:00 committed by GitHub
parent 217ab4a2e3
commit 2df1c2e7bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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);
}