Skip to content

Commit

Permalink
Add emacs-like cursor navigation to dateselect; fix lint (#187)
Browse files Browse the repository at this point in the history
* Add emacs-like cursor navigation to dataselect

Accept Ctrl-p and Ctrl-b as up and down. Additionally accept Ctrl-b
and Ctrl-f as left and right.

* Fix clippy lint for unwrap_or_default

Latest nightly clippy warns:

    warning: use of `unwrap_or_else` to construct default value
      --> inquire/src/prompts/multiselect/prompt.rs:67:14
       |
    67 |             .unwrap_or_else(BTreeSet::new);
       |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_or_default
       = note: `#[warn(clippy::unwrap_or_default)]` on by default

---------

Co-authored-by: Mikael Mello <git@mikaelmello.com>
  • Loading branch information
jasonish and mikaelmello authored Nov 1, 2023
1 parent 1949b47 commit 7ab1e94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
`Some(score)`: score determines the order of options, higher score, higher on the list of options.
- Implement fuzzy search as default on Select and MultiSelect prompts. [#176](https://github.com/mikaelmello/inquire/pull/176)
- Add new option on Select/MultiSelect prompts allowing to reset selection to the first item on filter-input changes. [#176](https://github.com/mikaelmello/inquire/pull/176)
- Keybindings Ctrl-p and Ctrl-n added for Up and Down actions
- Emacs-like keybindings added where applicable:
- Ctrl-p/Ctrl-n for up/down
- Ctrl-b/Ctrl-f for left/right
- Ctrl-j/Ctrl-g for enter/cancel
- Added 'with_starting_filter_input' to both Select and MultiSelect, which allows for setting an initial value to the filter section of the prompt.
- Keybindings Ctrl-j and Ctrl-g added for Enter and Cancel actions

### Fixes

Expand Down
16 changes: 12 additions & 4 deletions inquire/src/prompts/dateselect/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ impl InnerAction for DateSelectPromptAction {
}

let action = match key {
Key::Left(KeyModifiers::NONE) => Self::GoToPrevDay,
Key::Right(KeyModifiers::NONE) => Self::GoToNextDay,
Key::Up(KeyModifiers::NONE) => Self::GoToPrevWeek,
Key::Down(KeyModifiers::NONE) | Key::Tab => Self::GoToNextWeek,
Key::Left(KeyModifiers::NONE) | Key::Char('b', KeyModifiers::CONTROL) => {
Self::GoToPrevDay
}
Key::Right(KeyModifiers::NONE) | Key::Char('f', KeyModifiers::CONTROL) => {
Self::GoToNextDay
}
Key::Up(KeyModifiers::NONE) | Key::Char('p', KeyModifiers::CONTROL) => {
Self::GoToPrevWeek
}
Key::Down(KeyModifiers::NONE) | Key::Char('n', KeyModifiers::CONTROL) | Key::Tab => {
Self::GoToNextWeek
}
Key::Left(KeyModifiers::CONTROL) => Self::GoToPrevMonth,
Key::Right(KeyModifiers::CONTROL) => Self::GoToNextMonth,
Key::Up(KeyModifiers::CONTROL) => Self::GoToPrevYear,
Expand Down

0 comments on commit 7ab1e94

Please sign in to comment.