@@ -29,7 +29,7 @@ export type IEditorContributionCtor = IConstructorSignature1<ICodeEditor, editor
2929
3030export 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
0 commit comments