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

Enable the ability to sort the which key #652

Closed
1 task
taylo2allen opened this issue Feb 9, 2024 · 9 comments · Fixed by #662
Closed
1 task

Enable the ability to sort the which key #652

taylo2allen opened this issue Feb 9, 2024 · 9 comments · Fixed by #662
Labels
feature New feature request good first issue Good for newcomers

Comments

@taylo2allen
Copy link

taylo2allen commented Feb 9, 2024

Is your feature request related to a problem? Please describe

No response

Will you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

In the yazi.toml add [which] that has the methods sort_by & sort_sensitive that allows you to sort the which menu.

Describe alternatives you've considered

One way for me to sort the which menu is to physically go to my keymap.toml and sort my keybinding definitions.

Additional context

No response

@taylo2allen taylo2allen added the feature New feature request label Feb 9, 2024
@sxyazi
Copy link
Owner

sxyazi commented Feb 10, 2024

Sounds good to me. Does anyone want to give it a try?

@sxyazi sxyazi added the good first issue Good for newcomers label Feb 10, 2024
@abhaysp95
Copy link
Contributor

@taylo2allen I completed the rust basics and I have just started using Yazi. I would like to help. I want to understand few points for this issue:

  • What is meant by sorting the which key ?
  • Currently, sort_by & sort_sensitive option are under [manager]. What is wanted is to created a new table named [which] ?
  • Can you kindly show the steps of what you are doing for 'alternatives' you mentioned

CC: @sxyazi

@sxyazi
Copy link
Owner

sxyazi commented Feb 11, 2024

Thank you very much for the help! @abhaysp95

I'll wait for OP's reply and provide more detailed suggestions on how to implement it :)

@sxyazi sxyazi added the waiting on op Waiting for more information from the original poster label Feb 11, 2024
@taylo2allen
Copy link
Author

I have a lot of keykindings to move to different folders on my system for example:
`
{ on = [ "g", "C" ], exec = "cd ~/.config", desc = "GoTo: ~/.config" },
{ on = [ "g", "c", "b" ], exec = "cd ~/.config/xmobar", desc = "GoTo: ~/C/xmobar" },
{ on = [ "g", "c", "f" ], exec = "cd ~/.config/fish", desc = "GoTo: ~/C/fish" },
{ on = [ "g", "c", "q" ], exec = "cd ~/.config/qutebrowser", desc = "GoTo: ~/C/qutebrowser" },
{ on = [ "g", "c", "r" ], exec = "cd ~/.config/ranger", desc = "GoTo: ~/C/ranger" },
{ on = [ "g", "c", "x" ], exec = "cd ~/.config/xmonad", desc = "GoTo: ~/C/xmonad" },

`
in the code above I use "g", "c" as a leader key to go to all of the folders I have bookmarked in my .config folder. When I press the "g" key the whichkey menu pops up with the next possible keys you can press, I would like to sort the options for keybindings like "c", "b" to be shown first before "c", "x". The only way I found to sort the list of keybindings is to shift the definitions around in my keymap.toml file.
2024-02-10_20-59

@github-actions github-actions bot removed the waiting on op Waiting for more information from the original poster label Feb 11, 2024
@abhaysp95
Copy link
Contributor

@taylo2allen Okay. So this has nothing to do with sorting options present under [manager]. Got it.

  • sort_by can only have "alphabetically" and "alphabetically (reverse)', right ? or do you have some more options in mind ?

@sxyazi I'm going through the source code, I'll try to implement it in the free time I get between my work. This is a nice project and looks like a fun way to get good with Rust.

@taylo2allen
Copy link
Author

Thank you for taking a look @sxyazi @abhaysp95 I believe this would be possible to implement this feature with the sort function found in yazi-core/src/folder/sorter.rs instead of feeding two files into the sort fn you can pass two items in the list of possible keybindings before the text can be displayed on the screen.

@sxyazi
Copy link
Owner

sxyazi commented Feb 11, 2024

I'm going through the source code, I'll try to implement it in the free time I get between my work. This is a nice project and looks like a fun way to get good with Rust.

Thanks.

I believe this would be possible to implement this feature with the sort function found in yazi-core/src/folder/sorter.rs instead of feeding two files into the sort fn you can pass two items in the list of possible keybindings before the text can be displayed on the screen.

No, it's a file-specific sorting, not applicable to keys, as keys don't have file-specific attributes like modification time, creation time, extension, etc., and they are also hard to share. Therefore, the simplest way is to directly invoke natsort function to sort.

We can add the sorting logic after

self.cands = KEYMAP
.get(layer)
.iter()
.filter(|c| c.on.len() > 1 && &c.on[0] == key)
.map(|c| c.into())
.collect();

It's the only place that needs to change, with:

  • sort_by (String): "key" or "description"
  • sort_sensitive (Boolean): Whether sort case-sensitively

@abhaysp95
Copy link
Contributor

@taylo2allen I have created the PR #662 . You can try to confirm the behaviour if it fits you

CC: @sxyazi

Copy link

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 Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New feature request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants