File tree Expand file tree Collapse file tree 5 files changed +30
-9
lines changed Expand file tree Collapse file tree 5 files changed +30
-9
lines changed Original file line number Diff line number Diff line change 1
1
#[ derive( Debug , PartialEq ) ]
2
2
pub ( crate ) enum Action {
3
+ Update ( String ) ,
3
4
Start ( String ) ,
4
5
Next ( String ) ,
5
6
Previous ( String ) ,
Original file line number Diff line number Diff line change 1
1
mod action;
2
- // mod options;
3
2
mod state;
4
3
#[ cfg( test) ]
5
4
mod tests;
@@ -9,7 +8,10 @@ use view::{LineSegment, ViewLine};
9
8
10
9
pub ( crate ) use self :: action:: Action as SearchBarAction ;
11
10
use crate :: {
12
- components:: { search_bar:: state:: State , shared:: EditableLine } ,
11
+ components:: {
12
+ search_bar:: state:: State ,
13
+ shared:: { EditAction , EditableLine } ,
14
+ } ,
13
15
events:: Event ,
14
16
} ;
15
17
@@ -93,10 +95,12 @@ impl SearchBar {
93
95
SearchBarAction :: Cancel
94
96
} ,
95
97
_ => {
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
98
103
}
99
- SearchBarAction :: None
100
104
} ,
101
105
}
102
106
}
Original file line number Diff line number Diff line change @@ -168,11 +168,27 @@ fn handle_event_search_start_active() {
168
168
}
169
169
170
170
#[ test]
171
- fn handle_event_other_active ( ) {
171
+ fn handle_event_other_active_without_change ( ) {
172
172
let mut search_bar = SearchBar :: new ( ) ;
173
173
search_bar. start_search ( Some ( "foo" ) ) ;
174
- let event = Event :: from ( 'a' ) ;
174
+ let event = Event :: from ( KeyCode :: Null ) ;
175
175
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
+ ) ;
176
192
assert_rendered_output ! (
177
193
& create_view_data( & search_bar) ,
178
194
"{BODY}" ,
Original file line number Diff line number Diff line change 1
1
mod editable_line;
2
2
3
- pub ( crate ) use editable_line:: EditableLine ;
3
+ pub ( crate ) use editable_line:: { EditAction , EditableLine } ;
Original file line number Diff line number Diff line change @@ -586,7 +586,7 @@ impl List {
586
586
self . search . cancel ( ) ;
587
587
return Some ( Results :: from ( event) ) ;
588
588
} ,
589
- SearchBarAction :: None => return None ,
589
+ SearchBarAction :: None | SearchBarAction :: Update ( _ ) => return None ,
590
590
}
591
591
drop ( todo_file) ;
592
592
You can’t perform that action at this time.
0 commit comments