Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MenuComplete: Improve tab completion in Filesystem providers #4038

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

blaisemGH
Copy link

@blaisemGH blaisemGH commented Jun 13, 2024

PR Summary

This PR aims to improve the tab completion experience when using the MenuComplete function in filesystem providers (or analogous providers). It targets 2 bugs and streamlines inconsistent behavior in a 3rd QoL issue.

These are:

  1. Pressing Spacebar on a path containing whitespace will incorrectly autocomplete a single path in spite of multiple ambiguous paths existing.
  2. Tab fails to complete containers (directories) when their full name is manually typed out (or backspaced into) when a menu is open.
  3. Inconsistent / tedious behavior when autcompleting a single, unambiguous container within the menu.

Description / Reproduction

  1. On Windows, type cd C:/program and press Tab. You'll have something like these options:
  • Program Files
  • Program Files (x86)
  • ProgramData
    If you try to press SpaceBar in order to exclude ProgramData, you will instead autocomplete Program Files and enter its directory, even though Program Files (x86) would have also been viable at that point.
    => Fixed so that pressing Spacebar in this context does not autocomplete the entire word.
  1. Pressing Tab can fail to complete containers (directories) when manually typed out in a menu.
    Type cd C:/ and press Tab to open a menu.
    Type usr and press Tab.
    You will have cd C:/usr/ open, but the final / is a suggestion, and no further presses of tab will complete this slash.
    => Fixed so that manually typing a directory name and pressing Tab will complete it including the directory separator.

  2. Inconsistent / tedious behavior when autocompleting a single, unambiguous container within the menu.
    Navigate to the PSReadLine module home directory. There are 2 folders here that begin with "P", Polyfill and PSReadLine.
    First, type cd PS and press tab. You will correctly complete to cd .\PSReadline\. This is because a menu was avoided.
    Instead, try typing cd P and then Tab. This will open a menu. Type s followed by Tab. You will end up stuck before the directory separator character (similar to bug 2 but for a different reason).
    => This has been made consistent, so that an open menu will complete the same as no menu. This is also a QoL fix that streamlines using a menu, making it faster to tab through nested directories when navigating the filesystem. Ideally this would make MenuComplete as quick to use as function Complete while retaining the benefit of offering a menu.

All of the fixes are localized in one region of the code, except the first fix, which is on line 774.

Miscellaneous

As this is my first time contributing, please let me know if there's anything I should consider in my PR. I'm also happy to engage in any discussion.

Tested MenuComplete functionality works for Containers, and doesn't impact, e.g., commands.
Tested on Windows 10 with PS 7.4.2 and PS 5.1.19041.

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure you've added one or more new tests
  • Make sure you've tested these changes in terminals that PowerShell is commonly used in (i.e. conhost.exe, Windows Terminal, Visual Studio Code Integrated Terminal, etc.)
  • User-facing changes
    • Not Applicable
    • OR
    • Documentation needed at PowerShell-Docs
      • Doc Issue filed:
Microsoft Reviewers: Open in CodeFlow

* Address 3 issues:

1. pressing space inside quotes autocompletes the
   current word, even if there are multiple
   ambiguous choices available

2. Pressing Tab to open a menu and then typing out
   a directory completely locks tab from autocompleting.
   It stops before the slash and requires an enter
   instead.

3. Align tab completion behavior between no menu and
   menu scenarios when a single item is involved and
   that item is a container in a filesystem provider.
@blaisemGH
Copy link
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant