Skip to content

Commit

Permalink
terminal: add toggle terminal command (#11193)
Browse files Browse the repository at this point in the history
Signed-off-by: jaimemartinagui@gmail.com
Co-authored-by: Vincent Fugnitto <vincent.fugnitto@ericsson.com>
Co-authored-by: zhaomenghuan <1028317108@qq.com>
  • Loading branch information
3 people authored Aug 5, 2022
1 parent 5318f1e commit 2a7341d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/terminal/src/browser/terminal-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ export namespace TerminalCommands {
category: TERMINAL_CATEGORY,
label: 'Scroll Down (Page)'
});
export const TOGGLE_TERMINAL = Command.toDefaultLocalizedCommand({
id: 'workbench.action.terminal.toggleTerminal',
category: TERMINAL_CATEGORY,
label: 'Toggle Terminal'
});

/**
* Command that displays all terminals that are currently opened
Expand Down Expand Up @@ -411,6 +416,37 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
(this.shell.activeWidget as TerminalWidget).scrollPageDown();
}
});
commands.registerCommand(TerminalCommands.TOGGLE_TERMINAL, {
execute: () => this.toggleTerminal()
});
}

protected toggleTerminal(): void {

const terminals = this.shell.getWidgets('bottom').filter(w => w instanceof TerminalWidget);

if (terminals.length === 0) {
this.openTerminal();
return;
}

if (this.shell.bottomPanel.isHidden) {
this.shell.bottomPanel.setHidden(false);
terminals[0].activate();
return;
}

if (this.shell.bottomPanel.isVisible) {
const visibleTerminal = terminals.find(t => t.isVisible);
if (!visibleTerminal) {
this.shell.bottomPanel.activateWidget(terminals[0]);
} else if (this.shell.activeWidget !== visibleTerminal) {
this.shell.bottomPanel.activateWidget(visibleTerminal);
} else {
this.shell.bottomPanel.setHidden(true);
}
}

}

async openInTerminal(uri: URI): Promise<void> {
Expand Down Expand Up @@ -593,6 +629,10 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
keybinding: 'shift-pageDown',
context: TerminalKeybindingContexts.terminalActive
});
keybindings.registerKeybinding({
command: TerminalCommands.TOGGLE_TERMINAL.id,
keybinding: 'ctrl+`',
});
}

async newTerminal(options: TerminalWidgetOptions): Promise<TerminalWidget> {
Expand Down

0 comments on commit 2a7341d

Please sign in to comment.