8000 Ignore case when binding PSReadline keyhandler functions · PowerShell/PowerShell@8d3f853 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d3f853

Browse files
oisinglzybkr
authored andcommitted
Ignore case when binding PSReadline keyhandler functions
Fix #4300
1 parent 0b7451b commit 8d3f853

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,11 +693,18 @@ protected override void EndProcessing()
693693
if (ParameterSetName.Equals(FunctionParameterSet))
694694
{
695695
var function = (string)_dynamicParameters.Value[FunctionParameter].Value;
696-
MethodInfo mi = typeof (PSConsoleReadLine).GetMethod(function);
696+
MethodInfo mi = typeof (PSConsoleReadLine).GetMethod(function,
697+
BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase);
698+
699+
string functionName = mi.Name;
700+
697701
var keyHandler = (Action<ConsoleKeyInfo?, object>)
698702
mi.CreateDelegate(typeof (Action<ConsoleKeyInfo?, object>));
699-
BriefDescription = function;
700-
PSConsoleReadLine.SetKeyHandler(Chord, keyHandler, BriefDescription, Description);
703+
704+
string longDescription = PSReadLineResources.ResourceManager.GetString(
705+
functionName + "Description");
706+
707+
PSConsoleReadLine.SetKeyHandler(Chord, keyHandler, functionName, longDescription);
701708
}
702709
else
703710
{

src/Microsoft.PowerShell.PSReadLine/ConsoleKeyChordConverter.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ private static ConsoleKeyInfo ConvertOneSequence(string sequence)
7979
// key should be first token to be popped
8080
if (key == 0)
8181
{
82-
// the keyChar is this token
83-
keyChar = token[0];
82+
// the keyChar is this token, if not a special key like "Fxx" etc.
83+
if (token.Length == 1)
84+
{
85+
keyChar = token[0];
86+
}
8487

8588
// Enum.TryParse accepts arbitrary integers. We shouldn't,
8689
// but single digits need to map to the correct key, e.g.

test/powershell/Modules/PSReadLine/PSReadLine.Tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ Describe "PSReadLine" -tags "CI" {
4242
(Get-PSReadLineKeyHandler | Where-Object { $_.Key -ceq "Alt+B" }).Function | Should Be SelectBackwardWord
4343
}
4444

45+
It "Should ignore case when using Function binding" {
46+
$lowerCaseFunctionName = "yank"
47+
Set-PSReadlineKeyHandler "Ctrl+F24" -Function $lowerCaseFunctionName
48+
(Get-PSReadlineKeyHandler | Where { $_.Key -eq "Ctrl+F24"}).Function | Should Be "Yank"
49+
}
50+
4551
AfterAll {
4652
Remove-Module PSReadLine
4753

0 commit comments

Comments
 (0)
0