Skip to content

Commit b0f5a48

Browse files
committed
When editing todo, dont clear
1 parent 4953c5f commit b0f5a48

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/modules/confirm_abort.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
input::{Event, InputOptions, KeyBindings},
88
module::{ExitStatus, Module, State},
99
process::Results,
10-
todo_file::TodoFile,
10+
todo_file::{TodoFile, State as TodoFileState},
1111
view::{RenderContext, ViewData},
1212
};
1313

@@ -34,7 +34,10 @@ impl Module for ConfirmAbort {
3434
let mut results = Results::new();
3535
match confirmed {
3636
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+
}
3841
results.exit_status(ExitStatus::Good);
3942
},
4043
Confirmed::No => {
@@ -135,4 +138,24 @@ mod tests {
135138
},
136139
);
137140
}
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+
}
138161
}

src/todo_file.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ impl TodoFile {
8888
self.history.reset();
8989
}
9090

91+
/// Set the rebase todo file state.
92+
#[inline]
93+
pub fn set_state(&mut self, state: State) {
94+
self.state = state;
95+
}
96+
9197
/// Load the rebase file from disk.
9298
///
9399
/// # Errors
@@ -117,7 +123,7 @@ impl TodoFile {
117123
})
118124
.collect();
119125
self.set_lines(lines?);
120-
self.state = detect_state(&self.filepath)?;
126+
self.set_state(detect_state(&self.filepath)?);
121127
Ok(())
122128
}
123129

0 commit comments

Comments
 (0)