MenuComplete: Improve tab completion in Filesystem providers
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:
- Pressing
Spacebaron a path containing whitespace will incorrectly autocomplete a single path in spite of multiple ambiguous paths existing. Tabfails to complete containers (directories) when their full name is manually typed out (or backspaced into) when a menu is open.- Inconsistent / tedious behavior when autcompleting a single, unambiguous container within the menu.
Description / Reproduction
- On Windows, type
cd C:/programand pressTab. You'll have something like these options:
- Program Files
- Program Files (x86)
- ProgramData
If you try to press
SpaceBarin order to exclude ProgramData, you will instead autocompleteProgram Filesand enter its directory, even thoughProgram Files (x86)would have also been viable at that point. => Fixed so that pressingSpacebarin this context does not autocomplete the entire word.
-
Pressing
Tabcan fail to complete containers (directories) when manually typed out in a menu. Typecd C:/and pressTabto open a menu. Typeusrand pressTab. You will havecd 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 pressingTabwill complete it including the directory separator. -
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 PSand press tab. You will correctly complete tocd .\PSReadline\. This is because a menu was avoided. Instead, try typingcd Pand thenTab. This will open a menu. Typesfollowed byTab. 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 makeMenuCompleteas quick to use as functionCompletewhile 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
@microsoft-github-policy-service agree