Support a list of commands to skip handling by shell

Fixes #7269
This commit is contained in:
Daniel Imms 2016-08-08 09:08:12 -07:00
parent 7c734490c7
commit 0d6dd8627d
5 changed files with 43 additions and 9 deletions

View file

@ -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 = <IConfigurationRegistry>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
]
}
}
});

View file

@ -46,7 +46,8 @@ export interface ITerminalConfiguration {
fontLigatures: boolean,
fontSize: number,
lineHeight: number,
setLocaleVariables: boolean
setLocaleVariables: boolean,
commandsToSkipShell: string[]
}
};
}

View file

@ -169,7 +169,7 @@ export class TerminalConfigHelper {
return shell;
}
public isSetLocaleVariables() {
public isSetLocaleVariables(): boolean {
let config = this.configurationService.getConfiguration<ITerminalConfiguration>();
return config.terminal.integrated.setLocaleVariables;
}
@ -184,4 +184,9 @@ export class TerminalConfigHelper {
}
return r;
}
public getCommandsToSkipShell(): string[] {
let config = this.configurationService.getConfiguration<ITerminalConfiguration>();
return config.terminal.integrated.commandsToSkipShell;
}
}

View file

@ -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;

View file

@ -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) {