mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-22 04:02:15 +01:00
Merge pull request #201234 from microsoft/tyriar/200413
Allow pasting terminal text as single line
This commit is contained in:
@@ -14,7 +14,10 @@ export class TestDialogService implements IDialogService {
|
||||
readonly onWillShowDialog = Event.None;
|
||||
readonly onDidShowDialog = Event.None;
|
||||
|
||||
constructor(private defaultConfirmResult: IConfirmationResult | undefined = undefined) { }
|
||||
constructor(
|
||||
private defaultConfirmResult: IConfirmationResult | undefined = undefined,
|
||||
private defaultPromptResult: IPromptResult<any> | undefined = undefined
|
||||
) { }
|
||||
|
||||
private confirmResult: IConfirmationResult | undefined = undefined;
|
||||
setConfirmResult(result: IConfirmationResult) {
|
||||
@@ -36,6 +39,9 @@ export class TestDialogService implements IDialogService {
|
||||
prompt<T>(prompt: IPromptWithDefaultCancel<T>): Promise<IPromptResult<T>>;
|
||||
prompt<T>(prompt: IPrompt<T>): Promise<IPromptResult<T>>;
|
||||
async prompt<T>(prompt: IPrompt<T> | IPromptWithCustomCancel<T>): Promise<IPromptResult<T> | IPromptResultWithCancel<T>> {
|
||||
if (this.defaultPromptResult) {
|
||||
return this.defaultPromptResult;
|
||||
}
|
||||
const promptButtons: IPromptBaseButton<T>[] = [...(prompt.buttons ?? [])];
|
||||
if (prompt.cancelButton && typeof prompt.cancelButton !== 'string' && typeof prompt.cancelButton !== 'boolean') {
|
||||
promptButtons.push(prompt.cancelButton);
|
||||
|
||||
@@ -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.replace(/\r?\n/g, '') };
|
||||
}
|
||||
|
||||
return result.confirmed;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ suite('TerminalClipboard', function () {
|
||||
configurationService = new TestConfigurationService({
|
||||
[TerminalSettingId.EnableMultiLinePasteWarning]: 'auto'
|
||||
});
|
||||
dialogService = new TestDialogService({ confirmed: false });
|
||||
dialogService = new TestDialogService(undefined, { result: { confirmed: false } });
|
||||
|
||||
instantiationService.stub(IConfigurationService, configurationService);
|
||||
instantiationService.stub(IDialogService, dialogService);
|
||||
|
||||
Reference in New Issue
Block a user