From 0d6dd8627d7cdd72eefdb577a7419bf19a462033 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 8 Aug 2016 09:08:12 -0700 Subject: [PATCH] Support a list of commands to skip handling by shell Fixes #7269 --- .../electron-browser/terminal.contribution.ts | 15 ++++++++++++++ .../terminal/electron-browser/terminal.ts | 3 ++- .../electron-browser/terminalConfigHelper.ts | 7 ++++++- .../electron-browser/terminalInstance.ts | 20 ++++++++++++------- .../electron-browser/terminalPanel.ts | 7 +++++++ 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts b/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts index 6746c7c7688..1dc181fe90e 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts @@ -17,6 +17,9 @@ import {Registry} from 'vs/platform/platform'; import {SyncActionDescriptor} from 'vs/platform/actions/common/actions'; import {TerminalService} from 'vs/workbench/parts/terminal/electron-browser/terminalService'; import {registerSingleton} from 'vs/platform/instantiation/common/extensions'; +import {GlobalQuickOpenAction} from 'vs/workbench/browser/parts/editor/editorActions'; +import {ShowAllCommandsAction} from 'vs/workbench/parts/quickopen/browser/commandsHandler'; +import {ToggleTabFocusModeAction} from 'vs/editor/contrib/toggleTabFocusMode/common/toggleTabFocusMode'; let configurationRegistry = Registry.as(Extensions.Configuration); configurationRegistry.registerConfiguration({ @@ -84,6 +87,18 @@ configurationRegistry.registerConfiguration({ 'description': nls.localize('terminal.integrated.setLocaleVariables', "Controls whether locale variables are set at startup of the terminal, this defaults to true on OS X, false on other platforms."), 'type': 'boolean', 'default': platform.isMacintosh + }, + 'terminal.integrated.commandsToSkipShell': { + 'description': nls.localize('terminal.integrated.commandsToSkipShell', "A set of keybindings that will not be sent to the shell and instead always be handled by Code. This allows the use of keybindings that would normally be consumed by the shell to act the same as when the terminal is not focused, for example ctrl+p to launch quick open."), + 'type': 'array', + 'items': { + 'type': 'string' + }, + 'default': [ + ToggleTabFocusModeAction.ID, + GlobalQuickOpenAction.ID, + ShowAllCommandsAction.ID + ] } } }); diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminal.ts b/src/vs/workbench/parts/terminal/electron-browser/terminal.ts index 8f5a0c4d44a..96e170dde67 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminal.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminal.ts @@ -46,7 +46,8 @@ export interface ITerminalConfiguration { fontLigatures: boolean, fontSize: number, lineHeight: number, - setLocaleVariables: boolean + setLocaleVariables: boolean, + commandsToSkipShell: string[] } }; } diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalConfigHelper.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalConfigHelper.ts index 4f5cb6869c6..7c7ab80567f 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalConfigHelper.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalConfigHelper.ts @@ -169,7 +169,7 @@ export class TerminalConfigHelper { return shell; } - public isSetLocaleVariables() { + public isSetLocaleVariables(): boolean { let config = this.configurationService.getConfiguration(); return config.terminal.integrated.setLocaleVariables; } @@ -184,4 +184,9 @@ export class TerminalConfigHelper { } return r; } + + public getCommandsToSkipShell(): string[] { + let config = this.configurationService.getConfiguration(); + return config.terminal.integrated.commandsToSkipShell; + } } \ No newline at end of file diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts index 484d4feef4d..0eeba8ed2a3 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts @@ -20,20 +20,19 @@ import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace'; import {Keybinding} from 'vs/base/common/keyCodes'; import {StandardKeyboardEvent} from 'vs/base/browser/keyboardEvent'; import {TabFocus} from 'vs/editor/common/config/commonEditorConfig'; -import {ToggleTabFocusModeAction} from 'vs/editor/contrib/toggleTabFocusMode/common/toggleTabFocusMode'; export class TerminalInstance { private static eolRegex = /\r?\n/g; private isExiting: boolean = false; + private skipTerminalKeybindings: Keybinding[] = []; private toDispose: lifecycle.IDisposable[]; private xterm; private terminalDomElement: HTMLDivElement; private wrapperElement: HTMLDivElement; private font: ITerminalFont; - private skipTerminalKeybindings: Keybinding[]; public constructor( private terminalProcess: ITerminalProcess, @@ -49,11 +48,6 @@ export class TerminalInstance { ) { let self = this; this.toDispose = []; - this.skipTerminalKeybindings = [].concat( - self.keybindingService.lookupKeybindings(ToggleTabFocusModeAction.ID), - self.keybindingService.lookupKeybindings(ScrollDownTerminalAction.ID), - self.keybindingService.lookupKeybindings(ScrollUpTerminalAction.ID)); - console.log(this.skipTerminalKeybindings); this.wrapperElement = document.createElement('div'); DOM.addClass(this.wrapperElement, 'terminal-wrapper'); this.terminalDomElement = document.createElement('div'); @@ -171,6 +165,18 @@ export class TerminalInstance { } } + public setCommandsToSkipShell(commands: string[]): void { + this.skipTerminalKeybindings = commands.concat([ + // Terminal related keybindings that must pass through or they would not function + ScrollDownTerminalAction.ID, + ScrollUpTerminalAction.ID + ]).map((c) => { + return this.keybindingService.lookupKeybindings(c); + }).reduce((prev, curr) => { + return prev.concat(curr); + }); + } + public focus(force?: boolean): void { if (!this.xterm) { return; diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts index 54aa973823c..6f10d78b90f 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts @@ -297,6 +297,7 @@ export class TerminalPanel extends Panel { private updateConfig(): void { this.updateFont(); this.updateCursorBlink(); + this.updateCommandsToSkipShell(); } private updateFont(): void { @@ -331,6 +332,12 @@ export class TerminalPanel extends Panel { }); } + private updateCommandsToSkipShell(): void { + this.terminalInstances.forEach((instance) => { + instance.setCommandsToSkipShell(this.configurationHelper.getCommandsToSkipShell()); + }); + } + public focus(): void { let activeIndex = this.terminalService.getActiveTerminalIndex(); if (activeIndex !== -1 && this.terminalInstances.length > 0) {