Skip to content

Exception when deleting invalid command retained from ValidateAndAcceptLine in Vi Mode #3919

Open
@HenriquedoVal

Description

@HenriquedoVal

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

### Environment
PSReadLine: 2.3.4
PowerShell: 7.4.0
OS: Microsoft Windows 10.0.22621
BufferWidth: 169
BufferHeight: 41

Last 114 Keys:

 S e t - P S R e a d L i n e O p t i o n Spacebar - E d i t M o d e Spacebar V i Enter S e t - P S R e a d L i n e K e y H a n d l e r Spacebar - K e y Spacebar E n t e r Spacebar - F u n c t i o n Spacebar V a l i d a t e A n d A c c e p t L i n e Enter n o t v a l i d Enter Escape d d

### Exception

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.Text.StringBuilder.get_Chars(Int32 index)
   at Microsoft.PowerShell.PSConsoleReadLine.ConvertOffsetToPoint(Int32 offset)
   at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   at Microsoft.PowerShell.PSConsoleReadLine.RenderWithPredictionQueryPaused()
   at Microsoft.PowerShell.PSConsoleReadLine.ClearStatusMessage(Boolean render)
   at Microsoft.PowerShell.PSConsoleReadLine.SaveEditItem(EditItem editItem)
   at Microsoft.PowerShell.PSConsoleReadLine.DeleteLineImpl(Int32 lineIndex, Int32 lineCount)
   at Microsoft.PowerShell.PSConsoleReadLine.DeleteLine(Nullable`1 key, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(PSKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ViChordHandler(Dictionary`2 secondKeyDispatchTable, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ViChord(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, Nullable`1 lastRunStatus)

Screenshot

screenshot

Environment data

PS Version: 7.4.0
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.3.4
PSReadLine EditMode: Vi
OS: 10.0.22621.2428 (WinBuild.160101.0800)
BufferWidth: 169
BufferHeight: 41

Steps to reproduce

Start pwsh without profile, set edit mode to Vi, set Enter key handler to ValidateAndAcceptLine, enter a not valid command, press Escape to exit insert mode, enter dd

Expected behavior

The current input is deleted

Actual behavior

The above exception happens

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIt either shouldn't be doing this or needs an investigation.Needs-More InvestigationInitial investigation is done, but need to follow up.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions