Skip to content

Commit 2db9790

Browse files
committed
Allow pasting terminal text as single line
Fixes microsoft#200413
1 parent a276ee6 commit 2db9790

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/vs/workbench/contrib/terminal/browser/terminalInstance.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,12 +1188,16 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
11881188
return;
11891189
}
11901190

1191-
const currentText: string = value;
1191+
let currentText = value;
11921192
const shouldPasteText = await this._scopedInstantiationService.invokeFunction(shouldPasteTerminalText, currentText, this.xterm?.raw.modes.bracketedPasteMode);
11931193
if (!shouldPasteText) {
11941194
return;
11951195
}
11961196

1197+
if (typeof shouldPasteText === 'object') {
1198+
currentText = shouldPasteText.modifiedText;
1199+
}
1200+
11971201
this.focus();
11981202
this.xterm.raw.paste(currentText);
11991203
}

src/vs/workbench/contrib/terminal/common/terminalClipboard.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
99
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
1010
import { TerminalSettingId } from 'vs/platform/terminal/common/terminal';
1111

12-
export async function shouldPasteTerminalText(accessor: ServicesAccessor, text: string, bracketedPasteMode: boolean | undefined): Promise<boolean> {
12+
export async function shouldPasteTerminalText(accessor: ServicesAccessor, text: string, bracketedPasteMode: boolean | undefined): Promise<boolean | { modifiedText: string }> {
1313
const configurationService = accessor.get(IConfigurationService);
1414
const dialogService = accessor.get(IDialogService);
1515

@@ -70,18 +70,37 @@ export async function shouldPasteTerminalText(accessor: ServicesAccessor, text:
7070
detail += `\n…`;
7171
}
7272

73-
const { confirmed, checkboxChecked } = await dialogService.confirm({
73+
const { result, checkboxChecked } = await dialogService.prompt<{ confirmed: boolean; singleLine: boolean }>({
7474
message: localize('confirmMoveTrashMessageFilesAndDirectories', "Are you sure you want to paste {0} lines of text into the terminal?", textForLines.length),
7575
detail,
76-
primaryButton: localize({ key: 'multiLinePasteButton', comment: ['&& denotes a mnemonic'] }, "&&Paste"),
76+
type: 'warning',
77+
buttons: [
78+
{
79+
label: localize({ key: 'multiLinePasteButton', comment: ['&& denotes a mnemonic'] }, "&&Paste"),
80+
run: () => ({ confirmed: true, singleLine: false })
81+
},
82+
{
83+
label: localize({ key: 'multiLinePasteButton.oneLine', comment: ['&& denotes a mnemonic'] }, "Paste as &&one line"),
84+
run: () => ({ confirmed: true, singleLine: true })
85+
}
86+
],
87+
cancelButton: true,
7788
checkbox: {
7889
label: localize('doNotAskAgain', "Do not ask me again")
7990
}
8091
});
8192

82-
if (confirmed && checkboxChecked) {
93+
if (!result) {
94+
return false;
95+
}
96+
97+
if (result.confirmed && checkboxChecked) {
8398
await configurationService.updateValue(TerminalSettingId.EnableMultiLinePasteWarning, false);
8499
}
85100

86-
return confirmed;
101+
if (result.singleLine) {
102+
return { modifiedText: text.replaceAll(/\r?\n/, '') };
103+
}
104+
105+
return result.confirmed;
87106
}

0 commit comments

Comments
 (0)