@@ -162,6 +162,24 @@ describe("Keybind.match", () => {
162162 expect ( Keybind . match ( a , b ) ) . toBe ( true )
163163 } )
164164
165+ test ( "should match ctrl shortcuts by baseCode from alternate layouts" , ( ) => {
166+ const a : Keybind . Info = { ctrl : true , meta : false , shift : false , leader : false , name : "c" }
167+ const b : Keybind . Info = { ctrl : true , meta : false , shift : false , leader : false , name : "ㅊ" , baseCode : 99 }
168+ expect ( Keybind . match ( a , b ) ) . toBe ( true )
169+ } )
170+
171+ test ( "should still match the reported character when baseCode is also present" , ( ) => {
172+ const a : Keybind . Info = { ctrl : true , meta : false , shift : false , leader : false , name : "ㅊ" }
173+ const b : Keybind . Info = { ctrl : true , meta : false , shift : false , leader : false , name : "ㅊ" , baseCode : 99 }
174+ expect ( Keybind . match ( a , b ) ) . toBe ( true )
175+ } )
176+
177+ test ( "should not match a different shortcut just because baseCode exists" , ( ) => {
178+ const a : Keybind . Info = { ctrl : true , meta : false , shift : false , leader : false , name : "x" }
179+ const b : Keybind . Info = { ctrl : true , meta : false , shift : false , leader : false , name : "ㅊ" , baseCode : 99 }
180+ expect ( Keybind . match ( a , b ) ) . toBe ( false )
181+ } )
182+
165183 test ( "should match super+shift combination" , ( ) => {
166184 const a : Keybind . Info = { ctrl : false , meta : false , shift : true , super : true , leader : false , name : "z" }
167185 const b : Keybind . Info = { ctrl : false , meta : false , shift : true , super : true , leader : false , name : "z" }
@@ -419,3 +437,68 @@ describe("Keybind.parse", () => {
419437 ] )
420438 } )
421439} )
440+
441+ describe ( "Keybind.parseOne" , ( ) => {
442+ test ( "should parse a single keybind" , ( ) => {
443+ expect ( Keybind . parseOne ( "ctrl+x" ) ) . toEqual ( {
444+ ctrl : true ,
445+ meta : false ,
446+ shift : false ,
447+ leader : false ,
448+ name : "x" ,
449+ } )
450+ } )
451+
452+ test ( "should reject multiple keybinds" , ( ) => {
453+ expect ( ( ) => Keybind . parseOne ( "ctrl+x,ctrl+y" ) ) . toThrow ( "Expected exactly one keybind" )
454+ } )
455+ } )
456+
457+ describe ( "Keybind.fromParsedKey" , ( ) => {
458+ test ( "should preserve baseCode from ParsedKey" , ( ) => {
459+ const result = Keybind . fromParsedKey ( {
460+ name : "ㅊ" ,
461+ ctrl : true ,
462+ meta : false ,
463+ shift : false ,
464+ option : false ,
465+ number : false ,
466+ sequence : "ㅊ" ,
467+ raw : "\x1b[12618::99;5u" ,
468+ eventType : "press" ,
469+ source : "kitty" ,
470+ baseCode : 99 ,
471+ } )
472+
473+ expect ( result ) . toEqual ( {
474+ name : "ㅊ" ,
475+ ctrl : true ,
476+ meta : false ,
477+ shift : false ,
478+ super : false ,
479+ leader : false ,
480+ baseCode : 99 ,
481+ } )
482+ } )
483+
484+ test ( "should ignore leader unless explicitly requested" , ( ) => {
485+ const key = {
486+ name : "ㅊ" ,
487+ ctrl : true ,
488+ meta : false ,
489+ shift : false ,
490+ option : false ,
491+ number : false ,
492+ sequence : "ㅊ" ,
493+ raw : "\x1b[12618::99;5u" ,
494+ eventType : "press" as const ,
495+ source : "kitty" as const ,
496+ baseCode : 99 ,
497+ }
498+
499+ expect ( Keybind . matchParsedKey ( "ctrl+c" , key ) ) . toBe ( true )
500+ expect ( Keybind . matchParsedKey ( "ctrl+x,ctrl+c" , key ) ) . toBe ( true )
501+ expect ( Keybind . matchParsedKey ( "ctrl+x,ctrl+y" , key ) ) . toBe ( false )
502+ expect ( Keybind . matchParsedKey ( "ctrl+c" , key , true ) ) . toBe ( false )
503+ } )
504+ } )
0 commit comments