Ignore case when binding PSReadline keyhandler functions

Fix #4300
This commit is contained in:
Oisin Grehan
2017-08-07 14:24:35 -07:00
committed by Jason Shirk
parent 0b7451bda3
commit 8d3f8537de
3 changed files with 21 additions and 5 deletions
+10 -3
View File
@@ -693,11 +693,18 @@ namespace Microsoft.PowerShell
if (ParameterSetName.Equals(FunctionParameterSet))
{
var function = (string)_dynamicParameters.Value[FunctionParameter].Value;
MethodInfo mi = typeof (PSConsoleReadLine).GetMethod(function);
MethodInfo mi = typeof (PSConsoleReadLine).GetMethod(function,
BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase);
string functionName = mi.Name;
var keyHandler = (Action<ConsoleKeyInfo?, object>)
mi.CreateDelegate(typeof (Action<ConsoleKeyInfo?, object>));
BriefDescription = function;
PSConsoleReadLine.SetKeyHandler(Chord, keyHandler, BriefDescription, Description);
string longDescription = PSReadLineResources.ResourceManager.GetString(
functionName + "Description");
PSConsoleReadLine.SetKeyHandler(Chord, keyHandler, functionName, longDescription);
}
else
{
@@ -79,8 +79,11 @@ namespace Microsoft.PowerShell
// key should be first token to be popped
if (key == 0)
{
// the keyChar is this token
keyChar = token[0];
// the keyChar is this token, if not a special key like "Fxx" etc.
if (token.Length == 1)
{
keyChar = token[0];
}
// Enum.TryParse accepts arbitrary integers. We shouldn't,
// but single digits need to map to the correct key, e.g.
@@ -42,6 +42,12 @@ Describe "PSReadLine" -tags "CI" {
(Get-PSReadLineKeyHandler | Where-Object { $_.Key -ceq "Alt+B" }).Function | Should Be SelectBackwardWord
}
It "Should ignore case when using Function binding" {
$lowerCaseFunctionName = "yank"
Set-PSReadlineKeyHandler "Ctrl+F24" -Function $lowerCaseFunctionName
(Get-PSReadlineKeyHandler | Where { $_.Key -eq "Ctrl+F24"}).Function | Should Be "Yank"
}
AfterAll {
Remove-Module PSReadLine