From a218aea244bf482cebfa9c0ac4dc0bfa61a60201 Mon Sep 17 00:00:00 2001 From: Tim Oram Date: Sun, 21 Jul 2024 20:52:58 -0230 Subject: [PATCH] Fix issue with handling of search input in list 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. --- CHANGELOG.md | 4 ++++ src/input/event_handler.rs | 21 +++++++++++++++++++++ src/input/input_options.rs | 6 ++++-- src/modules/list.rs | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aba8dfcac..cfb7f81b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/src/input/event_handler.rs b/src/input/event_handler.rs index 0a2621feb..c9319d6ca 100644 --- a/src/input/event_handler.rs +++ b/src/input/event_handler.rs @@ -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; @@ -115,6 +120,13 @@ impl EventHandler { }) } + fn handle_search_start(key_bindings: &KeyBindings, event: Event) -> Option { + key_bindings + .search_start + .contains(&event) + .then(|| Event::from(StandardEvent::SearchStart)) + } + fn handle_search(key_bindings: &KeyBindings, event: Event) -> Option { match event { e if key_bindings.search_next.contains(&e) => Some(Event::from(StandardEvent::SearchNext)), @@ -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()); diff --git a/src/input/input_options.rs b/src/input/input_options.rs index 3320a2e64..da884dfdd 100644 --- a/src/input/input_options.rs +++ b/src/input/input_options.rs @@ -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; } } diff --git a/src/modules/list.rs b/src/modules/list.rs index e1005353d..88196b08a 100644 --- a/src/modules/list.rs +++ b/src/modules/list.rs @@ -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 {