Skip to content

Commit de809ac

Browse files
authored
Merge pull request microsoft#201234 from microsoft/tyriar/200413
Allow pasting terminal text as single line
2 parents 972172b + 1080064 commit de809ac

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

src/vs/platform/dialogs/test/common/testDialogService.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export class TestDialogService implements IDialogService {
1414
readonly onWillShowDialog = Event.None;
1515
readonly onDidShowDialog = Event.None;
1616

17-
constructor(private defaultConfirmResult: IConfirmationResult | undefined = undefined) { }
17+
constructor(
18+
private defaultConfirmResult: IConfirmationResult | undefined = undefined,
19+
private defaultPromptResult: IPromptResult<any> | undefined = undefined
20+
) { }
1821

1922
private confirmResult: IConfirmationResult | undefined = undefined;
2023
setConfirmResult(result: IConfirmationResult) {
@@ -36,6 +39,9 @@ export class TestDialogService implements IDialogService {
3639
prompt<T>(prompt: IPromptWithDefaultCancel<T>): Promise<IPromptResult<T>>;
3740
prompt<T>(prompt: IPrompt<T>): Promise<IPromptResult<T>>;
3841
async prompt<T>(prompt: IPrompt<T> | IPromptWithCustomCancel<T>): Promise<IPromptResult<T> | IPromptResultWithCancel<T>> {
42+
if (this.defaultPromptResult) {
43+
return this.defaultPromptResult;
44+
}
3945
const promptButtons: IPromptBaseButton<T>[] = [...(prompt.buttons ?? [])];
4046
if (prompt.cancelButton && typeof prompt.cancelButton !== 'string' && typeof prompt.cancelButton !== 'boolean') {
4147
promptButtons.push(prompt.cancelButton);

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.replace(/\r?\n/g, '') };
103+
}
104+
105+
return result.confirmed;
87106
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ suite('TerminalClipboard', function () {
2525
configurationService = new TestConfigurationService({
2626
[TerminalSettingId.EnableMultiLinePasteWarning]: 'auto'
2727
});
28-
dialogService = new TestDialogService({ confirmed: false });
28+
dialogService = new TestDialogService(undefined, { result: { confirmed: false } });
2929

3030
instantiationService.stub(IConfigurationService, configurationService);
3131
instantiationService.stub(IDialogService, dialogService);

0 commit comments

Comments
 (0)