Skip to content

Right-click earlier text in console readout, then hit escape causes exception #1597

Closed

Description

Environment

Attribute Value
PS version 7.1.0-preview.3
PSReadline version 2.1.0-beta1
os 10.0.19640.1 (WinBuild.160101.0800)
PS file version 7.1.0.0
HostName ConsoleHost
BufferWidth: 104
BufferHeight 1000
 e n v : P R O Tab Tab Tab Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace g Tab Tab Tab \ Delete Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Enter
 g e t - p r o Tab Spacebar - Tab Tab 2 3 2 2 0 LeftArrow LeftArrow LeftArrow LeftArrow LeftArrow Spacebar Enter
 UpArrow Ctrl+Backspace 2 0 5 4 8 Enter
 UpArrow UpArrow UpArrow Ctrl+a Ctrl+x UpArrow UpArrow UpArrow UpArrow UpArrow UpArrow UpArrow Enter
 UpArrow Home Ctrl+RightArrow UpArrow UpArrow UpArrow UpArrow UpArrow UpArrow UpArrow UpArrow UpArrow UpArrow DownArrow DownArrow Enter
 UpArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow LeftArrow LeftArrow Ctrl+Delete Ctrl+RightArrow LeftArrow LeftArrow Ctrl+Delete Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+z Ctrl+z Ctrl+LeftArrow Ctrl+LeftArrow LeftArrow LeftArrow LeftArrow RightArrow Shift+Ctrl+RightArrow Shift+Ctrl+RightArrow Shift+LeftArrow Shift+LeftArrow Shift+LeftArrow Shift+LeftArrow Shift+LeftArrow Shift+LeftArrow Shift+RightArrow Ctrl+x Ctrl+RightArrow LeftArrow LeftArrow Shift+Ctrl+RightArrow Shift+Ctrl+RightArrow Shift+LeftArrow Shift+LeftArrow Shift+LeftArrow Shift+LeftArrow Shift+LeftArrow Shift+LeftArrow - - h e l p Ctrl+RightArrow LeftArrow LeftArrow LeftArrow LeftArrow Ctrl+Delete Delete Ctrl+LeftArrow Ctrl+LeftArrow RightArrow RightArrow RightArrow u p d a t e Enter
 UpArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow RightArrow RightArrow RightArrow RightArrow RightArrow Delete Enter
 UpArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Shift+RightArrow Shift+RightArrow Shift+RightArrow Shift+RightArrow Delete - - p r e v i e w U p d a t e Escape

Exception

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'length')
   at System.Text.StringBuilder.Remove(Int32 startIndex, Int32 length)
   at Microsoft.PowerShell.PSConsoleReadLine.EditItemInsertChar.Undo()
   at Microsoft.PowerShell.PSConsoleReadLine.RevertLine(Nullable`1 key, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(PSKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken)

Steps to reproduce

Prepare the scene by recalling an earlier command at the prompt using the up-arrow. Press back-arrow to move cursor into the spot at which you want to inject text from earlier in the console readout. Scroll up, highlight text in the console readout. Right-click the console to reproduce the text at the current cursor location. Hit escape to clear the command at the prompt. Sit back and enjoy the exception.

Expected behavior

Escape should not raise an exception after right click injecting text from the console readout.

Actual behavior

- System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'length')

Activity

  1. ghost added
    Needs-Triage 🔍It's a new issue that core contributor team needs to triage.
    on Jun 10, 2020
  2. daxian-dbw commented on Jun 10, 2020

    @daxian-dbw
    Member

    Mavaddat Javid (@mavaddat) Didn't you already open #1495 for the same issue?
    It was fixed by #1496, and is included in 2.1.0-beta2 version of PSReadLine, which is available in PowerShell Gallery.

  3. ghost removed
    Needs-Triage 🔍It's a new issue that core contributor team needs to triage.
    on Jun 10, 2020
  4. mavaddat commented on Jun 10, 2020

    @mavaddat
    Author

    Mavaddat Javid (@mavaddat) Didn't you already open #1495 for the same issue?
    It was fixed by #1496, and is included in 2.1.0-beta2 version of PSReadLine, which is available in PowerShell Gallery.

    Oh geez. Is it the same issue? I assumed I had updated PSReadLine since then. Sorry.

  5. daxian-dbw commented on Jun 10, 2020

    @daxian-dbw
    Member

    No worries, yeah I saw the new PS version, but the PSReadLine version is the same.
    Install the 2.1.0-beta2 from PowerShell Gallery and give it a try.

  6. mavaddat commented on Jun 10, 2020

    @mavaddat
    Author

    The bug is gone in 2.1.0-beta2. Thanks!

  7. daxian-dbw commented on Jun 10, 2020

    @daxian-dbw
    Member

    Be noted that the predictive suggestion feature is disabled by default in 2.1.0-beta2, you can turn it on by Set-PSReadLineOption -PredictionSource History

  8. mavaddat commented on Jun 10, 2020

    @mavaddat
    Author

    Be noted that the predictive suggestion feature is disabled by default in 2.1.0-beta2, you can turn it on by Set-PSReadLineOption -PredictionSource History

    You read my mind! I was literally just trying to figure out how to modulate this feature (turn it back on), reading this pull request thread about it and this sample profile.ps1 to achieve certain features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-DuplicateThere's another issue on the tracker that's pretty much the same thing.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions