-
Notifications
You must be signed in to change notification settings - Fork 305
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
Add argument selection handler to sample profile #1947
Add argument selection handler to sample profile #1947
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good. Formatting should be consistent with the rest of the file, e.g. use 4 spaces for indent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very interesting! The Az predictor team is actually looking for a similar experience, and we may have a built-in function in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I left 2 minor comments, once you address them we can merge the PR.
Co-authored-by: Dongbo Wang <[email protected]>
@lzybkr Could you take another look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are no arguments, the cursor shouldn't move. An early return (and a Ding?) also avoids other potential issues, like indexing out of bounds (which is reported in V2 strict mode.)
I have conflicting feelings about not selecting arguments, but this is a sample, so I don't care if that behavior is changed. I say conflicting because I tried this one a command line like:
echoargs -a 1 --long 2
Repeatedly pressing Alt+a would select 1
, --long
, and 2
. In this example, it's surprising that -a
is not selected but --long
is. I know why, but it does feel weird.
$args[0].Parent -is [System.Management.Automation.Language.CommandAst] -and | ||
$args[0].Extent.StartOffset -ne $args[0].Parent.Extent.StartOffset | ||
}, $true) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ($asts.Count -eq 0) { | |
[Microsoft.PowerShell.PSConsoleReadLine]::Ding() | |
return | |
} |
🎉 |
PR Summary
This adds a handler to the sample PSReadLine profile which cycles through the arguments on the current command line, and selects the entire argument. This makes it simpler to quickly change an argument when recalling a command from the history, or changing the values of an argument when using a suggested command from a PSReadLine predictor plugin.
PR Checklist
Microsoft Reviewers: Open in CodeFlow