Allow accepting suggestion with the EndOfLine key (End) if cursor is at the end of line · Issue #3705 · PowerShell/PSReadLine · GitHub
Skip to content

Allow accepting suggestion with the EndOfLine key (End) if cursor is at the end of line #3705

Open

Description

Prerequisites

  • Write a descriptive title.

Description of the new feature/enhancement

Currently, it is only possible to accept suggestions when at the end of line if the ForwardChar (right arrow) key is hit. I think it would also make sense to treat the EndOfLine (End) key the same way. I know that this is how zsh-autosuggestions work, I haven't tested if fish autosuggestions also work like that but I feel like it's an intuitive behavior since you're trying to go to the end of the suggested line. I'm sure it is possible with a script block (I haven't yet looked into how but probably will soon) but I think that this would be a sensible default to have.

Arguably, the End key makes more sense than the right arrow key, and the right arrow key could be used for accepting the next word but that's really just my opinion which doesn't really matter when there are already so many users that are used to this. + It is possible to change it with the provided ForwardCharAndAcceptNextSuggestionWord example.

Proposed technical implementation details (optional)

No response

[Edited by Dongbo Wang (@daxian-dbw)] Added one upvote to represent the duplicate issue #3741

Activity

  1. ghost added
    Needs-Triage 🔍It's a new issue that core contributor team needs to triage.
    on Jun 3, 2023
  2. StevenBucher98 commented on Jun 4, 2023

    @StevenBucher98
    Collaborator

    Thanks for the issue Jakub Kuczys (@Jackenmen)! You change change the AcceptSuggestion function to the End key to accept the suggestion. I do not know the exact key name of the End key but if you run [System.Console]::ReadKey(), press the end key and use that "Key" property to fill in this commend Set-PSReadLineKeyHandler -Chord '<END KEY PROPERTY>' -Function MenuComplete. I am restricted to a laptop currently so don't have that key to test myself 😄 Let me know if that works for you!

  3. Jackenmen commented on Jun 4, 2023

    @Jackenmen
    Author

    I was asking for a change in the default behavior of the End key such that:

    • it moves the cursor to the end of the current editing line, if it isn't already there
    • it accepts the suggestion, otherwise (i.e. when the cursor is at the end of the current editing line)

    This would make it act more like the RightArrow key works:

    • it moves the cursor one character to the right, if it isn't at the end of the current editing line
    • it accepts the suggestion, otherwise (i.e. when the cursor is at the end of the current editing line)

    Right now, I use this custom key handler to do this:

    Set-PSReadLineKeyHandler -Key "End" `
            -BriefDescription ForwardCharAndAcceptNextSuggestionWord `
            -LongDescription "Move the cursor to the end of the current editing line or accept the suggestion if it's already there" `
            -ScriptBlock {
        param($key, $arg)
    
        $line = $null
        $cursor = $null
        [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
        if ($cursor -lt $line.Length) {
            [Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine($key, $arg)
        } else {
            [Microsoft.PowerShell.PSConsoleReadLine]::AcceptSuggestion($key, $arg)
        }
    }

    but as I described in the issue, I think that this would be a sensible default to have which is why I'm requesting it. Personally, I feel like it's a weird inconsistency considering that both the right arrow and the End key are used for cursor movement.

  4. Jackenmen commented on Jun 4, 2023

    @Jackenmen
    Author

    The relevant functions:


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

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions