@@ -87,80 +87,43 @@ export class NativeResolvedKeybinding extends ResolvedKeybinding {
8787 this . _chordPart = chordPart ;
8888 }
8989
90- private _getUILabelForScanCodeBinding ( binding : ScanCodeBinding ) : string {
91- if ( ! binding ) {
92- return null ;
93- }
94- if ( binding . isDuplicateModifierCase ( ) ) {
95- return '' ;
96- }
97- return this . _mapper . getUILabelForScanCode ( binding . scanCode ) ;
98- }
99-
10090 public getLabel ( ) : string {
101- let firstPart = this . _getUILabelForScanCodeBinding ( this . _firstPart ) ;
102- let chordPart = this . _getUILabelForScanCodeBinding ( this . _chordPart ) ;
91+ let firstPart = this . _mapper . getUILabelForScanCodeBinding ( this . _firstPart ) ;
92+ let chordPart = this . _mapper . getUILabelForScanCodeBinding ( this . _chordPart ) ;
10393 return UILabelProvider . toLabel ( this . _firstPart , firstPart , this . _chordPart , chordPart , this . _OS ) ;
10494 }
10595
106- private _getAriaLabelForScanCodeBinding ( binding : ScanCodeBinding ) : string {
107- if ( ! binding ) {
108- return null ;
109- }
110- if ( binding . isDuplicateModifierCase ( ) ) {
111- return '' ;
112- }
113- return this . _mapper . getAriaLabelForScanCode ( binding . scanCode ) ;
114- }
115-
11696 public getAriaLabel ( ) : string {
117- let firstPart = this . _getAriaLabelForScanCodeBinding ( this . _firstPart ) ;
118- let chordPart = this . _getAriaLabelForScanCodeBinding ( this . _chordPart ) ;
97+ let firstPart = this . _mapper . getAriaLabelForScanCodeBinding ( this . _firstPart ) ;
98+ let chordPart = this . _mapper . getAriaLabelForScanCodeBinding ( this . _chordPart ) ;
11999 return AriaLabelProvider . toLabel ( this . _firstPart , firstPart , this . _chordPart , chordPart , this . _OS ) ;
120100 }
121101
122- private _getElectronAcceleratorLabelForScanCodeBinding ( binding : ScanCodeBinding ) : string {
123- if ( ! binding ) {
124- return null ;
125- }
126- if ( binding . isDuplicateModifierCase ( ) ) {
127- return null ;
128- }
129- return this . _mapper . getElectronLabelForScanCode ( binding . scanCode ) ;
130- }
131-
132102 public getElectronAccelerator ( ) : string {
133103 if ( this . _chordPart !== null ) {
134104 // Electron cannot handle chords
135105 return null ;
136106 }
137107
138- let firstPart = this . _getElectronAcceleratorLabelForScanCodeBinding ( this . _firstPart ) ;
108+ let firstPart = this . _mapper . getElectronAcceleratorLabelForScanCodeBinding ( this . _firstPart ) ;
139109 return ElectronAcceleratorLabelProvider . toLabel ( this . _firstPart , firstPart , null , null , this . _OS ) ;
140110 }
141111
142- private _getUserSettingsLabelForScanCodeBinding ( binding : ScanCodeBinding ) : string {
143- if ( ! binding ) {
144- return null ;
145- }
146- if ( binding . isDuplicateModifierCase ( ) ) {
147- return '' ;
148- }
149- return this . _mapper . getUserSettingsLabel ( binding . scanCode ) ;
150- }
151-
152112 public getUserSettingsLabel ( ) : string {
153- let firstPart = this . _getUserSettingsLabelForScanCodeBinding ( this . _firstPart ) ;
154- let chordPart = this . _getUserSettingsLabelForScanCodeBinding ( this . _chordPart ) ;
113+ let firstPart = this . _mapper . getUserSettingsLabelForScanCodeBinding ( this . _firstPart ) ;
114+ let chordPart = this . _mapper . getUserSettingsLabelForScanCodeBinding ( this . _chordPart ) ;
155115 return UserSettingsLabelProvider . toLabel ( this . _firstPart , firstPart , this . _chordPart , chordPart , this . _OS ) ;
156116 }
157117
158- private _isWYSIWYG ( scanCode : ScanCode ) : boolean {
159- if ( IMMUTABLE_CODE_TO_KEY_CODE [ scanCode ] !== - 1 ) {
118+ private _isWYSIWYG ( binding : ScanCodeBinding ) : boolean {
119+ if ( ! binding ) {
160120 return true ;
161121 }
162- let a = this . _mapper . getAriaLabelForScanCode ( scanCode ) ;
163- let b = this . _mapper . getUserSettingsLabel ( scanCode ) ;
122+ if ( IMMUTABLE_CODE_TO_KEY_CODE [ binding . scanCode ] !== - 1 ) {
123+ return true ;
124+ }
125+ let a = this . _mapper . getAriaLabelForScanCodeBinding ( binding ) ;
126+ let b = this . _mapper . getUserSettingsLabelForScanCodeBinding ( binding ) ;
164127
165128 if ( ! a && ! b ) {
166129 return true ;
@@ -172,10 +135,7 @@ export class NativeResolvedKeybinding extends ResolvedKeybinding {
172135 }
173136
174137 public isWYSIWYG ( ) : boolean {
175- let result = true ;
176- result = result && ( this . _firstPart ? this . _isWYSIWYG ( this . _firstPart . scanCode ) : true ) ;
177- result = result && ( this . _chordPart ? this . _isWYSIWYG ( this . _chordPart . scanCode ) : true ) ;
178- return result ;
138+ return ( this . _isWYSIWYG ( this . _firstPart ) && this . _isWYSIWYG ( this . _chordPart ) ) ;
179139 }
180140
181141 public isChord ( ) : boolean {
@@ -199,8 +159,8 @@ export class NativeResolvedKeybinding extends ResolvedKeybinding {
199159 binding . shiftKey ,
200160 binding . altKey ,
201161 binding . metaKey ,
202- this . _getUILabelForScanCodeBinding ( binding ) ,
203- this . _getAriaLabelForScanCodeBinding ( binding )
162+ this . _mapper . getUILabelForScanCodeBinding ( binding ) ,
163+ this . _mapper . getAriaLabelForScanCodeBinding ( binding )
204164 ) ;
205165 }
206166
@@ -900,9 +860,15 @@ export class MacLinuxKeyboardMapper implements IKeyboardMapper {
900860 return result ;
901861 }
902862
903- public getUILabelForScanCode ( scanCode : ScanCode ) : string {
863+ public getUILabelForScanCodeBinding ( binding : ScanCodeBinding ) : string {
864+ if ( ! binding ) {
865+ return null ;
866+ }
867+ if ( binding . isDuplicateModifierCase ( ) ) {
868+ return '' ;
869+ }
904870 if ( this . _OS === OperatingSystem . Macintosh ) {
905- switch ( scanCode ) {
871+ switch ( binding . scanCode ) {
906872 case ScanCode . ArrowLeft :
907873 return '←' ;
908874 case ScanCode . ArrowUp :
@@ -913,11 +879,17 @@ export class MacLinuxKeyboardMapper implements IKeyboardMapper {
913879 return '↓' ;
914880 }
915881 }
916- return this . _scanCodeToLabel [ scanCode ] ;
882+ return this . _scanCodeToLabel [ binding . scanCode ] ;
917883 }
918884
919- public getAriaLabelForScanCode ( scanCode : ScanCode ) : string {
920- return this . _scanCodeToLabel [ scanCode ] ;
885+ public getAriaLabelForScanCodeBinding ( binding : ScanCodeBinding ) : string {
886+ if ( ! binding ) {
887+ return null ;
888+ }
889+ if ( binding . isDuplicateModifierCase ( ) ) {
890+ return '' ;
891+ }
892+ return this . _scanCodeToLabel [ binding . scanCode ] ;
921893 }
922894
923895 public getDispatchStrForScanCodeBinding ( keypress : ScanCodeBinding ) : string {
@@ -944,19 +916,33 @@ export class MacLinuxKeyboardMapper implements IKeyboardMapper {
944916 return result ;
945917 }
946918
947- public getUserSettingsLabel ( scanCode : ScanCode ) : string {
948- const immutableKeyCode = IMMUTABLE_CODE_TO_KEY_CODE [ scanCode ] ;
919+ public getUserSettingsLabelForScanCodeBinding ( binding : ScanCodeBinding ) : string {
920+ if ( ! binding ) {
921+ return null ;
922+ }
923+ if ( binding . isDuplicateModifierCase ( ) ) {
924+ return '' ;
925+ }
926+
927+ const immutableKeyCode = IMMUTABLE_CODE_TO_KEY_CODE [ binding . scanCode ] ;
949928 if ( immutableKeyCode !== - 1 ) {
950929 return USER_SETTINGS . fromKeyCode ( immutableKeyCode ) . toLowerCase ( ) ;
951930 }
952931
953932 // Check if this scanCode always maps to the same keyCode and back
954- let constantKeyCode : KeyCode = this . _scanCodeKeyCodeMapper . guessStableKeyCode ( scanCode ) ;
933+ let constantKeyCode : KeyCode = this . _scanCodeKeyCodeMapper . guessStableKeyCode ( binding . scanCode ) ;
955934 if ( constantKeyCode !== - 1 ) {
956- return USER_SETTINGS . fromKeyCode ( constantKeyCode ) . toLowerCase ( ) ;
935+ // Verify that this is a good key code that can be mapped back to the same scan code
936+ let reverseBindings = this . simpleKeybindingToScanCodeBinding ( new SimpleKeybinding ( binding . ctrlKey , binding . shiftKey , binding . altKey , binding . metaKey , constantKeyCode ) ) ;
937+ for ( let i = 0 , len = reverseBindings . length ; i < len ; i ++ ) {
938+ const reverseBinding = reverseBindings [ i ] ;
939+ if ( reverseBinding . scanCode === binding . scanCode ) {
940+ return USER_SETTINGS . fromKeyCode ( constantKeyCode ) . toLowerCase ( ) ;
941+ }
942+ }
957943 }
958944
959- return this . _scanCodeToDispatch [ scanCode ] ;
945+ return this . _scanCodeToDispatch [ binding . scanCode ] ;
960946 }
961947
962948 private _getElectronLabelForKeyCode ( keyCode : KeyCode ) : string {
@@ -980,14 +966,21 @@ export class MacLinuxKeyboardMapper implements IKeyboardMapper {
980966 return KeyCodeUtils . toString ( keyCode ) ;
981967 }
982968
983- public getElectronLabelForScanCode ( scanCode : ScanCode ) : string {
984- const immutableKeyCode = IMMUTABLE_CODE_TO_KEY_CODE [ scanCode ] ;
969+ public getElectronAcceleratorLabelForScanCodeBinding ( binding : ScanCodeBinding ) : string {
970+ if ( ! binding ) {
971+ return null ;
972+ }
973+ if ( binding . isDuplicateModifierCase ( ) ) {
974+ return null ;
975+ }
976+
977+ const immutableKeyCode = IMMUTABLE_CODE_TO_KEY_CODE [ binding . scanCode ] ;
985978 if ( immutableKeyCode !== - 1 ) {
986979 return this . _getElectronLabelForKeyCode ( immutableKeyCode ) ;
987980 }
988981
989982 // Check if this scanCode always maps to the same keyCode and back
990- let constantKeyCode : KeyCode = this . _scanCodeKeyCodeMapper . guessStableKeyCode ( scanCode ) ;
983+ const constantKeyCode : KeyCode = this . _scanCodeKeyCodeMapper . guessStableKeyCode ( binding . scanCode ) ;
991984
992985 if ( ! this . _isUSStandard ) {
993986 // Electron cannot handle these key codes on anything else than standard US
0 commit comments