@@ -489,109 +489,6 @@ class BinaryKeybindings {
489489 }
490490}
491491
492- export function createKeybinding ( keybinding : number ) : Keybinding {
493- if ( BinaryKeybindings . hasChord ( keybinding ) ) {
494- return new ChordKeybinding ( keybinding ) ;
495- }
496- return new SimpleKeybinding ( keybinding ) ;
497- }
498-
499- export class SimpleKeybinding {
500- public readonly value : number ;
501-
502- constructor ( keybinding : number ) {
503- this . value = keybinding ;
504- }
505-
506- /**
507- * @internal
508- */
509- public isChord ( ) : this is ChordKeybinding {
510- return false ;
511- }
512-
513- /**
514- * @internal
515- */
516- public equals ( other : Keybinding ) : boolean {
517- return ( other && this . value === other . value ) ;
518- }
519-
520- public hasCtrlCmd ( ) : boolean {
521- return BinaryKeybindings . hasCtrlCmd ( this . value ) ;
522- }
523-
524- public hasShift ( ) : boolean {
525- return BinaryKeybindings . hasShift ( this . value ) ;
526- }
527-
528- public hasAlt ( ) : boolean {
529- return BinaryKeybindings . hasAlt ( this . value ) ;
530- }
531-
532- public hasWinCtrl ( ) : boolean {
533- return BinaryKeybindings . hasWinCtrl ( this . value ) ;
534- }
535-
536- public isModifierKey ( ) : boolean {
537- return BinaryKeybindings . isModifierKey ( this . value ) ;
538- }
539-
540- public getKeyCode ( ) : KeyCode {
541- return BinaryKeybindings . extractKeyCode ( this . value ) ;
542- }
543- }
544-
545- export class ChordKeybinding {
546- public readonly value : number ;
547-
548- constructor ( keybinding : number ) {
549- this . value = keybinding ;
550- }
551-
552- public isChord ( ) : this is ChordKeybinding {
553- return true ;
554- }
555-
556- public equals ( other : Keybinding ) : boolean {
557- return ( other && this . value === other . value ) ;
558- }
559-
560- public extractFirstPart ( ) : SimpleKeybinding {
561- return new SimpleKeybinding ( BinaryKeybindings . extractFirstPart ( this . value ) ) ;
562- }
563-
564- public extractChordPart ( ) : SimpleKeybinding {
565- return new SimpleKeybinding ( BinaryKeybindings . extractChordPart ( this . value ) ) ;
566- }
567- }
568-
569- export type Keybinding = SimpleKeybinding | ChordKeybinding ;
570-
571- export function _createRuntimeKeybinding ( keybinding : Keybinding , OS : OperatingSystem ) : RuntimeKeybinding {
572- if ( keybinding . isChord ( ) ) {
573- return new ChordRuntimeKeybinding (
574- _createSimpleRuntimeKeybinding ( keybinding . extractFirstPart ( ) , OS ) ,
575- _createSimpleRuntimeKeybinding ( keybinding . extractChordPart ( ) , OS ) ,
576- ) ;
577- }
578- return _createSimpleRuntimeKeybinding ( keybinding , OS ) ;
579- }
580-
581- function _createSimpleRuntimeKeybinding ( keybinding : SimpleKeybinding , OS : OperatingSystem ) : SimpleRuntimeKeybinding {
582- const ctrlCmd = keybinding . hasCtrlCmd ( ) ;
583- const winCtrl = keybinding . hasWinCtrl ( ) ;
584- const ctrlKey = ( OS === OperatingSystem . Macintosh ? winCtrl : ctrlCmd ) ;
585- const metaKey = ( OS === OperatingSystem . Macintosh ? ctrlCmd : winCtrl ) ;
586-
587- const shiftKey = keybinding . hasShift ( ) ;
588- const altKey = keybinding . hasAlt ( ) ;
589-
590- const keyCode = keybinding . getKeyCode ( ) ;
591-
592- return new SimpleRuntimeKeybinding ( ctrlKey , shiftKey , altKey , metaKey , keyCode ) ;
593- }
594-
595492export function createRuntimeKeybinding ( keybinding : number , OS : OperatingSystem ) : RuntimeKeybinding {
596493 if ( keybinding === 0 ) {
597494 return null ;
@@ -605,7 +502,7 @@ export function createRuntimeKeybinding(keybinding: number, OS: OperatingSystem)
605502 return createSimpleRuntimeKeybinding ( keybinding , OS ) ;
606503}
607504
608- function createSimpleRuntimeKeybinding ( keybinding : number , OS : OperatingSystem ) : SimpleRuntimeKeybinding {
505+ export function createSimpleRuntimeKeybinding ( keybinding : number , OS : OperatingSystem ) : SimpleRuntimeKeybinding {
609506
610507 const ctrlCmd = BinaryKeybindings . hasCtrlCmd ( keybinding ) ;
611508 const winCtrl = BinaryKeybindings . hasWinCtrl ( keybinding ) ;
@@ -641,6 +538,29 @@ export class SimpleRuntimeKeybinding {
641538 this . metaKey = metaKey ;
642539 this . keyCode = keyCode ;
643540 }
541+
542+ public equals ( other : RuntimeKeybinding ) : boolean {
543+ if ( other . type !== RuntimeKeybindingType . Simple ) {
544+ return false ;
545+ }
546+ return (
547+ this . ctrlKey === other . ctrlKey
548+ && this . shiftKey === other . shiftKey
549+ && this . altKey === other . altKey
550+ && this . metaKey === other . metaKey
551+ && this . keyCode === other . keyCode
552+ ) ;
553+ }
554+
555+ public isModifierKey ( ) : boolean {
556+ return (
557+ this . keyCode === KeyCode . Unknown
558+ || this . keyCode === KeyCode . Ctrl
559+ || this . keyCode === KeyCode . Meta
560+ || this . keyCode === KeyCode . Alt
561+ || this . keyCode === KeyCode . Shift
562+ ) ;
563+ }
644564}
645565
646566export class ChordRuntimeKeybinding {
0 commit comments