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

Additions to the InputSelector #4226

Closed
Danielkonge opened this issue Aug 30, 2023 · 4 comments
Closed

Additions to the InputSelector #4226

Danielkonge opened this issue Aug 30, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@Danielkonge
Copy link
Contributor

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is.

I am trying to use the InputSelector more for choosing from longer lists and would like a few more options.

Describe the solution you'd like
A clear and concise description of what you want to happen.

My primary suggestion is to add a longer alphabet to choose from with one click when opening the InputSelector.

Right now it only shows numbers [1-9] for the first 9 elements of the list, but it would be nice to show [1-9] for the first 9 elements and then [a-z] for the next 26 elements and possibly [A-Z] beyond that for anyone using small enough fonts to see that many elements.

Alternatively, one could choose the exact labels themselves, but this would probably require slightly more work, and I assume my first suggestion would be easier to implement.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

I have also thought about jumping straight to the filter part of the InputSelector to avoid picking out elements like above. It would be nice if there was a flag "start_with_filter" (or something like that) for the InputSelector that is "false" if you want to start the InputSelector as it does now and "true" if it essentially does what would be equivalent to starting the InputSelector and then pressing "/" now.

Finally it would be nice if we were able to edit the text that currently says:
"Select an item and press Enter=accept Esc=cancel /=filter"

Additional context
Add any other context or screenshots about the feature request here.

Here is a picture where what I would like to add is "a. " in front of the line with .pylint.d, "b. " in front of the line with .ipython, and so on.

Screenshot 2023-08-30 at 17 22 09

If I am pointed to the code that would need changing to implement this, I can try to take a look at it myself, but I don't really have any working experience with rust. Though I assume the above would hopefully be relatively simple?

@Danielkonge Danielkonge added the enhancement New feature or request label Aug 30, 2023
@wez
Copy link
Owner

wez commented Aug 30, 2023

These sound like reasonable requests.

If you feel like taking a crack at coding some of this, then I'd suggest starting with the alphabet, as that doesn't require changing any of the other config related structures to get it going.

It should be possible to re-use the logic from quick select, which is encapsulated in this function:

pub fn compute_labels_for_alphabet(alphabet: &str, num_matches: usize) -> Vec<String> {

You pass in the alphabet (eg: "1234567890abcdefghijklmnopqrstuvwxyz") and the number of entries in the list (or rather, the number of lines that can seen on the screen) and it will return a list of corresponding strings that represent each entry in the list.

Then the logic over here in the selector that matches a label by number:

}) if !self.filtering && c >= '1' && c <= '9' => {
if self.launch(self.top_row + (c as u32 - '1' as u32) as usize) {
break;
}
}

would need to be modified in a way that is similar to the quickselect logic for matching against the labels and resolving the index in the list:

(KeyCode::Char(c), KeyModifiers::NONE) | (KeyCode::Char(c), KeyModifiers::SHIFT) => {
// Type to add to the selection
let mut r = self.renderer.lock();
r.selection.push(c);
let lowered = r.selection.to_lowercase();
let paste = lowered != r.selection;
if let Some(result_index) = r.by_label.get(&lowered).cloned() {
r.select_and_copy_match_number(result_index, paste);
r.close();
}
}

this particular code is accumulating the keypress into a string, then looking up that string in the list of labels to see if there is a match.

I'd be happy to give more feedback on a PR if you want to iterate that way!

@wez
Copy link
Owner

wez commented Aug 30, 2023

Why use compute_labels_for_alphabet instead of expanding and hard coding the existing logic? The reason is that it allows the user to specify their preferred alphabet. They may want to use alpha symbols from the home row in their preferred keyboard layout, for example.

@Danielkonge
Copy link
Contributor Author

I have made a pull request now: #4227

@wez wez closed this as completed in 525080b Sep 22, 2023
wez added a commit that referenced this issue Sep 22, 2023
@github-actions
Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants