Repository navigation
Added incremental MenuComplete support - #515
Conversation
Jason Shirk (lzybkr)
left a comment
There was a problem hiding this comment.
I think this is a great proof of concept.
I don't see why this is an option - I've tried to avoid adding unnecessary options, and incremental feels like it's something everybody would want, nobody would turn it off.
Using the point and mark feels wrong - that's a user's bookmark.
Most importantly - invoking MenuComplete again is probably not acceptable. It might feel fast enough in some cases, but re-invoking tab completion on each incremental update will be painful in some cases.
|
This is an option mostly because it change behavoiur of Enter key - it can be a pain for other users ( not me ) I use point and mark because it a common way to suggest things in other editors and because every cursor move drop this mark, but I agree that saving it before and restoring after will be a good thing. btw, now this mark dropped on every completition and yes, I still can't feel that I fully understand how Tab Completition work and I decided: lets PSReadLine think for me :) I will see what I can do with it with minimal changes |
|
Still leave Option intact because of reasons above. If other changes will be approved it can be removed faster than inserted :) Still use mark for suggestions because can't find how original version can use it, Marking always dropped after using menu. Now CompletionMatches filtered by remove because of strange error with CommandCompletion constructor. This code stay commented out. |
|
Jason Shirk (@lzybkr) , rfc for latest commit :) |
… method to Add() instead of Remove()
|
Sorry, I've been pretty busy and haven't had a chance to look closely at this yet. If you are getting a compiler error, it's most likely because I build against the PowerShell V3 reference assemblies and a new constructor was added since then. I will consider dropping V3 support in the next release though - because I want to make the module portable between Windows PowerShell and PowerShell Core - and that means I'll need to require .Net 4.5 at a minimum. Windows PowerShell V3 does not require .Net 4.5, so it might be confusing if PSReadline started requiring a newer runtime. |
|
latest commit use CopyTo() instead of building new CommandCompletion() |
|
I strongly prefer no option - so we'll refine the experience so it feels natural. |
|
here it is |
|
There still problems with keys like Home/End/PgUp/PgDn. I don't know, may be I need to rework current concept into handling all keys inside |
…=null are forbidden
+ Optimized Render() calls * Fixed Keys.Delete behaviour on empty completition
|
I hope now I foresaw all the cases with completions filtering... |
|
Jason Shirk (@lzybkr) , please tell what story lies behind PS C:\Users\User> $r = [System.Management.Automation.CommandCompletion]::CompleteInput('.\nt',1,$null)
>> $r.CompletionMatches
CompletionText ListItemText
-------------- ------------
.\NTUSER.DAT NTUSER.DAT
& '.\NTUSER.DAT{d51862bb-b663-11e6-9335-dfe3e1845d6f}.TM.blf' NTUSER.DAT{d51862...
.\ntuser.ini ntuser.iniI would like to add similar feature inside IncrementalCompletion (Tab advance IncrementalCompletion to the longest unambiguous prefix) and reuse the code but not fully understanded why it was implemented in a such way |
|
IIRC, the scenario was Without that code, the unambiguous prefix was the empty string because a directory It seems I missed the case where |
|
I see but why you calculate some speedup ? what if I correct btw, for example above |
|
After I slept with this thought, I realized that for the user its look like undo, so I make it through undo. |
| } | ||
|
|
||
| var matches = completions.CompletionMatches; | ||
| private static CHAR_INFO[] CreateCompletionMenu(System.Collections.ObjectModel.Collection<CompletionResult> matches, IConsole console, bool showToolTips, out int MenuColumnWidth, out int DisplayRows) |
There was a problem hiding this comment.
parameters should not start with upper case
| // we exit loop with current completion up to cursor | ||
| truncateCurrentCompletion = true; | ||
| if (userInitialCompletionLength == 0) | ||
| undo = true; |
There was a problem hiding this comment.
Please use braces around the body.
| // we exit loop with current completion up to cursor | ||
| truncateCurrentCompletion = true; | ||
| if (userInitialCompletionLength == 0) | ||
| undo = true; |
There was a problem hiding this comment.
Please use braces around the body.
| } | ||
| // without render all key chords that just move cursor leave selection visible, but it can be wrong | ||
| Render(); | ||
| if (!undo && !keepSelection) Render(); |
There was a problem hiding this comment.
I'm not always consistent about single line if statements, but in this case, I'd prefer braces and the body not on the same line as the condition.
|
Thanks for all the fixes, it's probably getting close to be ready to merge. I hit another minor issue, it's a little weird. The cursor is moving outside the command line. To reproduce: When you've done this, the screen will look like: And the cursor will be on the I don't see any real problems with this bug, but it's weird enough I'd like it fixed. |
|
I see. The original version have similar bug with end of buffer. |
|
What you think about double call to It change nothing in my code but extend For example if I have program.exe somewhere in search path, |
|
That does sound like an improvement - I think I'm fine with that. |
|
How it works now PS C:\> Set-PSReadlineOption -EditMode Emacs
PS C:\> prog<tab> #Ding here and line changed to
PS C:\> Program
PS C:\> #Second <tab>
Program Files - C:\Program Files
Program Files (x86) - C:\Program Files (x86)
ProgramData - C:\ProgramData
program.exe - C:\Windows\system32\program.exethe only thing that can be named 'problem' is that first letter case changes to upper |
|
I think this is ready to merge, but I'd like the history cleaned up a bit. If you're fine with me squashing and editing the commit message as I see fit, then I'll go ahead and do that, but I thought I'd give you a chance to do that before I merge. If you feel like adding some tests, that'd be nice too, but I'd merge without tests, this functionality will be heavily used so regressions would be quickly noticed. |
|
I'm fine with commit messages editing. About the tests, to be honest, I do not know how to write them correctly in this case. |
|
about last fix: PS C:\>Get-PR<tab>
Get-Privilege
...
Get-Process
...
PScx\Get-Privilegewith 'optimization', ListItemText comparing starts on last item, and return |
|
Thanks so much for your contribution and your patience with me, this will be a popular feature. I don't have many completion tests (partly because it's a bit painful), see https://github.com/lzybkr/PSReadLine/blob/master/UnitTestPSReadLine/CompletionTest.cs. There is a useful sort of dsl to make writing tests easier, but it's still tedious for the menu completion. I'll gladly accept a future PR with just tests if you're so inclined. |
|
Jason Shirk (@lzybkr) , I tried to write a small test, but I was stuck with exception |
#485
Add new Option and support for Incremental MenuComplete (Default = $false for seamless intergration)
Mimic PowerTab behaviour on MenuComplete - Enter finishes completition, Space finishes completition and add a space after.