Allow pasting terminal text as single line

Fixes #200413
This commit is contained in:
Daniel Imms
2023-12-19 09:58:38 -08:00
parent a276ee63cc
commit 2db9790a9c
2 changed files with 29 additions and 6 deletions
@@ -1188,12 +1188,16 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
return;
}
const currentText: string = value;
let currentText = value;
const shouldPasteText = await this._scopedInstantiationService.invokeFunction(shouldPasteTerminalText, currentText, this.xterm?.raw.modes.bracketedPasteMode);
if (!shouldPasteText) {
return;
}
if (typeof shouldPasteText === 'object') {
currentText = shouldPasteText.modifiedText;
}
this.focus();
this.xterm.raw.paste(currentText);
}
@@ -9,7 +9,7 @@ import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { TerminalSettingId } from 'vs/platform/terminal/common/terminal';
export async function shouldPasteTerminalText(accessor: ServicesAccessor, text: string, bracketedPasteMode: boolean | undefined): Promise<boolean> {
export async function shouldPasteTerminalText(accessor: ServicesAccessor, text: string, bracketedPasteMode: boolean | undefined): Promise<boolean | { modifiedText: string }> {
const configurationService = accessor.get(IConfigurationService);
const dialogService = accessor.get(IDialogService);
@@ -70,18 +70,37 @@ export async function shouldPasteTerminalText(accessor: ServicesAccessor, text:
detail += `\n…`;
}
const { confirmed, checkboxChecked } = await dialogService.confirm({
const { result, checkboxChecked } = await dialogService.prompt<{ confirmed: boolean; singleLine: boolean }>({
message: localize('confirmMoveTrashMessageFilesAndDirectories', "Are you sure you want to paste {0} lines of text into the terminal?", textForLines.length),
detail,
primaryButton: localize({ key: 'multiLinePasteButton', comment: ['&& denotes a mnemonic'] }, "&&Paste"),
type: 'warning',
buttons: [
{
label: localize({ key: 'multiLinePasteButton', comment: ['&& denotes a mnemonic'] }, "&&Paste"),
run: () => ({ confirmed: true, singleLine: false })
},
{
label: localize({ key: 'multiLinePasteButton.oneLine', comment: ['&& denotes a mnemonic'] }, "Paste as &&one line"),
run: () => ({ confirmed: true, singleLine: true })
}
],
cancelButton: true,
checkbox: {
label: localize('doNotAskAgain', "Do not ask me again")
}
});
if (confirmed && checkboxChecked) {
if (!result) {
return false;
}
if (result.confirmed && checkboxChecked) {
await configurationService.updateValue(TerminalSettingId.EnableMultiLinePasteWarning, false);
}
return confirmed;
if (result.singleLine) {
return { modifiedText: text.replaceAll(/\r?\n/, '') };
}
return result.confirmed;
}