-
-
Notifications
You must be signed in to change notification settings - Fork 532
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
Allow letter keys (A-Z) to cycle indexes in Prompts #996
base: main
Are you sure you want to change the base?
Conversation
|
||
// find indexes of items that start with the letter | ||
int[] matchingIndexes = Items.Select((item, idx) => (item, idx)) | ||
.Where(k => k.item.Data.ToString()?.StartsWith(keyStruck, StringComparison.InvariantCultureIgnoreCase) ?? false) |
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.
k.item.Data
must not be string
but can be any type of object. You have to respect a potential converter. See how the data is rendered e.g. in SelectionPrompt
:
var text = (Converter ?? TypeConverterHelper.ConvertToString)?.Invoke(item.Node.Data) ?? item.Node.Data.ToString() ?? "?"; |
When you want to jump to an item with the specific starting character, you have to look for the string that is actually displayed.
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.
Thanks for pointing this out, I had missed that. I have added the converter
arg to ListPromptState<T>.Update
method so it can check the actual string contents. I added it as a default parameter to the method but if you would rather I create a new overload instead then I can update to that approach.
I had to add the converter property to IListPromptStrategy<T>
since that is what ListPrompt.cs
has access to. And ListPrompt
is the one calling state.Update
.
Adds the ability to press letter keys (A-Z) to cycle selection to next item beginning with that letter in Prompt.
I have made changes only to
ListPromptState.cs
as this is where Up and Down are being handled. Let me know if there is a better place for it or if this isn't a feature you want to incorporate.I created a Discussion in #992 but since it was so easy to implement I thought I would just create a PR to demonstrate the idea.
Check up/down works then pressing 'M' repeatedly then 'L' then End followed by clycling 'O'
Please upvote 👍 this pull request if you are interested in it.