提交 d185dd6d 编写于 作者: A Alex Dima

Share common KbExpr instances

上级 06ea27bf
......@@ -16,6 +16,7 @@ import {ICommandHandler} from 'vs/platform/commands/common/commands';
const H = editorCommon.Handler;
const D = editorCommon.CommandDescription;
const EditorKbExpr = editorCommon.EditorKbExpr;
export function findFocusedEditor(commandId: string, accessor: ServicesAccessor, complain: boolean): editorCommon.ICommonCodeEditor {
let editor = accessor.get(ICodeEditorService).getFocusedCodeEditor();
......@@ -62,7 +63,7 @@ function registerCoreCommand(handlerId: string, kb: IKeybindings, weight?: numbe
id: handlerId,
handler: triggerEditorHandler.bind(null, handlerId),
weight: weight ? weight : KeybindingsRegistry.WEIGHT.editorCore(),
when: (when ? when : KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS)),
when: (when ? when : EditorKbExpr.TextFocus),
primary: kb.primary,
secondary: kb.secondary,
win: kb.win,
......@@ -281,14 +282,14 @@ registerCoreCommand(H.CursorColumnSelectPageDown, {
registerCoreCommand(H.Tab, {
primary: KeyCode.Tab
}, KeybindingsRegistry.WEIGHT.editorCore(), KbExpr.and(
KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS),
KbExpr.not(editorCommon.KEYBINDING_CONTEXT_EDITOR_TAB_MOVES_FOCUS)
EditorKbExpr.TextFocus,
EditorKbExpr.TabDoesNotMoveFocus
));
registerCoreCommand(H.Outdent, {
primary: KeyMod.Shift | KeyCode.Tab
}, KeybindingsRegistry.WEIGHT.editorCore(), KbExpr.and(
KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS),
KbExpr.not(editorCommon.KEYBINDING_CONTEXT_EDITOR_TAB_MOVES_FOCUS)
EditorKbExpr.TextFocus,
EditorKbExpr.TabDoesNotMoveFocus
));
registerCoreCommand(H.DeleteLeft, {
......@@ -343,15 +344,15 @@ registerCoreCommand(H.CancelSelection, {
primary: KeyCode.Escape,
secondary: [KeyMod.Shift | KeyCode.Escape]
}, KeybindingsRegistry.WEIGHT.editorCore(), KbExpr.and(
KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS),
KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION)
EditorKbExpr.TextFocus,
EditorKbExpr.HasNonEmptySelection
));
registerCoreCommand(H.RemoveSecondaryCursors, {
primary: KeyCode.Escape,
secondary: [KeyMod.Shift | KeyCode.Escape]
}, KeybindingsRegistry.WEIGHT.editorCore(1), KbExpr.and(
KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS),
KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_HAS_MULTIPLE_SELECTIONS)
EditorKbExpr.TextFocus,
EditorKbExpr.HasMultipleSelections
));
registerCoreCommand(H.CursorTop, {
......@@ -418,6 +419,6 @@ KeybindingsRegistry.registerCommandDesc({
id: 'editor.action.selectAll',
handler: selectAll,
weight: KeybindingsRegistry.WEIGHT.editorCore(),
when: KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS),
when: EditorKbExpr.TextFocus,
primary: KeyMod.CtrlCmd | KeyCode.KEY_A
});
......@@ -19,6 +19,8 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import {IModelService} from 'vs/editor/common/services/modelService';
import {MenuId, MenuRegistry} from 'vs/platform/actions/common/actions';
const EditorKbExpr = editorCommon.EditorKbExpr;
export type ServicesAccessor = ServicesAccessor;
// --- Keybinding extensions to make it more concise to express keybindings conditions
......@@ -205,7 +207,7 @@ function triggerEditorActionGlobal(actionId: string, accessor: ServicesAccessor,
function whenRule(needsTextFocus: boolean, needsKey: string): KbExpr {
let base = KbExpr.has(needsTextFocus ? editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS : editorCommon.KEYBINDING_CONTEXT_EDITOR_FOCUS);
let base = (needsTextFocus ? EditorKbExpr.TextFocus : EditorKbExpr.Focus);
if (needsKey) {
return KbExpr.and(base, KbExpr.has(needsKey));
......
......@@ -7,7 +7,7 @@
import * as nls from 'vs/nls';
import {KeyCode, KeyMod} from 'vs/base/common/keyCodes';
import {Disposable} from 'vs/base/common/lifecycle';
import {IKeybindingContextKey, IKeybindingService, IKeybindings, KbExpr} from 'vs/platform/keybinding/common/keybinding';
import {IKeybindingContextKey, IKeybindingService, IKeybindings} from 'vs/platform/keybinding/common/keybinding';
import {Range} from 'vs/editor/common/core/range';
import {Selection} from 'vs/editor/common/core/selection';
import * as strings from 'vs/base/common/strings';
......@@ -18,6 +18,8 @@ import {FindReplaceState, FindReplaceStateChangedEvent, INewFindReplaceState} fr
import {DocumentHighlightProviderRegistry} from 'vs/editor/common/modes';
import {RunOnceScheduler} from 'vs/base/common/async';
const EditorKbExpr = editorCommon.EditorKbExpr;
export enum FindStartFocusAction {
NoFocusChange,
FocusFindInput,
......@@ -694,7 +696,7 @@ export class CompatChangeAll extends AbstractSelectHighlightsAction {
this.menuOpts = {
group: '1_modification',
order: 1.2,
kbExpr: KbExpr.not(editorCommon.KEYBINDING_CONTEXT_EDITOR_READONLY)
kbExpr: EditorKbExpr.Writable
};
}
}
......
......@@ -8,7 +8,7 @@ import * as nls from 'vs/nls';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { dispose } from 'vs/base/common/lifecycle';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ICommonCodeEditor, IEditorContribution, KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS, EditorKbExpr } from 'vs/editor/common/editorCommon';
import { ICommonCodeEditor, IEditorContribution, EditorKbExpr } from 'vs/editor/common/editorCommon';
import { KbExpr } from 'vs/platform/keybinding/common/keybinding';
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { withCodeEditorFromCommandHandler } from 'vs/editor/common/config/config';
......@@ -104,7 +104,7 @@ KeybindingsRegistry.registerCommandDesc({
id: 'closeParameterHints',
handler: handler('closeParameterHints', c => c.cancel()),
weight,
when: KbExpr.and(KbExpr.has(KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS), KbExpr.has(Context.Visible)),
when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(Context.Visible)),
primary: KeyCode.Escape,
secondary: [KeyMod.Shift | KeyCode.Escape]
});
......@@ -113,7 +113,7 @@ KeybindingsRegistry.registerCommandDesc({
id: 'showPrevParameterHint',
handler: handler('showPrevParameterHint', c => c.previous()),
weight,
when: KbExpr.and(KbExpr.has(KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS), KbExpr.has(Context.Visible), KbExpr.has(Context.MultipleSignatures)),
when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(Context.Visible), KbExpr.has(Context.MultipleSignatures)),
primary: KeyCode.UpArrow,
secondary: [KeyMod.Alt | KeyCode.UpArrow],
mac: { primary: KeyCode.UpArrow, secondary: [KeyMod.Alt | KeyCode.UpArrow, KeyMod.WinCtrl | KeyCode.KEY_P] }
......@@ -123,7 +123,7 @@ KeybindingsRegistry.registerCommandDesc({
id: 'showNextParameterHint',
handler: handler('showNextParameterHint', c => c.next()),
weight,
when: KbExpr.and(KbExpr.has(KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS), KbExpr.has(Context.Visible), KbExpr.has(Context.MultipleSignatures)),
when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(Context.Visible), KbExpr.has(Context.MultipleSignatures)),
primary: KeyCode.DownArrow,
secondary: [KeyMod.Alt | KeyCode.DownArrow],
mac: { primary: KeyCode.DownArrow, secondary: [KeyMod.Alt | KeyCode.DownArrow, KeyMod.WinCtrl | KeyCode.KEY_N] }
......
......@@ -15,10 +15,9 @@ import {IEventService} from 'vs/platform/event/common/event';
import {IKeybindingContextKey, IKeybindingService, KbExpr} from 'vs/platform/keybinding/common/keybinding';
import {IMessageService} from 'vs/platform/message/common/message';
import {IProgressService} from 'vs/platform/progress/common/progress';
import {IRange, ICommonCodeEditor, EditorKbExpr} from 'vs/editor/common/editorCommon';
import {ServicesAccessor, EditorAction, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
import {EditorBrowserRegistry} from 'vs/editor/browser/editorBrowserExtensions';
import {KEYBINDING_CONTEXT_EDITOR_READONLY, ModeContextKeys, IEditorContribution} from 'vs/editor/common/editorCommon';
import {IRange, ICommonCodeEditor, EditorKbExpr, ModeContextKeys, IEditorContribution} from 'vs/editor/common/editorCommon';
import {BulkEdit, createBulkEdit} from 'vs/editor/common/services/bulkEdit';
import {RenameProviderRegistry} from 'vs/editor/common/modes';
import {ICodeEditor} from 'vs/editor/browser/editorBrowser';
......@@ -165,7 +164,7 @@ export class RenameAction extends EditorAction {
this.menuOpts = {
group: '1_modification',
order: 1.1,
kbExpr: KbExpr.and(KbExpr.has(ModeContextKeys.hasRenameProvider), KbExpr.not(KEYBINDING_CONTEXT_EDITOR_READONLY))
kbExpr: KbExpr.and(KbExpr.has(ModeContextKeys.hasRenameProvider), EditorKbExpr.Writable)
};
}
......
......@@ -9,7 +9,7 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { KbExpr } from 'vs/platform/keybinding/common/keybinding';
import { ICommonCodeEditor, IEditorContribution, EditorKbExpr, KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS } from 'vs/editor/common/editorCommon';
import { ICommonCodeEditor, IEditorContribution, EditorKbExpr } from 'vs/editor/common/editorCommon';
import { ServicesAccessor, EditorAction, CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
import { ISuggestSupport, SuggestRegistry } from 'vs/editor/common/modes';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
......@@ -214,7 +214,7 @@ KeybindingsRegistry.registerCommandDesc({
id: 'acceptSelectedSuggestion',
handler: handler('acceptSelectedSuggestion', c => c.acceptSelectedSuggestion()),
weight,
when: KbExpr.and(KbExpr.has(KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS), KbExpr.has(SuggestContext.Visible)),
when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible)),
primary: KeyCode.Tab
});
......@@ -222,7 +222,7 @@ KeybindingsRegistry.registerCommandDesc({
id: 'acceptSelectedSuggestionOnEnter',
handler: handler('acceptSelectedSuggestionOnEnter', c => c.acceptSelectedSuggestion()),
weight,
when: KbExpr.and(KbExpr.has(KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS), KbExpr.has(SuggestContext.Visible), KbExpr.has('config.editor.acceptSuggestionOnEnter')),
when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible), KbExpr.has('config.editor.acceptSuggestionOnEnter')),
primary: KeyCode.Enter
});
......@@ -230,7 +230,7 @@ KeybindingsRegistry.registerCommandDesc({
id: 'hideSuggestWidget',
handler: handler('hideSuggestWidget', c => c.cancelSuggestWidget()),
weight,
when: KbExpr.and(KbExpr.has(KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS), KbExpr.has(SuggestContext.Visible)),
when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible)),
primary: KeyCode.Escape,
secondary: [KeyMod.Shift | KeyCode.Escape]
});
......@@ -239,7 +239,7 @@ KeybindingsRegistry.registerCommandDesc({
id: 'selectNextSuggestion',
handler: handler('selectNextSuggestion', c => c.selectNextSuggestion()),
weight,
when: KbExpr.and(KbExpr.has(KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS), KbExpr.has(SuggestContext.Visible), KbExpr.has(SuggestContext.MultipleSuggestions)),
when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible), KbExpr.has(SuggestContext.MultipleSuggestions)),
primary: KeyCode.DownArrow,
secondary: [KeyMod.Alt | KeyCode.DownArrow],
mac: { primary: KeyCode.DownArrow, secondary: [KeyMod.Alt | KeyCode.DownArrow, KeyMod.WinCtrl | KeyCode.KEY_N] }
......@@ -249,7 +249,7 @@ KeybindingsRegistry.registerCommandDesc({
id: 'selectNextPageSuggestion',
handler: handler('selectNextPageSuggestion', c => c.selectNextPageSuggestion()),
weight,
when: KbExpr.and(KbExpr.has(KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS), KbExpr.has(SuggestContext.Visible), KbExpr.has(SuggestContext.MultipleSuggestions)),
when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible), KbExpr.has(SuggestContext.MultipleSuggestions)),
primary: KeyCode.PageDown,
secondary: [KeyMod.Alt | KeyCode.PageDown]
});
......@@ -258,7 +258,7 @@ KeybindingsRegistry.registerCommandDesc({
id: 'selectPrevSuggestion',
handler: handler('selectPrevSuggestion', c => c.selectPrevSuggestion()),
weight,
when: KbExpr.and(KbExpr.has(KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS), KbExpr.has(SuggestContext.Visible), KbExpr.has(SuggestContext.MultipleSuggestions)),
when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible), KbExpr.has(SuggestContext.MultipleSuggestions)),
primary: KeyCode.UpArrow,
secondary: [KeyMod.Alt | KeyCode.UpArrow],
mac: { primary: KeyCode.UpArrow, secondary: [KeyMod.Alt | KeyCode.UpArrow, KeyMod.WinCtrl | KeyCode.KEY_P] }
......@@ -268,7 +268,7 @@ KeybindingsRegistry.registerCommandDesc({
id: 'selectPrevPageSuggestion',
handler: handler('selectPrevPageSuggestion', c => c.selectPrevPageSuggestion()),
weight,
when: KbExpr.and(KbExpr.has(KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS), KbExpr.has(SuggestContext.Visible), KbExpr.has(SuggestContext.MultipleSuggestions)),
when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible), KbExpr.has(SuggestContext.MultipleSuggestions)),
primary: KeyCode.PageUp,
secondary: [KeyMod.Alt | KeyCode.PageUp]
});
......@@ -277,7 +277,7 @@ KeybindingsRegistry.registerCommandDesc({
id: 'toggleSuggestionDetails',
handler: handler('toggleSuggestionDetails', c => c.toggleSuggestionDetails()),
weight,
when: KbExpr.and(KbExpr.has(KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS), KbExpr.has(SuggestContext.Visible)),
when: KbExpr.and(EditorKbExpr.TextFocus, KbExpr.has(SuggestContext.Visible)),
primary: KeyMod.CtrlCmd | KeyCode.Space,
mac: { primary: KeyMod.WinCtrl | KeyCode.Space }
});
......
......@@ -12,13 +12,15 @@ import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegi
import {ISnippetsRegistry, Extensions, getNonWhitespacePrefix, ISnippet} from 'vs/editor/common/modes/snippetsRegistry';
import {Registry} from 'vs/platform/platform';
import {IDisposable} from 'vs/base/common/lifecycle';
import * as editor from 'vs/editor/common/editorCommon';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
import {CodeSnippet, ISnippetController, getSnippetController} from 'vs/editor/contrib/snippet/common/snippet';
const EditorKbExpr = editorCommon.EditorKbExpr;
let snippetsRegistry = <ISnippetsRegistry>Registry.as(Extensions.Snippets);
class TabCompletionController implements editor.IEditorContribution {
class TabCompletionController implements editorCommon.IEditorContribution {
static Id = 'editor.tabCompletionController';
static ContextKey = 'hasSnippetCompletions';
......@@ -28,7 +30,7 @@ class TabCompletionController implements editor.IEditorContribution {
private _currentSnippets: ISnippet[] = [];
constructor(
editor: editor.ICommonCodeEditor,
editor: editorCommon.ICommonCodeEditor,
@IKeybindingService keybindingService: IKeybindingService
) {
this._snippetController = getSnippetController(editor);
......@@ -79,8 +81,8 @@ KeybindingsRegistry.registerCommandDesc({
weight: KeybindingsRegistry.WEIGHT.editorContrib(),
primary: KeyCode.Tab,
when: KbExpr.and(KbExpr.has(TabCompletionController.ContextKey),
KbExpr.has(editor.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS),
KbExpr.not(editor.KEYBINDING_CONTEXT_EDITOR_TAB_MOVES_FOCUS),
EditorKbExpr.TextFocus,
EditorKbExpr.TabDoesNotMoveFocus,
KbExpr.has('config.editor.tabCompletion')),
handler(accessor) {
const editor = accessor.get(ICodeEditorService).getFocusedCodeEditor();
......
......@@ -12,9 +12,10 @@ import { IEditorGroupService } from 'vs/workbench/services/group/common/groupSer
import { IWorkbenchEditorConfiguration, ActiveEditorMoveArguments, ActiveEditorMovePositioning, ActiveEditorMovePositioningBy, EditorCommands } from 'vs/workbench/common/editor';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { KbExpr } from 'vs/platform/keybinding/common/keybinding';
import { IEditor, Position, POSITIONS } from 'vs/platform/editor/common/editor';
const EditorKbExpr = editorCommon.EditorKbExpr;
export function registerEditorComamnds() {
_registerActiveEditorMoveCommand();
}
......@@ -46,7 +47,7 @@ function _registerActiveEditorMoveCommand() {
KeybindingsRegistry.registerCommandDesc({
id: EditorCommands.MoveActiveEditor,
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS),
when: EditorKbExpr.TextFocus,
primary: null,
handler: (accessor, args: any) => _moveActiveEditor(args, accessor),
description: {
......
......@@ -22,6 +22,8 @@ import {ServicesAccessor, EditorAction} from 'vs/editor/common/editorCommonExten
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';
import IDebugService = debug.IDebugService;
const EditorKbExpr = editorCommon.EditorKbExpr;
export class AbstractDebugAction extends actions.Action {
protected toDispose: lifecycle.IDisposable[];
......@@ -671,7 +673,7 @@ export class SelectionToReplAction extends EditorAction {
);
this.menuOpts = {
kbExpr: KbExpr.and(KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_HAS_NON_EMPTY_SELECTION), KbExpr.has(debug.CONTEXT_IN_DEBUG_MODE)),
kbExpr: KbExpr.and(EditorKbExpr.HasNonEmptySelection, KbExpr.has(debug.CONTEXT_IN_DEBUG_MODE)),
group: 'debug'
};
}
......@@ -709,7 +711,7 @@ export class ShowDebugHoverAction extends EditorAction {
);
this.kbOpts = {
kbExpr: KbExpr.and(KbExpr.has(debug.CONTEXT_IN_DEBUG_MODE), KbExpr.has(editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS)),
kbExpr: KbExpr.and(KbExpr.has(debug.CONTEXT_IN_DEBUG_MODE), EditorKbExpr.TextFocus),
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_I)
};
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册