diff --git a/src/core/src/modules/confirm_abort/mod.rs b/src/core/src/modules/confirm_abort/mod.rs index 2b9722d55..13d4c8628 100644 --- a/src/core/src/modules/confirm_abort/mod.rs +++ b/src/core/src/modules/confirm_abort/mod.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use input::InputOptions; use parking_lot::Mutex; -use todo_file::TodoFile; +use todo_file::{TodoFile, State as TodoFileState}; use view::{RenderContext, ViewData}; use crate::{ @@ -35,7 +35,10 @@ impl Module for ConfirmAbort { let mut results = Results::new(); match confirmed { Confirmed::Yes => { - self.todo_file.lock().set_lines(vec![]); + let todo_state = self.todo_file.lock().state().clone(); + if todo_state != TodoFileState::Edit { + self.todo_file.lock().set_lines(vec![]); + } results.exit_status(ExitStatus::Good); }, Confirmed::No => { @@ -133,4 +136,24 @@ mod tests { }, ); } + + #[test] + fn handle_event_yes_in_edit() { + module_test( + &["pick aaa comment"], + &[Event::from(MetaEvent::Yes)], + |mut test_context| { + let mut todo_file = test_context.take_todo_file(); + todo_file.set_state(TodoFileState::Edit); + + let mut module = create_confirm_abort(todo_file); + assert_results!( + test_context.handle_event(&mut module), + Artifact::Event(Event::from(MetaEvent::Yes)), + Artifact::ExitStatus(ExitStatus::Good) + ); + assert!(!module.todo_file.lock().is_empty()); + }, + ); + } } diff --git a/src/todo_file/src/lib.rs b/src/todo_file/src/lib.rs index 209a3c052..0c9c8632d 100644 --- a/src/todo_file/src/lib.rs +++ b/src/todo_file/src/lib.rs @@ -205,6 +205,12 @@ impl TodoFile { self.history.reset(); } + /// Set the rebase todo file state. + #[inline] + pub fn set_state(&mut self, state: State) { + self.state = state; + } + /// Load the rebase file from disk. /// /// # Errors @@ -235,7 +241,7 @@ impl TodoFile { }) .collect(); self.set_lines(lines?); - self.state = detect_state(&self.filepath)?; + self.set_state(detect_state(&self.filepath)?); Ok(()) }