Skip to content

Commit 608c07c

Browse files
committed
Have kbOpts.weight be mandatory
1 parent 2b0800a commit 608c07c

43 files changed

Lines changed: 306 additions & 160 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/vs/editor/browser/controller/coreCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ function findFocusedEditor(accessor: ServicesAccessor): ICodeEditor {
16201620
}
16211621

16221622
function registerCommand(command: Command) {
1623-
command.register(CORE_WEIGHT);
1623+
command.register();
16241624
}
16251625

16261626
/**

src/vs/editor/browser/editorExtensions.ts

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type IEditorContributionCtor = IConstructorSignature1<ICodeEditor, editor
2929

3030
export interface ICommandKeybindingsOptions extends IKeybindings {
3131
kbExpr?: ContextKeyExpr;
32-
weight?: number;
32+
weight: number;
3333
}
3434
// export interface ICommandMenubarOptions {
3535
// group?: string;
@@ -57,36 +57,47 @@ export abstract class Command {
5757
this._description = opts.description;
5858
}
5959

60-
private _toCommandAndKeybindingRule(defaultWeight: number): ICommandAndKeybindingRule {
61-
const kbOpts = this._kbOpts || { primary: 0 };
62-
63-
let kbWhen = kbOpts.kbExpr;
64-
if (this.precondition) {
65-
if (kbWhen) {
66-
kbWhen = ContextKeyExpr.and(kbWhen, this.precondition);
67-
} else {
68-
kbWhen = this.precondition;
60+
private _toCommandAndKeybindingRule(): ICommandAndKeybindingRule {
61+
if (this._kbOpts) {
62+
let kbWhen = this._kbOpts.kbExpr;
63+
if (this.precondition) {
64+
if (kbWhen) {
65+
kbWhen = ContextKeyExpr.and(kbWhen, this.precondition);
66+
} else {
67+
kbWhen = this.precondition;
68+
}
6969
}
70-
}
7170

72-
const weight = (typeof kbOpts.weight === 'number' ? kbOpts.weight : defaultWeight);
71+
return {
72+
id: this.id,
73+
handler: (accessor, args) => this.runCommand(accessor, args),
74+
weight: this._kbOpts.weight,
75+
when: kbWhen,
76+
primary: this._kbOpts.primary,
77+
secondary: this._kbOpts.secondary,
78+
win: this._kbOpts.win,
79+
linux: this._kbOpts.linux,
80+
mac: this._kbOpts.mac,
81+
description: this._description
82+
};
83+
}
7384

7485
return {
7586
id: this.id,
7687
handler: (accessor, args) => this.runCommand(accessor, args),
77-
weight: weight,
78-
when: kbWhen,
79-
primary: kbOpts.primary,
80-
secondary: kbOpts.secondary,
81-
win: kbOpts.win,
82-
linux: kbOpts.linux,
83-
mac: kbOpts.mac,
88+
weight: undefined,
89+
when: undefined,
90+
primary: 0,
91+
secondary: undefined,
92+
win: undefined,
93+
linux: undefined,
94+
mac: undefined,
8495
description: this._description
8596
};
8697
}
8798

88-
public register(defaultWeight: number): void {
89-
KeybindingsRegistry.registerCommandAndKeybindingRule(this._toCommandAndKeybindingRule(defaultWeight));
99+
public register(): void {
100+
KeybindingsRegistry.registerCommandAndKeybindingRule(this._toCommandAndKeybindingRule());
90101
}
91102

92103
public abstract runCommand(accessor: ServicesAccessor, args: any): void | TPromise<void>;
@@ -193,14 +204,14 @@ export abstract class EditorAction extends EditorCommand {
193204
};
194205
}
195206

196-
public register(defaultWeight: number): void {
207+
public register(): void {
197208

198209
let menuItem = this._toMenuItem();
199210
if (menuItem) {
200211
MenuRegistry.appendMenuItem(MenuId.EditorContext, menuItem);
201212
}
202213

203-
super.register(defaultWeight);
214+
super.register();
204215
}
205216

206217
public runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | TPromise<void> {
@@ -316,7 +327,7 @@ class EditorContributionRegistry {
316327
}
317328

318329
public registerEditorAction(action: EditorAction) {
319-
action.register(KeybindingsRegistry.WEIGHT.editorContrib());
330+
action.register();
320331
this.editorActions.push(action);
321332
}
322333

@@ -329,7 +340,7 @@ class EditorContributionRegistry {
329340
}
330341

331342
public registerEditorCommand(editorCommand: EditorCommand) {
332-
editorCommand.register(KeybindingsRegistry.WEIGHT.editorContrib());
343+
editorCommand.register();
333344
this.editorCommands[editorCommand.id] = editorCommand;
334345
}
335346

src/vs/editor/browser/widget/diffReview.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService
3030
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
3131
import { ITextModel, TextModelResolvedOptions } from 'vs/editor/common/model';
3232
import { ViewLineRenderingData } from 'vs/editor/common/viewModel/viewModel';
33+
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
3334

3435
const DIFF_LINES_PADDING = 3;
3536

@@ -810,7 +811,8 @@ class DiffReviewNext extends EditorAction {
810811
precondition: ContextKeyExpr.has('isInDiffEditor'),
811812
kbOpts: {
812813
kbExpr: null,
813-
primary: KeyCode.F7
814+
primary: KeyCode.F7,
815+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
814816
}
815817
});
816818
}
@@ -832,7 +834,8 @@ class DiffReviewPrev extends EditorAction {
832834
precondition: ContextKeyExpr.has('isInDiffEditor'),
833835
kbOpts: {
834836
kbExpr: null,
835-
primary: KeyMod.Shift | KeyCode.F7
837+
primary: KeyMod.Shift | KeyCode.F7,
838+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
836839
}
837840
});
838841
}

src/vs/editor/contrib/bracketMatching/bracketMatching.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
2222
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
2323
import { registerColor } from 'vs/platform/theme/common/colorRegistry';
2424
import { TrackedRangeStickiness, IModelDeltaDecoration, OverviewRulerLane } from 'vs/editor/common/model';
25+
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
2526

2627
const overviewRulerBracketMatchForeground = registerColor('editorOverviewRuler.bracketMatchForeground', { dark: '#A0A0A0', light: '#A0A0A0', hc: '#A0A0A0' }, nls.localize('overviewRulerBracketMatchForeground', 'Overview ruler marker color for matching brackets.'));
2728

@@ -34,7 +35,8 @@ class JumpToBracketAction extends EditorAction {
3435
precondition: null,
3536
kbOpts: {
3637
kbExpr: EditorContextKeys.editorTextFocus,
37-
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_BACKSLASH
38+
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_BACKSLASH,
39+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
3840
}
3941
});
4042
}

src/vs/editor/contrib/caretOperations/transpose.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { registerEditorAction, EditorAction, ServicesAccessor } from 'vs/editor/
1515
import { ReplaceCommand } from 'vs/editor/common/commands/replaceCommand';
1616
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
1717
import { ITextModel } from 'vs/editor/common/model';
18+
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
1819

1920
class TransposeLettersAction extends EditorAction {
2021

@@ -67,7 +68,8 @@ class TransposeLettersAction extends EditorAction {
6768
primary: 0,
6869
mac: {
6970
primary: KeyMod.WinCtrl | KeyCode.KEY_T
70-
}
71+
},
72+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
7173
}
7274
});
7375
}

src/vs/editor/contrib/clipboard/clipboard.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { registerEditorAction, IActionOptions, EditorAction, ICommandKeybindings
1616
import { CopyOptions } from 'vs/editor/browser/controller/textAreaInput';
1717
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
1818
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
19+
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
1920

2021
const CLIPBOARD_CONTEXT_MENU_GROUP = '9_cutcopypaste';
2122

@@ -62,7 +63,8 @@ class ExecCommandCutAction extends ExecCommandAction {
6263
let kbOpts: ICommandKeybindingsOptions = {
6364
kbExpr: EditorContextKeys.textInputFocus,
6465
primary: KeyMod.CtrlCmd | KeyCode.KEY_X,
65-
win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_X, secondary: [KeyMod.Shift | KeyCode.Delete] }
66+
win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_X, secondary: [KeyMod.Shift | KeyCode.Delete] },
67+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
6668
};
6769
// Do not bind cut keybindings in the browser,
6870
// since browsers do that for us and it avoids security prompts
@@ -99,7 +101,8 @@ class ExecCommandCopyAction extends ExecCommandAction {
99101
let kbOpts: ICommandKeybindingsOptions = {
100102
kbExpr: EditorContextKeys.textInputFocus,
101103
primary: KeyMod.CtrlCmd | KeyCode.KEY_C,
102-
win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_C, secondary: [KeyMod.CtrlCmd | KeyCode.Insert] }
104+
win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_C, secondary: [KeyMod.CtrlCmd | KeyCode.Insert] },
105+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
103106
};
104107
// Do not bind copy keybindings in the browser,
105108
// since browsers do that for us and it avoids security prompts
@@ -137,7 +140,8 @@ class ExecCommandPasteAction extends ExecCommandAction {
137140
let kbOpts: ICommandKeybindingsOptions = {
138141
kbExpr: EditorContextKeys.textInputFocus,
139142
primary: KeyMod.CtrlCmd | KeyCode.KEY_V,
140-
win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_V, secondary: [KeyMod.Shift | KeyCode.Insert] }
143+
win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_V, secondary: [KeyMod.Shift | KeyCode.Insert] },
144+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
141145
};
142146
// Do not bind paste keybindings in the browser,
143147
// since browsers do that for us and it avoids security prompts
@@ -169,7 +173,8 @@ class ExecCommandCopyWithSyntaxHighlightingAction extends ExecCommandAction {
169173
precondition: null,
170174
kbOpts: {
171175
kbExpr: EditorContextKeys.textInputFocus,
172-
primary: null
176+
primary: null,
177+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
173178
}
174179
});
175180
}

src/vs/editor/contrib/codeAction/codeActionCommands.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { CodeActionModel, CodeActionsComputeEvent, SUPPORTED_CODE_ACTIONS } from
2626
import { CodeActionAutoApply, CodeActionFilter, CodeActionKind } from './codeActionTrigger';
2727
import { CodeActionContextMenu } from './codeActionWidget';
2828
import { LightBulbWidget } from './lightBulbWidget';
29+
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
2930

3031
function contextKeyForSupportedActions(kind: CodeActionKind) {
3132
return ContextKeyExpr.regex(
@@ -192,7 +193,8 @@ export class QuickFixAction extends EditorAction {
192193
precondition: ContextKeyExpr.and(EditorContextKeys.writable, EditorContextKeys.hasCodeActionsProvider),
193194
kbOpts: {
194195
kbExpr: EditorContextKeys.editorTextFocus,
195-
primary: KeyMod.CtrlCmd | KeyCode.US_DOT
196+
primary: KeyMod.CtrlCmd | KeyCode.US_DOT,
197+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
196198
}
197199
});
198200
}
@@ -272,7 +274,8 @@ export class RefactorAction extends EditorAction {
272274
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_R,
273275
mac: {
274276
primary: KeyMod.WinCtrl | KeyMod.Shift | KeyCode.KEY_R
275-
}
277+
},
278+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
276279
},
277280
menuOpts: {
278281
group: '1_modification',
@@ -335,7 +338,8 @@ export class OrganizeImportsAction extends EditorAction {
335338
contextKeyForSupportedActions(CodeActionKind.SourceOrganizeImports)),
336339
kbOpts: {
337340
kbExpr: EditorContextKeys.editorTextFocus,
338-
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_O
341+
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_O,
342+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
339343
}
340344
});
341345
}

src/vs/editor/contrib/comment/comment.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { registerEditorAction, IActionOptions, EditorAction, ServicesAccessor }
1212
import { BlockCommentCommand } from './blockCommentCommand';
1313
import { LineCommentCommand, Type } from './lineCommentCommand';
1414
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
15+
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
1516

1617
abstract class CommentLineAction extends EditorAction {
1718

@@ -52,7 +53,8 @@ class ToggleCommentLineAction extends CommentLineAction {
5253
precondition: EditorContextKeys.writable,
5354
kbOpts: {
5455
kbExpr: EditorContextKeys.editorTextFocus,
55-
primary: KeyMod.CtrlCmd | KeyCode.US_SLASH
56+
primary: KeyMod.CtrlCmd | KeyCode.US_SLASH,
57+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
5658
}
5759
});
5860
}
@@ -67,7 +69,8 @@ class AddLineCommentAction extends CommentLineAction {
6769
precondition: EditorContextKeys.writable,
6870
kbOpts: {
6971
kbExpr: EditorContextKeys.editorTextFocus,
70-
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_C)
72+
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_C),
73+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
7174
}
7275
});
7376
}
@@ -82,7 +85,8 @@ class RemoveLineCommentAction extends CommentLineAction {
8285
precondition: EditorContextKeys.writable,
8386
kbOpts: {
8487
kbExpr: EditorContextKeys.editorTextFocus,
85-
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_U)
88+
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_U),
89+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
8690
}
8791
});
8892
}
@@ -99,7 +103,8 @@ class BlockCommentAction extends EditorAction {
99103
kbOpts: {
100104
kbExpr: EditorContextKeys.editorTextFocus,
101105
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_A,
102-
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_A }
106+
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_A },
107+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
103108
}
104109
});
105110
}

src/vs/editor/contrib/contextmenu/contextmenu.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { IEditorContribution, IScrollEvent, ScrollType } from 'vs/editor/common/
2020
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
2121
import { registerEditorAction, registerEditorContribution, ServicesAccessor, EditorAction } from 'vs/editor/browser/editorExtensions';
2222
import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser';
23+
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
2324

2425
export interface IPosition {
2526
x: number;
@@ -227,7 +228,8 @@ class ShowContextMenu extends EditorAction {
227228
precondition: null,
228229
kbOpts: {
229230
kbExpr: EditorContextKeys.textInputFocus,
230-
primary: KeyMod.Shift | KeyCode.F10
231+
primary: KeyMod.Shift | KeyCode.F10,
232+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
231233
}
232234
});
233235
}

src/vs/editor/contrib/cursorUndo/cursorUndo.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Disposable } from 'vs/base/common/lifecycle';
1212
import { IEditorContribution, ScrollType } from 'vs/editor/common/editorCommon';
1313
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
1414
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
15+
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
1516

1617
class CursorState {
1718
readonly selections: Selection[];
@@ -118,7 +119,8 @@ export class CursorUndo extends EditorAction {
118119
precondition: null,
119120
kbOpts: {
120121
kbExpr: EditorContextKeys.textInputFocus,
121-
primary: KeyMod.CtrlCmd | KeyCode.KEY_U
122+
primary: KeyMod.CtrlCmd | KeyCode.KEY_U,
123+
weight: KeybindingsRegistry.WEIGHT.editorContrib()
122124
}
123125
});
124126
}

0 commit comments

Comments
 (0)