提交 77df1953 编写于 作者: D Daniel Imms

Add IKeybindingService.resolve

上级 31482f68
...@@ -15,9 +15,9 @@ import { isFalsyOrEmpty } from 'vs/base/common/arrays'; ...@@ -15,9 +15,9 @@ import { isFalsyOrEmpty } from 'vs/base/common/arrays';
import * as dom from 'vs/base/browser/dom'; import * as dom from 'vs/base/browser/dom';
import { IKeyboardEvent, StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { IKeyboardEvent, StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { ICommandService, CommandsRegistry, ICommandHandlerDescription } from 'vs/platform/commands/common/commands'; import { ICommandService, CommandsRegistry, ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver'; import { KeybindingResolver, IResolveResult } from 'vs/platform/keybinding/common/keybindingResolver';
import { IKeybindingItem, IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IKeybindingItem, IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IContextKeyService, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar'; import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
import { IMessageService } from 'vs/platform/message/common/message'; import { IMessageService } from 'vs/platform/message/common/message';
...@@ -142,18 +142,26 @@ export abstract class KeybindingService implements IKeybindingService { ...@@ -142,18 +142,26 @@ export abstract class KeybindingService implements IKeybindingService {
return '// ' + nls.localize('unboundCommands', "Here are other available commands: ") + '\n// - ' + pretty; return '// ' + nls.localize('unboundCommands', "Here are other available commands: ") + '\n// - ' + pretty;
} }
protected _dispatch(e: IKeyboardEvent): void { public resolve(keybinding: Keybinding, target: IContextKeyServiceTarget): IResolveResult {
let isModifierKey = (e.keyCode === KeyCode.Ctrl || e.keyCode === KeyCode.Shift || e.keyCode === KeyCode.Alt || e.keyCode === KeyCode.Meta); const keyCode = keybinding.extractKeyCode();
let isModifierKey = (keyCode === KeyCode.Ctrl || keyCode === KeyCode.Shift || keyCode === KeyCode.Alt || keyCode === KeyCode.Meta);
if (isModifierKey) { if (isModifierKey) {
return; return null;
} }
let contextValue = this._contextKeyService.getContextValue(e.target); let contextValue = this._contextKeyService.getContextValue(target);
// console.log(JSON.stringify(contextValue, null, '\t'));
return this._getResolver().resolve(contextValue, this._currentChord, keybinding.value);
}
protected _dispatch(e: IKeyboardEvent): void {
const resolveResult = this.resolve(new Keybinding(e.asKeybinding()), e.target);
let resolveResult = this._getResolver().resolve(contextValue, this._currentChord, e.asKeybinding()); if (!resolveResult) {
return;
}
if (resolveResult && resolveResult.enterChord) { if (resolveResult.enterChord) {
e.preventDefault(); e.preventDefault();
this._currentChord = resolveResult.enterChord; this._currentChord = resolveResult.enterChord;
if (this._statusService) { if (this._statusService) {
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
import { IHTMLContentElement } from 'vs/base/common/htmlContent'; import { IHTMLContentElement } from 'vs/base/common/htmlContent';
import { Keybinding } from 'vs/base/common/keybinding'; import { Keybinding } from 'vs/base/common/keybinding';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { ContextKeyExpr, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey';
import { IResolveResult } from 'vs/platform/keybinding/common/keybindingResolver';
import Event from 'vs/base/common/event'; import Event from 'vs/base/common/event';
export interface IUserFriendlyKeybinding { export interface IUserFriendlyKeybinding {
...@@ -58,5 +59,6 @@ export interface IKeybindingService { ...@@ -58,5 +59,6 @@ export interface IKeybindingService {
getDefaultKeybindings(): string; getDefaultKeybindings(): string;
lookupKeybindings(commandId: string): Keybinding[]; lookupKeybindings(commandId: string): Keybinding[];
customKeybindingsCount(): number; customKeybindingsCount(): number;
resolve(keybinding: Keybinding, target: IContextKeyServiceTarget): IResolveResult;
} }
...@@ -8,7 +8,8 @@ import { IHTMLContentElement } from 'vs/base/common/htmlContent'; ...@@ -8,7 +8,8 @@ import { IHTMLContentElement } from 'vs/base/common/htmlContent';
import { Keybinding } from 'vs/base/common/keybinding'; import { Keybinding } from 'vs/base/common/keybinding';
import Event from 'vs/base/common/event'; import Event from 'vs/base/common/event';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextKey, IContextKeyService, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { IContextKey, IContextKeyService, IContextKeyServiceTarget, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { IResolveResult } from 'vs/platform/keybinding/common/keybindingResolver';
class MockKeybindingContextKey<T> implements IContextKey<T> { class MockKeybindingContextKey<T> implements IContextKey<T> {
private _key: string; private _key: string;
...@@ -93,4 +94,8 @@ export class MockKeybindingService2 implements IKeybindingService { ...@@ -93,4 +94,8 @@ export class MockKeybindingService2 implements IKeybindingService {
public customKeybindingsCount(): number { public customKeybindingsCount(): number {
return 0; return 0;
} }
public resolve(keybinding: Keybinding, target: IContextKeyServiceTarget): IResolveResult {
return null;
}
} }
...@@ -9,7 +9,6 @@ import 'vs/css!./media/xterm'; ...@@ -9,7 +9,6 @@ import 'vs/css!./media/xterm';
import * as panel from 'vs/workbench/browser/panel'; import * as panel from 'vs/workbench/browser/panel';
import * as platform from 'vs/base/common/platform'; import * as platform from 'vs/base/common/platform';
import nls = require('vs/nls'); import nls = require('vs/nls');
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry'; import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { GlobalQuickOpenAction } from 'vs/workbench/browser/parts/quickopen/quickopen.contribution'; import { GlobalQuickOpenAction } from 'vs/workbench/browser/parts/quickopen/quickopen.contribution';
import { ITerminalService, KEYBINDING_CONTEXT_TERMINAL_FOCUS, KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED, TERMINAL_PANEL_ID, TERMINAL_DEFAULT_SHELL_LINUX, TERMINAL_DEFAULT_SHELL_OSX, TERMINAL_DEFAULT_SHELL_WINDOWS } from 'vs/workbench/parts/terminal/common/terminal'; import { ITerminalService, KEYBINDING_CONTEXT_TERMINAL_FOCUS, KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED, TERMINAL_PANEL_ID, TERMINAL_DEFAULT_SHELL_LINUX, TERMINAL_DEFAULT_SHELL_OSX, TERMINAL_DEFAULT_SHELL_WINDOWS } from 'vs/workbench/parts/terminal/common/terminal';
...@@ -157,10 +156,10 @@ let actionRegistry = <IWorkbenchActionRegistry>Registry.as(ActionExtensions.Work ...@@ -157,10 +156,10 @@ let actionRegistry = <IWorkbenchActionRegistry>Registry.as(ActionExtensions.Work
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(KillTerminalAction, KillTerminalAction.ID, KillTerminalAction.LABEL), 'Terminal: Kill the Active Terminal Instance', category); actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(KillTerminalAction, KillTerminalAction.ID, KillTerminalAction.LABEL), 'Terminal: Kill the Active Terminal Instance', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(CopyTerminalSelectionAction, CopyTerminalSelectionAction.ID, CopyTerminalSelectionAction.LABEL, { actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(CopyTerminalSelectionAction, CopyTerminalSelectionAction.ID, CopyTerminalSelectionAction.LABEL, {
primary: KeyMod.CtrlCmd | KeyCode.KEY_C, primary: KeyMod.CtrlCmd | KeyCode.KEY_C,
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_C }, //linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_C },
// Don't apply to Mac since cmd+c works // Don't apply to Mac since cmd+c works
mac: { primary: null } mac: { primary: null }
}, ContextKeyExpr.and(KEYBINDING_CONTEXT_TERMINAL_FOCUS, KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED)), 'Terminal: Copy Selection', category); }, KEYBINDING_CONTEXT_TERMINAL_TEXT_SELECTED), 'Terminal: Copy Selection', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(CreateNewTerminalAction, CreateNewTerminalAction.ID, CreateNewTerminalAction.LABEL, { actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(CreateNewTerminalAction, CreateNewTerminalAction.ID, CreateNewTerminalAction.LABEL, {
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_BACKTICK, primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_BACKTICK,
mac: { primary: KeyMod.WinCtrl | KeyMod.Shift | KeyCode.US_BACKTICK } mac: { primary: KeyMod.WinCtrl | KeyMod.Shift | KeyCode.US_BACKTICK }
......
...@@ -41,7 +41,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -41,7 +41,7 @@ export class TerminalInstance implements ITerminalInstance {
private _onTitleChanged: Emitter<string>; private _onTitleChanged: Emitter<string>;
private _process: cp.ChildProcess; private _process: cp.ChildProcess;
private _processId: number; private _processId: number;
private _skipTerminalKeybindings: Keybinding[]; private _skipTerminalCommands: string[];
private _title: string; private _title: string;
private _toDispose: lifecycle.IDisposable[]; private _toDispose: lifecycle.IDisposable[];
private _wrapperElement: HTMLDivElement; private _wrapperElement: HTMLDivElement;
...@@ -68,7 +68,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -68,7 +68,7 @@ export class TerminalInstance implements ITerminalInstance {
@IMessageService private _messageService: IMessageService @IMessageService private _messageService: IMessageService
) { ) {
this._toDispose = []; this._toDispose = [];
this._skipTerminalKeybindings = []; this._skipTerminalCommands = [];
this._isExiting = false; this._isExiting = false;
this._isLaunching = true; this._isLaunching = true;
this._isVisible = false; this._isVisible = false;
...@@ -119,15 +119,11 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -119,15 +119,11 @@ export class TerminalInstance implements ITerminalInstance {
return false; return false;
}); });
this._xterm.attachCustomKeydownHandler((event: KeyboardEvent) => { this._xterm.attachCustomKeydownHandler((event: KeyboardEvent) => {
// Allow the toggle tab mode keybinding to pass through the terminal so that focus can // Skip processing by xterm.js of commands within commandsToSkipShell
// be escaped const standardKeyboardEvent = new StandardKeyboardEvent(event);
let standardKeyboardEvent = new StandardKeyboardEvent(event); const keybinding = new Keybinding(standardKeyboardEvent.asKeybinding());
const resolveResult = this._keybindingService.resolve(keybinding, standardKeyboardEvent.target);
// TODO: Use this._contextKeyService.contextMatchesRules(rules); to check the context as if (resolveResult && this._skipTerminalCommands.some(k => k === resolveResult.commandId)) {
// well to ensure that only commands that are relevant given the context are skipped
// (eg. ctrl+c to copy when text selected or kill the process (don't skip) when not)
if (this._skipTerminalKeybindings.some(k => standardKeyboardEvent.equals(k.value))) {
event.preventDefault(); event.preventDefault();
return false; return false;
} }
...@@ -369,11 +365,7 @@ export class TerminalInstance implements ITerminalInstance { ...@@ -369,11 +365,7 @@ export class TerminalInstance implements ITerminalInstance {
} }
public setCommandsToSkipShell(commands: string[]): void { public setCommandsToSkipShell(commands: string[]): void {
this._skipTerminalKeybindings = commands.map((c) => { this._skipTerminalCommands = commands;
return this._keybindingService.lookupKeybindings(c);
}).reduce((prev, curr) => {
return prev.concat(curr);
}, []);
} }
public setScrollback(lineCount: number): void { public setScrollback(lineCount: number): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册