Skip to content

ListView prediction breaks RevertLine() #5047

Open

Description

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

N/A

Screenshot

Image

Environment data

PS Version: 7.5.4
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.4.5
PSReadLine EditMode: Windows
OS: 10.0.26100.7306 (WinBuild.160101.0800)
BufferWidth: 361
BufferHeight: 96

Steps to reproduce

In a pwsh -NoProfile session, run the following:

Set-PSReadLineKeyHandler -Chord "Ctrl+r" -ScriptBlock {
    [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
    [Microsoft.PowerShell.PSConsoleReadLine]::Insert("Inserted Text")
}

Set-PSReadLineOption -PredictionViewStyle ListView

Then, type foo (without pressing the enter key) and press Ctrl+R.

Expected behavior

Pressing Ctrl+R should replace foo by Inserted Text in the prompt.

Actual behavior

Pressing Ctrl+R adds Inserted Text to the existing foo: the end result is fooInserted Text in the prompt.

Activity

  1. daxian-dbw commented on Jan 5, 2026

    @daxian-dbw
    Member

    This is because RevertLine behaves differently when list view is active. When list view is active, RevertLine reverts back to the original user input, even if a different list item gets selected by UpArrow/DownArrow.

    Maybe RevertLine should continue erase the whole line when no item is selected in the list view (meaning the user didn't select anything in the list, so no need to revert to the original user input.)

    To work around it for now, your key handler needs to have 2 RevertLine calls in it.

  2. ltrzesniewski commented on Jan 5, 2026

    @ltrzesniewski
    Author

    Thanks for the explanation!

    This is because RevertLine behaves differently when list view is active.

    Well, that's exactly the problem described here. This was surprising to me. 😅

    The method's documentation is:

    Reverts all of the input to the current input.

    I didn't realize this was related to the list view. From its behavior, I thought this was an equivalent of a Clear() method, which doesn't exist. I guess I should have been more careful given the documentation I didn't understand.

    In any case, I suppose this method requires a more precise documentation.

  3. ltrzesniewski commented on Jan 5, 2026

    @ltrzesniewski
    Author

    Maybe RevertLine should either be a no-op, or just remove the prediction in InlineView mode?

    That would better match its description and behavior in ListView mode, but it would be a breaking change.

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

    Needs-Triage 🔍It's a new issue that core contributor team needs to triage.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions