@@ -50,6 +50,7 @@ class KeybindManager {
5050 userKeybindingError : OV < string > ;
5151 globalModel : any ;
5252 activeKeybindsVersion : OV < number > ;
53+ lastKeyData : { domain : string ; keyPress : string } ;
5354
5455 constructor ( GlobalModel : any ) {
5556 this . levelMap = new Map ( ) ;
@@ -67,6 +68,7 @@ class KeybindManager {
6768 } ) ;
6869 this . globalModel = GlobalModel ;
6970 this . initKeyDescriptionsMap ( ) ;
71+ this . lastKeyData = { domain : "none" , keyPress : "none" } ;
7072 }
7173
7274 initKeyDescriptionsMap ( ) {
@@ -127,8 +129,7 @@ class KeybindManager {
127129 this . keyDescriptionsMap = newKeyDescriptions ;
128130 }
129131
130- prettyPrintKeybind ( keyDescription : string ) : string {
131- let keyPress = parseKeyDescription ( keyDescription ) ;
132+ prettyPrintKeyPress ( keyPress : KeyPressDecl ) : string {
132133 let returnString = "" ;
133134 if ( keyPress . mods . Cmd ) {
134135 returnString += "⌘" ;
@@ -152,6 +153,11 @@ class KeybindManager {
152153 return returnString ;
153154 }
154155
156+ prettyPrintKeybind ( keyDescription : string ) : string {
157+ let keyPress = parseKeyDescription ( keyDescription ) ;
158+ return this . prettyPrintKeyPress ( keyPress ) ;
159+ }
160+
155161 getUIDescription ( keyDescription : string , prettyPrint : boolean = true ) : KeybindConfig {
156162 let keybinds = this . getKeybindsFromDescription ( keyDescription , prettyPrint ) ;
157163 if ( ! this . keyDescriptionsMap . has ( keyDescription ) ) {
@@ -268,11 +274,23 @@ class KeybindManager {
268274 if ( shouldReturn ) {
269275 nativeEvent . preventDefault ( ) ;
270276 nativeEvent . stopPropagation ( ) ;
277+ this . lastKeyData . domain = curKeybind . domain ;
278+ this . lastKeyData . keyPress = this . prettyPrintKeyPress (
279+ getKeyPressDeclFromKeyboardEvent ( event , KeyTypeKey )
280+ ) ;
281+ mobx . action ( ( ) => {
282+ this . activeKeybindsVersion . set ( this . activeKeybindsVersion . get ( ) + 1 ) ;
283+ } ) ( ) ;
271284 this . runDomainCallbacks ( event , domainCallbacksToRun ) ;
272285 return true ;
273286 }
274287 }
275288 }
289+ this . lastKeyData . domain = "none" ;
290+ this . lastKeyData . keyPress = "none" ;
291+ mobx . action ( ( ) => {
292+ this . activeKeybindsVersion . set ( this . activeKeybindsVersion . get ( ) + 1 ) ;
293+ } ) ( ) ;
276294 this . runDomainCallbacks ( event , domainCallbacksToRun ) ;
277295 return false ;
278296 }
@@ -373,7 +391,7 @@ class KeybindManager {
373391 }
374392
375393 getActiveKeybindsVersion ( ) {
376- return this . activeKeybindsVersion . get ( ) ;
394+ return this . activeKeybindsVersion ;
377395 }
378396
379397 checkKeyInKeybinding ( key : string , keyDescription : string ) {
@@ -441,6 +459,10 @@ class KeybindManager {
441459 return toReturn ;
442460 }
443461
462+ getLastKeyData ( ) {
463+ return this . lastKeyData ;
464+ }
465+
444466 getActiveKeybindings ( ) : Array < { name : string ; domains : Array < string > } > {
445467 let modalLevel = this . levelMap . get ( "modal" ) ;
446468 let toReturn : Array < { name : string ; domains : Array < string > } > = [ ] ;
@@ -644,6 +666,25 @@ function parseKeyDescription(keyDescription: string): KeyPressDecl {
644666 return rtn ;
645667}
646668
669+ function getKeyPressDeclFromKeyboardEvent ( waveEvent : WaveKeyboardEvent , keyType : string ) : KeyPressDecl {
670+ let rtn = { key : "" , mods : { } } as KeyPressDecl ;
671+ rtn . mods . Cmd = waveEvent . cmd ;
672+ rtn . mods . Ctrl = waveEvent . control ;
673+ rtn . mods . Shift = waveEvent . shift ;
674+ rtn . mods . Option = waveEvent . option ;
675+ rtn . mods . Alt = waveEvent . alt && ! waveEvent . option ;
676+ rtn . mods . Meta = waveEvent . meta && ! waveEvent . cmd ;
677+ if ( keyType == KeyTypeKey ) {
678+ rtn . key = waveEvent . code ;
679+ rtn . keyType = KeyTypeKey ;
680+ }
681+ if ( keyType == KeyTypeCode ) {
682+ rtn . key = waveEvent . code ;
683+ rtn . keyType = KeyTypeCode ;
684+ }
685+ return rtn ;
686+ }
687+
647688function parseKey ( key : string ) : { key : string ; type : string } {
648689 let regexMatch = key . match ( KeyTypeCodeRegex ) ;
649690 if ( regexMatch != null && regexMatch . length > 1 ) {
0 commit comments