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

Add vim mode to FuzzySelect #259

Merged
merged 4 commits into from May 21, 2023
Merged

Conversation

damymetzke
Copy link
Contributor

This pull request introduces a vim mode to FuzzySelect.
Vim mode works as follows:

  1. The user can press Escape to enter vim mode
  2. The user can use hjkl to navigate
  3. The user can still select with Enter, or press i/a to enter more text

This is based on the vim mode from https://github.com/go-survey/survey.

To achieve this I've added the following changes:

  • Keep track of vim_mode.
  • Add support for hjkl keys, only when vim_mode is true.
  • Add the FuzzySelect::enable_vim_mode method.

These changes have the following benefits:

  • They allow vim users to use vim bindings, even in a fuzzy select.
  • The behavior is opt-in, so other users won't even notice.
  • The behavior is the same as many other tools, one example being Telescope for Neovim.

I hope my contribution can be of use!

Add configuration option to enable vim mode to `FuzzySelect`
src/prompts/fuzzy_select.rs Outdated Show resolved Hide resolved
src/prompts/fuzzy_select.rs Outdated Show resolved Hide resolved
- Rename `FuzzySelect::enable_vim_mode` to `FuzzySelect::vim_mode`.
- Implement quitting in vim_mode.
- Remove `vim_mode = false` when a character is entered.
@@ -209,6 +221,8 @@ impl FuzzySelect<'_> {

term.hide_cursor()?;

let mut vim_mode = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this default to enable_vim_mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not. enable_vim_mode is meant to fully disable vim mode; the vim_mode variable keeps track of when you are entering text or when vim bindings are used. Typically you'd fuzzy find first, then use vim mode, So I think it should always start with no vim mode.

src/prompts/fuzzy_select.rs Outdated Show resolved Hide resolved
Change the quit key to be 'q' instead of Escape.
@pksunkara pksunkara merged commit c8cdaf3 into console-rs:master May 21, 2023
7 checks passed
@damymetzke damymetzke deleted the fuzzy-select-vim branch May 21, 2023 10:31
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.

None yet

2 participants