Skip to content

Commit a218aea

Browse files
committed
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.
1 parent 1812f6b commit a218aea

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

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

6+
## [Unreleased]
7+
### Fixed
8+
- 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))
9+
610
## [2.4.1] - 2024-06-26
711
### Fixed
812
- Renamed and copied file order reversed in show commit view ([#926](https://github.com/MitMaro/git-interactive-rebase-tool/pull/926))

src/input/event_handler.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ impl EventHandler {
3737
}
3838
}
3939

40+
if input_options.contains(InputOptions::SEARCH_START) {
41+
if let Some(evt) = Self::handle_search_start(&self.key_bindings, event) {
42+
return evt;
43+
}
44+
}
4045
if input_options.contains(InputOptions::SEARCH) {
4146
if let Some(evt) = Self::handle_search(&self.key_bindings, event) {
4247
return evt;
@@ -115,6 +120,13 @@ impl EventHandler {
115120
})
116121
}
117122

123+
fn handle_search_start(key_bindings: &KeyBindings, event: Event) -> Option<Event> {
124+
key_bindings
125+
.search_start
126+
.contains(&event)
127+
.then(|| Event::from(StandardEvent::SearchStart))
128+
}
129+
118130
fn handle_search(key_bindings: &KeyBindings, event: Event) -> Option<Event> {
119131
match event {
120132
e if key_bindings.search_next.contains(&e) => Some(Event::from(StandardEvent::SearchNext)),
@@ -273,6 +285,15 @@ mod tests {
273285
assert_eq!(result, expected);
274286
}
275287

288+
#[rstest]
289+
#[case::search_start(Event::from('/'), Event::from(StandardEvent::SearchStart))]
290+
#[case::other(Event::from('a'), Event::from(KeyCode::Null))]
291+
fn search_start(#[case] event: Event, #[case] expected: Event) {
292+
let event_handler = EventHandler::new(create_test_keybindings());
293+
let result = event_handler.read_event(event, &InputOptions::SEARCH_START, |_, _| Event::from(KeyCode::Null));
294+
assert_eq!(result, expected);
295+
}
296+
276297
#[test]
277298
fn help_event() {
278299
let event_handler = EventHandler::new(create_test_keybindings());

src/input/input_options.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ bitflags! {
1010
const RESIZE = 0b0000_0010;
1111
/// Enable undo and redo input handling
1212
const UNDO_REDO = 0b0000_0100;
13+
/// Search start
14+
const SEARCH_START = 0b0000_1000;
1315
/// Search handling
14-
const SEARCH = 0b0000_1000;
16+
const SEARCH = 0b0001_1000;
1517
/// Help input handling
16-
const HELP = 0b0001_0000;
18+
const HELP = 0b0010_0000;
1719
}
1820
}

src/modules/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use crate::{
4040
const INPUT_OPTIONS: InputOptions = InputOptions::UNDO_REDO
4141
.union(InputOptions::RESIZE)
4242
.union(InputOptions::HELP)
43-
.union(InputOptions::SEARCH);
43+
.union(InputOptions::SEARCH_START);
4444

4545
#[derive(Debug, PartialEq, Eq)]
4646
enum ListState {

0 commit comments

Comments
 (0)