Skip to content

Commit

Permalink
Merge pull request #176004 from andschwa/andschwa/set-mapped-key-handler
Browse files Browse the repository at this point in the history
Handle `ParameterBindingException` for PowerShell 5.1
  • Loading branch information
Tyriar committed Mar 10, 2023
2 parents fb5ca69 + 0431b96 commit 3bc06ff
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ if (Get-Module -Name PSReadLine) {
# Set always on key handlers which map to default VS Code keybindings
function Set-MappedKeyHandler {
param ([string[]] $Chord, [string[]]$Sequence)
$Handler = $(Get-PSReadLineKeyHandler -Chord $Chord | Select-Object -First 1)
try {
$Handler = Get-PSReadLineKeyHandler -Chord $Chord | Select-Object -First 1
} catch [System.Management.Automation.ParameterBindingException] {
# PowerShell 5.1 ships with PSReadLine 2.0.0 which does not have -Chord,
# so we check what's bound and filter it.
$Handler = Get-PSReadLineKeyHandler -Bound | Where-Object -FilterScript { $_.Key -eq $Chord } | Select-Object -First 1
}
if ($Handler) {
Set-PSReadLineKeyHandler -Chord $Sequence -Function $Handler.Function
}
Expand Down

0 comments on commit 3bc06ff

Please sign in to comment.