Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow modifying the recent command/dir in terminal #152988

Merged
merged 1 commit into from
Jun 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
if (!this.xterm) {
return;
}
let placeholder: string;
type Item = IQuickPickItem & { command?: ITerminalCommand };
let items: (Item | IQuickPickItem | IQuickPickSeparator)[] = [];
const commandMap: Set<string> = new Set();
Expand All @@ -820,6 +821,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
};

if (type === 'command') {
placeholder = isMacintosh ? nls.localize('selectRecentCommandMac', 'Select a command to run (hold Option-key to edit the command)') : nls.localize('selectRecentCommand', 'Select a command to run (hold Alt-key to edit the command)');
const cmdDetection = this.capabilities.get(TerminalCapability.CommandDetection);
const commands = cmdDetection?.commands;
// Current session history
Expand Down Expand Up @@ -898,6 +900,9 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
);
}
} else {
placeholder = isMacintosh
? nls.localize('selectRecentDirectoryMac', 'Select a directory to go to (hold Option-key to edit the command)')
: nls.localize('selectRecentDirectory', 'Select a directory to go to (hold Alt-key to edit the command)');
const cwds = this.capabilities.get(TerminalCapability.CwdDetection)?.cwds || [];
if (cwds && cwds.length > 0) {
for (const label of cwds) {
Expand Down Expand Up @@ -932,6 +937,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
const outputProvider = this._instantiationService.createInstance(TerminalOutputProvider);
const quickPick = this._quickInputService.createQuickPick();
quickPick.items = items;
quickPick.placeholder = placeholder;
return new Promise<void>(r => {
quickPick.onDidTriggerItemButton(async e => {
if (e.button === removeFromCommandHistoryButton) {
Expand Down Expand Up @@ -960,9 +966,9 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
}
quickPick.hide();
});
quickPick.onDidAccept(e => {
quickPick.onDidAccept(() => {
const result = quickPick.activeItems[0];
this.sendText(type === 'cwd' ? `cd ${result.label}` : result.label, true);
this.sendText(type === 'cwd' ? `cd ${result.label}` : result.label, !quickPick.keyMods.alt);
quickPick.hide();
});
quickPick.show();
Expand Down