@@ -399,5 +399,88 @@ public static void RemoveKeyHandler(string[] key)
399399 }
400400 }
401401 }
402+
403+ /// <summary>
404+ /// Return key handlers bound to specified chords.
405+ /// </summary>
406+ /// <returns></returns>
407+ public static IEnumerable < PowerShell . KeyHandler > GetKeyHandlers ( string [ ] Chord )
408+ {
409+ var boundFunctions = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) ;
410+
411+ if ( Chord == null ) yield break ;
412+
413+ foreach ( string Key in Chord )
414+ {
415+ ConsoleKeyInfo [ ] consoleKeyChord = ConsoleKeyChordConverter . Convert ( Key ) ;
416+ PSKeyInfo firstKey = PSKeyInfo . FromConsoleKeyInfo ( consoleKeyChord [ 0 ] ) ;
417+
418+ if ( _singleton . _dispatchTable . TryGetValue ( firstKey , out KeyHandler entry ) )
419+ {
420+ if ( consoleKeyChord . Length == 1 )
421+ {
422+ yield return new PowerShell . KeyHandler
423+ {
424+ Key = firstKey . KeyStr ,
425+ Function = entry . BriefDescription ,
426+ Description = entry . LongDescription ,
427+ Group = GetDisplayGrouping ( entry . BriefDescription ) ,
428+ } ;
429+ }
430+ else
431+ {
432+ PSKeyInfo secondKey = PSKeyInfo . FromConsoleKeyInfo ( consoleKeyChord [ 1 ] ) ;
433+ if ( _singleton . _chordDispatchTable . TryGetValue ( firstKey , out var secondDispatchTable ) &&
434+ secondDispatchTable . TryGetValue ( secondKey , out entry ) )
435+ {
436+ yield return new PowerShell . KeyHandler
437+ {
438+ Key = firstKey . KeyStr + "," + secondKey . KeyStr ,
439+ Function = entry . BriefDescription ,
440+ Description = entry . LongDescription ,
441+ Group = GetDisplayGrouping ( entry . BriefDescription ) ,
442+ } ;
443+ }
444+ }
445+ }
446+
447+ // If in Vi mode, also check Vi's command mode list.
448+ if ( PSConsoleReadLine . GetOptions ( ) . EditMode == EditMode . Vi )
449+ {
450+ if ( _viCmdKeyMap . TryGetValue ( firstKey , out entry ) )
451+ {
452+ if ( consoleKeyChord . Length == 1 )
453+ {
454+ if ( entry . BriefDescription == "Ignore" ) continue ;
455+ yield return new PowerShell . KeyHandler
456+ {
457+ Key = '<' + firstKey . KeyStr + '>' ,
458+ Function = entry . BriefDescription ,
459+ Description = entry . LongDescription ,
460+ Group = GetDisplayGrouping ( entry . BriefDescription ) ,
461+ } ;
462+ }
463+ else
464+ {
465+ PSKeyInfo secondKey = PSKeyInfo . FromConsoleKeyInfo ( consoleKeyChord [ 1 ] ) ;
466+ if ( _viCmdChordTable . TryGetValue ( firstKey , out var secondDispatchTable ) &&
467+ secondDispatchTable . TryGetValue ( secondKey , out entry ) )
468+ {
469+ if ( entry . BriefDescription == "Ignore" ) continue ;
470+ yield return new PowerShell . KeyHandler
471+ {
472+ Key = '<' + firstKey . KeyStr + "," + secondKey . KeyStr + '>' ,
473+ Function = entry . BriefDescription ,
474+ Description = entry . LongDescription ,
475+ Group = GetDisplayGrouping ( entry . BriefDescription ) ,
476+ } ;
477+ }
478+ }
479+ }
480+ }
481+ }
482+ yield break ;
483+
484+ }
402485 }
403486}
0 commit comments