Skip to content

Commit 63bdfb3

Browse files
committed
Add update action on content change to search bar
1 parent 7405f78 commit 63bdfb3

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

src/core/src/components/search_bar/action.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#[derive(Debug, PartialEq)]
22
pub(crate) enum Action {
3+
Update(String),
34
Start(String),
45
Next(String),
56
Previous(String),

src/core/src/components/search_bar/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
mod action;
2-
// mod options;
32
mod state;
43
#[cfg(test)]
54
mod tests;
@@ -9,7 +8,10 @@ use view::{LineSegment, ViewLine};
98

109
pub(crate) use self::action::Action as SearchBarAction;
1110
use crate::{
12-
components::{search_bar::state::State, shared::EditableLine},
11+
components::{
12+
search_bar::state::State,
13+
shared::{EditAction, EditableLine},
14+
},
1315
events::Event,
1416
};
1517

@@ -93,10 +95,12 @@ impl SearchBar {
9395
SearchBarAction::Cancel
9496
},
9597
_ => {
96-
if self.state == State::Editing {
97-
let _ = self.editable_line.handle_event(event);
98+
if self.state == State::Editing && self.editable_line.handle_event(event) == EditAction::ContentUpdate {
99+
SearchBarAction::Update(String::from(self.editable_line.get_content()))
100+
}
101+
else {
102+
SearchBarAction::None
98103
}
99-
SearchBarAction::None
100104
},
101105
}
102106
}

src/core/src/components/search_bar/tests.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,27 @@ fn handle_event_search_start_active() {
168168
}
169169

170170
#[test]
171-
fn handle_event_other_active() {
171+
fn handle_event_other_active_without_change() {
172172
let mut search_bar = SearchBar::new();
173173
search_bar.start_search(Some("foo"));
174-
let event = Event::from('a');
174+
let event = Event::from(KeyCode::Null);
175175
assert_eq!(search_bar.handle_event(event), SearchBarAction::None);
176+
assert_rendered_output!(
177+
&create_view_data(&search_bar),
178+
"{BODY}",
179+
"{Normal}/foo{Normal,Underline}"
180+
);
181+
}
182+
183+
#[test]
184+
fn handle_event_other_active_with_change() {
185+
let mut search_bar = SearchBar::new();
186+
search_bar.start_search(Some("foo"));
187+
let event = Event::from('a');
188+
assert_eq!(
189+
search_bar.handle_event(event),
190+
SearchBarAction::Update(String::from("fooa"))
191+
);
176192
assert_rendered_output!(
177193
&create_view_data(&search_bar),
178194
"{BODY}",

src/core/src/components/shared/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
mod editable_line;
22

3-
pub(crate) use editable_line::EditableLine;
3+
pub(crate) use editable_line::{EditAction, EditableLine};

src/core/src/modules/list/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ impl List {
586586
self.search.cancel();
587587
return Some(Results::from(event));
588588
},
589-
SearchBarAction::None => return None,
589+
SearchBarAction::None | SearchBarAction::Update(_) => return None,
590590
}
591591
drop(todo_file);
592592

0 commit comments

Comments
 (0)