-
Notifications
You must be signed in to change notification settings - Fork 320
Closed
Labels
Description
Prerequisites
- Write a descriptive title.
Issue summary
PS D:\Temp>
> Set-PSReadLineKeyHandler -Chord 'Ctrl+d','Ctrl+x' `
> -BriefDescription SmartInsertQuote `
> -LongDescription "Insert paired quotes if not already on a quote" `
> -ScriptBlock {
> param($key, $arg)
>
> $line = $null
> $cursor = $null
> [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
>
> if ($line[$cursor] -eq $key.KeyChar) {
> # Just move the cursor
> [Microsoft.PowerShell.PSConsoleReadLine]::SetCursorPosition($cursor + 1)
> }
> else {
> # Insert matching quotes, move cursor to be in between the quotes
> [Microsoft.PowerShell.PSConsoleReadLine]::Insert("$($key.KeyChar)" * 2)
> [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
> [Microsoft.PowerShell.PSConsoleReadLine]::SetCursorPosition($cursor - 1)
> }
> }
PS D:\Temp>
PS D:\Temp>
PS D:\Temp> An exception occurred in custom key handler, see $error for more information: Index was outside the bounds of the array.
PS D:\Temp> An exception occurred in custom key handler, see $error for more information: Index was outside the bounds of the array.
PS D:\Temp> $error
OperationStopped:
Line |
12 | if ($line[$cursor] -eq $key.KeyChar) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Index was outside the bounds of the array.
PS Version
PS D:\Temp> $PSVersionTable
Name Value
---- -----
PSVersion 7.2.6
PSEdition Core
GitCommitId 7.2.6
OS Microsoft Windows 10.0.19043
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PS D:\Temp>Windows 10 build version: 19043.1889
I'm aware that the example actually uses 'Oem7','Shift+Oem7' as parameter for chord, as I understand these keys are dependent on the keyboard layout. I assume this is supposed to be ' and " on an EN-US keyboard?
I tried to change my input method with the usual switcher in the system tray, but this did not change anything for me, it would simply insert one single quote char (or double quote) and nothing more. Changing the key binding to the example above triggers the error for me..
Could very well be a locale specific issue, but maybe someone can try to reproduce?