Skip to content

Commit

Permalink
Fix issue with handling of search input in list
Browse files Browse the repository at this point in the history
The search input handling was incorrectly handling Esc and Enter inputs
when the search is not active. This has resulted in those keys being
unable to be used in keybindings.

This change updates the input handling, to use a "search start" input
option instead of the full search option.
  • Loading branch information
MitMaro committed Jul 21, 2024
1 parent 1812f6b commit a218aea
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/).

## [Unreleased]
### Fixed
- Fix issue with search input handling that blocked setting `Esc` and `Enter` in keybindings ([#935](https://github.com/MitMaro/git-interactive-rebase-tool/pull/935))

## [2.4.1] - 2024-06-26
### Fixed
- Renamed and copied file order reversed in show commit view ([#926](https://github.com/MitMaro/git-interactive-rebase-tool/pull/926))
Expand Down
21 changes: 21 additions & 0 deletions src/input/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ impl EventHandler {
}
}

if input_options.contains(InputOptions::SEARCH_START) {
if let Some(evt) = Self::handle_search_start(&self.key_bindings, event) {
return evt;
}
}
if input_options.contains(InputOptions::SEARCH) {
if let Some(evt) = Self::handle_search(&self.key_bindings, event) {
return evt;
Expand Down Expand Up @@ -115,6 +120,13 @@ impl EventHandler {
})
}

fn handle_search_start(key_bindings: &KeyBindings, event: Event) -> Option<Event> {
key_bindings
.search_start
.contains(&event)
.then(|| Event::from(StandardEvent::SearchStart))
}

fn handle_search(key_bindings: &KeyBindings, event: Event) -> Option<Event> {
match event {
e if key_bindings.search_next.contains(&e) => Some(Event::from(StandardEvent::SearchNext)),
Expand Down Expand Up @@ -273,6 +285,15 @@ mod tests {
assert_eq!(result, expected);
}

#[rstest]
#[case::search_start(Event::from('/'), Event::from(StandardEvent::SearchStart))]
#[case::other(Event::from('a'), Event::from(KeyCode::Null))]
fn search_start(#[case] event: Event, #[case] expected: Event) {
let event_handler = EventHandler::new(create_test_keybindings());
let result = event_handler.read_event(event, &InputOptions::SEARCH_START, |_, _| Event::from(KeyCode::Null));
assert_eq!(result, expected);
}

#[test]
fn help_event() {
let event_handler = EventHandler::new(create_test_keybindings());
Expand Down
6 changes: 4 additions & 2 deletions src/input/input_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ bitflags! {
const RESIZE = 0b0000_0010;
/// Enable undo and redo input handling
const UNDO_REDO = 0b0000_0100;
/// Search start
const SEARCH_START = 0b0000_1000;
/// Search handling
const SEARCH = 0b0000_1000;
const SEARCH = 0b0001_1000;
/// Help input handling
const HELP = 0b0001_0000;
const HELP = 0b0010_0000;
}
}
2 changes: 1 addition & 1 deletion src/modules/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::{
const INPUT_OPTIONS: InputOptions = InputOptions::UNDO_REDO
.union(InputOptions::RESIZE)
.union(InputOptions::HELP)
.union(InputOptions::SEARCH);
.union(InputOptions::SEARCH_START);

#[derive(Debug, PartialEq, Eq)]
enum ListState {
Expand Down

0 comments on commit a218aea

Please sign in to comment.