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

Allow letter keys (A-Z) to cycle indexes in Prompts #996

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tznind
Copy link

@tznind tznind commented Oct 5, 2022

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.

loopWithLetters
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.

@CLAassistant
Copy link

CLAassistant commented Oct 5, 2022

CLA assistant check
All committers have signed the CLA.


// 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)
Copy link
Contributor

@thoemmi thoemmi Oct 15, 2022

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.

Copy link
Author

@tznind tznind Oct 15, 2022

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.

@tznind tznind requested a review from thoemmi October 22, 2022 19:44
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.

3 participants