@@ -7,7 +7,7 @@ use crate::{
7
7
input:: { Event , InputOptions , KeyBindings } ,
8
8
module:: { ExitStatus , Module , State } ,
9
9
process:: Results ,
10
- todo_file:: TodoFile ,
10
+ todo_file:: { TodoFile , State as TodoFileState } ,
11
11
view:: { RenderContext , ViewData } ,
12
12
} ;
13
13
@@ -34,7 +34,10 @@ impl Module for ConfirmAbort {
34
34
let mut results = Results :: new ( ) ;
35
35
match confirmed {
36
36
Confirmed :: Yes => {
37
- self . todo_file . lock ( ) . set_lines ( vec ! [ ] ) ;
37
+ let todo_state = self . todo_file . lock ( ) . state ( ) . clone ( ) ;
38
+ if todo_state != TodoFileState :: Edit {
39
+ self . todo_file . lock ( ) . set_lines ( vec ! [ ] ) ;
40
+ }
38
41
results. exit_status ( ExitStatus :: Good ) ;
39
42
} ,
40
43
Confirmed :: No => {
@@ -135,4 +138,24 @@ mod tests {
135
138
} ,
136
139
) ;
137
140
}
141
+
142
+ #[ test]
143
+ fn handle_event_yes_in_edit ( ) {
144
+ module_test (
145
+ & [ "pick aaa comment" ] ,
146
+ & [ Event :: from ( MetaEvent :: Yes ) ] ,
147
+ |mut test_context| {
148
+ let mut todo_file = test_context. take_todo_file ( ) ;
149
+ todo_file. set_state ( TodoFileState :: Edit ) ;
150
+
151
+ let mut module = create_confirm_abort ( todo_file) ;
152
+ assert_results ! (
153
+ test_context. handle_event( & mut module) ,
154
+ Artifact :: Event ( Event :: from( MetaEvent :: Yes ) ) ,
155
+ Artifact :: ExitStatus ( ExitStatus :: Good )
156
+ ) ;
157
+ assert ! ( !module. todo_file. lock( ) . is_empty( ) ) ;
158
+ } ,
159
+ ) ;
160
+ }
138
161
}
0 commit comments