Skip to content

Commit

Permalink
When editing todo, dont clear
Browse files Browse the repository at this point in the history
  • Loading branch information
forivall committed Jul 28, 2023
1 parent 91da8fb commit ca7f968
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
27 changes: 25 additions & 2 deletions src/core/src/modules/confirm_abort/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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());
},
);
}
}
8 changes: 7 additions & 1 deletion src/todo_file/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(())
}

Expand Down

0 comments on commit ca7f968

Please sign in to comment.