Skip to content

When editing in the middle of a rebase, dont clear on quit #873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding .vscode to the .gitignore file?

12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"editor.insertSpaces": false,
"editor.tabSize": 4,
"files.insertFinalNewline": true,
"[yaml]": {
"editor.insertSpaces": true,
"editor.tabSize": 2,
},
"[markdown]": {
"editor.insertSpaces": true,
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ Other platforms are not officially supported. Some platforms have community supp

### Install Rust

To start developing the project, you will need to [install Rust][install-rust], which can generally be done using [rustup].
To start developing the project, you will need to [install Rust][install-rust], which should be done using [rustup].

### Setup

Expand Down
2 changes: 2 additions & 0 deletions readme/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ Most keys can be changed to any printable character or supported special charact
| `inputActionPick` | p | String | Key for setting action to pick |
| `inputActionReword` | r | String | Key for setting action to reword |
| `inputActionSquash` | s | String | Key for setting action to squash |
| `inputActionCut` | x | String | Key for setting action to cut (git-revise) |
| `inputActionIndex` | i | String | Key for setting action to index (git-revise) |
| `inputConfirmNo` | n | String | Key for rejecting a confirmation |
| `inputConfirmYes` | y | String | Key for confirming a confirmation |
| `inputEdit` | E | String | Key for entering edit mode |
Expand Down
7 changes: 7 additions & 0 deletions src/config/key_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ pub(crate) struct KeyBindings {
pub(crate) abort: Vec<String>,
/// Key bindings for the break action.
pub(crate) action_break: Vec<String>,
/// Key bindings for the cut action.
pub(crate) action_cut: Vec<String>,
/// Key bindings for the drop action.
pub(crate) action_drop: Vec<String>,
/// Key bindings for the edit action.
pub(crate) action_edit: Vec<String>,
/// Key bindings for the fixup action.
pub(crate) action_fixup: Vec<String>,
/// Key bindings for the index action.
pub(crate) action_index: Vec<String>,
/// Key bindings for the pick action.
pub(crate) action_pick: Vec<String>,
/// Key bindings for the reword action.
Expand Down Expand Up @@ -126,9 +130,11 @@ impl KeyBindings {
Ok(Self {
abort: get_input(git_config, "interactive-rebase-tool.inputAbort", "q")?,
action_break: get_input(git_config, "interactive-rebase-tool.inputActionBreak", "b")?,
action_cut: get_input(git_config, "interactive-rebase-tool.inputActionCut", "x")?,
action_drop: get_input(git_config, "interactive-rebase-tool.inputActionDrop", "d")?,
action_edit: get_input(git_config, "interactive-rebase-tool.inputActionEdit", "e")?,
action_fixup: get_input(git_config, "interactive-rebase-tool.inputActionFixup", "f")?,
action_index: get_input(git_config, "interactive-rebase-tool.inputActionIndex", "i")?,
action_pick: get_input(git_config, "interactive-rebase-tool.inputActionPick", "p")?,
action_reword: get_input(git_config, "interactive-rebase-tool.inputActionReword", "r")?,
action_squash: get_input(git_config, "interactive-rebase-tool.inputActionSquash", "s")?,
Expand Down Expand Up @@ -243,6 +249,7 @@ mod tests {
config_test!(action_drop, "inputActionDrop", "d");
config_test!(action_edit, "inputActionEdit", "e");
config_test!(action_fixup, "inputActionFixup", "f");
config_test!(action_index, "inputActionIndex", "i");
config_test!(action_pick, "inputActionPick", "p");
config_test!(action_reword, "inputActionReword", "r");
config_test!(action_squash, "inputActionSquash", "s");
Expand Down
7 changes: 7 additions & 0 deletions src/config/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub(crate) struct Theme {
pub(crate) character_vertical_spacing: String,
/// The color for the break action.
pub(crate) color_action_break: Color,
/// The color for the cut action.
pub(crate) color_action_cut: Color,
/// The color for the drop action.
pub(crate) color_action_drop: Color,
/// The color for the edit action.
Expand All @@ -39,6 +41,8 @@ pub(crate) struct Theme {
pub(crate) color_action_exec: Color,
/// The color for the fixup action.
pub(crate) color_action_fixup: Color,
/// The color for the fixup action.
pub(crate) color_action_index: Color,
/// The color for the pick action.
pub(crate) color_action_pick: Color,
/// The color for the reword action.
Expand Down Expand Up @@ -83,10 +87,12 @@ impl Theme {
"~",
)?,
color_action_break: get_color(git_config, "interactive-rebase-tool.breakColor", Color::LightWhite)?,
color_action_cut: get_color(git_config, "interactive-rebase-tool.cutColor", Color::DarkRed)?,
color_action_drop: get_color(git_config, "interactive-rebase-tool.dropColor", Color::LightRed)?,
color_action_edit: get_color(git_config, "interactive-rebase-tool.editColor", Color::LightBlue)?,
color_action_exec: get_color(git_config, "interactive-rebase-tool.execColor", Color::LightWhite)?,
color_action_fixup: get_color(git_config, "interactive-rebase-tool.fixupColor", Color::LightMagenta)?,
color_action_index: get_color(git_config, "interactive-rebase-tool.indexColor", Color::DarkGreen)?,
color_action_pick: get_color(git_config, "interactive-rebase-tool.pickColor", Color::LightGreen)?,
color_action_reword: get_color(git_config, "interactive-rebase-tool.rewordColor", Color::LightYellow)?,
color_action_squash: get_color(git_config, "interactive-rebase-tool.squashColor", Color::LightCyan)?,
Expand Down Expand Up @@ -204,6 +210,7 @@ mod tests {
config_test!(color_action_edit, "editColor", Color::LightBlue);
config_test!(color_action_exec, "execColor", Color::LightWhite);
config_test!(color_action_fixup, "fixupColor", Color::LightMagenta);
config_test!(color_action_index, "indexColor", Color::DarkGreen);
config_test!(color_action_pick, "pickColor", Color::LightGreen);
config_test!(color_action_reword, "rewordColor", Color::LightYellow);
config_test!(color_action_squash, "squashColor", Color::LightCyan);
Expand Down
27 changes: 27 additions & 0 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ use crate::config::Theme;
#[derive(Debug)]
pub(crate) struct Display<T: Tui> {
action_break: (Colors, Colors),
action_cut: (Colors, Colors),
action_drop: (Colors, Colors),
action_edit: (Colors, Colors),
action_exec: (Colors, Colors),
action_fixup: (Colors, Colors),
action_index: (Colors, Colors),
action_label: (Colors, Colors),
action_merge: (Colors, Colors),
action_pick: (Colors, Colors),
Expand Down Expand Up @@ -77,6 +79,12 @@ impl<T: Tui> Display<T> {
theme.color_background,
theme.color_selected_background,
);
let action_cut = register_selectable_color_pairs(
color_mode,
theme.color_action_cut,
theme.color_background,
theme.color_selected_background,
);
let action_drop = register_selectable_color_pairs(
color_mode,
theme.color_action_drop,
Expand All @@ -101,6 +109,12 @@ impl<T: Tui> Display<T> {
theme.color_background,
theme.color_selected_background,
);
let action_index = register_selectable_color_pairs(
color_mode,
theme.color_action_index,
theme.color_background,
theme.color_selected_background,
);
let action_pick = register_selectable_color_pairs(
color_mode,
theme.color_action_pick,
Expand Down Expand Up @@ -176,10 +190,12 @@ impl<T: Tui> Display<T> {

Self {
action_break,
action_cut,
action_drop,
action_edit,
action_exec,
action_fixup,
action_index,
action_label,
action_merge,
action_pick,
Expand Down Expand Up @@ -236,10 +252,12 @@ impl<T: Tui> Display<T> {
if selected {
match color {
DisplayColor::ActionBreak => self.action_break.1,
DisplayColor::ActionCut => self.action_cut.1,
DisplayColor::ActionDrop => self.action_drop.1,
DisplayColor::ActionEdit => self.action_edit.1,
DisplayColor::ActionExec => self.action_exec.1,
DisplayColor::ActionFixup => self.action_fixup.1,
DisplayColor::ActionIndex => self.action_index.1,
DisplayColor::ActionPick => self.action_pick.1,
DisplayColor::ActionReword => self.action_reword.1,
DisplayColor::ActionSquash => self.action_squash.1,
Expand All @@ -259,10 +277,12 @@ impl<T: Tui> Display<T> {
else {
match color {
DisplayColor::ActionBreak => self.action_break.0,
DisplayColor::ActionCut => self.action_cut.0,
DisplayColor::ActionDrop => self.action_drop.0,
DisplayColor::ActionEdit => self.action_edit.0,
DisplayColor::ActionExec => self.action_exec.0,
DisplayColor::ActionFixup => self.action_fixup.0,
DisplayColor::ActionIndex => self.action_index.0,
DisplayColor::ActionPick => self.action_pick.0,
DisplayColor::ActionReword => self.action_reword.0,
DisplayColor::ActionSquash => self.action_squash.0,
Expand Down Expand Up @@ -427,6 +447,13 @@ mod tests {
CrosstermColor::Magenta,
CrosstermColor::AnsiValue(237)
)]
#[case::action_index(DisplayColor::ActionIndex, false, CrosstermColor::DarkGreen, CrosstermColor::Reset)]
#[case::action_index_selected(
DisplayColor::ActionIndex,
true,
CrosstermColor::DarkGreen,
CrosstermColor::AnsiValue(237)
)]
#[case::action_pick(DisplayColor::ActionPick, false, CrosstermColor::Green, CrosstermColor::Reset)]
#[case::action_pick_selected(
DisplayColor::ActionPick,
Expand Down
4 changes: 4 additions & 0 deletions src/display/display_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
pub(crate) enum DisplayColor {
/// The color for the break action.
ActionBreak,
/// The color for the cut action.
ActionCut,
/// The color for the drop action.
ActionDrop,
/// The color for the edit action.
Expand All @@ -12,6 +14,8 @@ pub(crate) enum DisplayColor {
ActionExec,
/// The color for the fixup action.
ActionFixup,
/// The color for the index action.
ActionIndex,
/// The color for the pick action.
ActionPick,
/// The color for the reword action.
Expand Down
6 changes: 6 additions & 0 deletions src/input/key_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ pub(crate) struct KeyBindings {
pub(crate) abort: Vec<Event>,
/// Key bindings for the break action.
pub(crate) action_break: Vec<Event>,
/// Key bindings for the cut action.
pub(crate) action_cut: Vec<Event>,
/// Key bindings for the drop action.
pub(crate) action_drop: Vec<Event>,
/// Key bindings for the edit action.
pub(crate) action_edit: Vec<Event>,
/// Key bindings for the fixup action.
pub(crate) action_fixup: Vec<Event>,
/// Key bindings for the index action.
pub(crate) action_index: Vec<Event>,
/// Key bindings for the pick action.
pub(crate) action_pick: Vec<Event>,
/// Key bindings for the reword action.
Expand Down Expand Up @@ -121,9 +125,11 @@ impl KeyBindings {
search_previous: map_keybindings(&key_bindings.search_previous),
abort: map_keybindings(&key_bindings.abort),
action_break: map_keybindings(&key_bindings.action_break),
action_cut: map_keybindings(&key_bindings.action_cut),
action_drop: map_keybindings(&key_bindings.action_drop),
action_edit: map_keybindings(&key_bindings.action_edit),
action_fixup: map_keybindings(&key_bindings.action_fixup),
action_index: map_keybindings(&key_bindings.action_index),
action_pick: map_keybindings(&key_bindings.action_pick),
action_reword: map_keybindings(&key_bindings.action_reword),
action_squash: map_keybindings(&key_bindings.action_squash),
Expand Down
4 changes: 4 additions & 0 deletions src/input/standard_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ pub(crate) enum StandardEvent {
ForceRebase,
/// The break action meta event.
ActionBreak,
/// The cut (git-revise) action meta event.
ActionCut,
/// The drop action meta event.
ActionDrop,
/// The edit action meta event.
ActionEdit,
/// The fixup action meta event.
ActionFixup,
/// The index (git-revise) action meta event.
ActionIndex,
/// The pick action meta event.
ActionPick,
/// The reword action meta event.
Expand Down
27 changes: 25 additions & 2 deletions src/modules/confirm_abort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
input::{Event, InputOptions, KeyBindings},
module::{ExitStatus, Module, State},
process::Results,
todo_file::TodoFile,
todo_file::{TodoFile, State as TodoFileState},
view::{RenderContext, ViewData},
};

Expand All @@ -34,7 +34,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 @@ -135,4 +138,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());
},
);
}
}
4 changes: 4 additions & 0 deletions src/modules/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,11 @@ impl List {
match event {
e if key_bindings.abort.contains(&e) => Event::from(StandardEvent::Abort),
e if key_bindings.action_break.contains(&e) => Event::from(StandardEvent::ActionBreak),
e if key_bindings.action_cut.contains(&e) => Event::from(StandardEvent::ActionCut),
e if key_bindings.action_drop.contains(&e) => Event::from(StandardEvent::ActionDrop),
e if key_bindings.action_edit.contains(&e) => Event::from(StandardEvent::ActionEdit),
e if key_bindings.action_fixup.contains(&e) => Event::from(StandardEvent::ActionFixup),
e if key_bindings.action_index.contains(&e) => Event::from(StandardEvent::ActionIndex),
e if key_bindings.action_pick.contains(&e) => Event::from(StandardEvent::ActionPick),
e if key_bindings.action_reword.contains(&e) => Event::from(StandardEvent::ActionReword),
e if key_bindings.action_squash.contains(&e) => Event::from(StandardEvent::ActionSquash),
Expand Down Expand Up @@ -642,9 +644,11 @@ impl List {
Event::Standard(standard_event) => {
match standard_event {
StandardEvent::Abort => self.abort(&mut results),
StandardEvent::ActionCut => self.set_selected_line_action(Action::Cut),
StandardEvent::ActionDrop => self.set_selected_line_action(Action::Drop),
StandardEvent::ActionEdit => self.set_selected_line_action(Action::Edit),
StandardEvent::ActionFixup => self.set_selected_line_action(Action::Fixup),
StandardEvent::ActionIndex => self.set_selected_line_action(Action::Index),
StandardEvent::ActionPick => self.set_selected_line_action(Action::Pick),
StandardEvent::ActionReword => self.set_selected_line_action(Action::Reword),
StandardEvent::ActionSquash => self.set_selected_line_action(Action::Squash),
Expand Down
8 changes: 6 additions & 2 deletions src/modules/list/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,23 @@ impl Searchable for Search {

let has_hash_match = match action {
Action::Break | Action::Noop | Action::Label | Action::Reset | Action::Merge | Action::Exec => false,
Action::Drop
Action::Cut
| Action::Drop
| Action::Edit
| Action::Fixup
| Action::Index
| Action::Pick
| Action::Reword
| Action::Squash
| Action::UpdateRef => line.get_hash().starts_with(term),
};
let has_content_match = match action {
Action::Break | Action::Noop => false,
Action::Drop
Action::Cut
| Action::Drop
| Action::Edit
| Action::Fixup
| Action::Index
| Action::Pick
| Action::Reword
| Action::Squash
Expand Down
4 changes: 4 additions & 0 deletions src/modules/list/tests/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ fn normal_mode_help() {
" s |Set selected commits to be squashed",
" f |Set selected commits to be fixed-up",
" d |Set selected commits to be dropped",
" x |Set selected commits to be cut / split (git-revise)",
" i |Set selected commits to be staged in the index (git-revise)",
" E |Edit an exec, label, reset or merge action's content",
" I |Insert a new line",
" Delete |Completely remove the selected lines",
Expand Down Expand Up @@ -105,6 +107,8 @@ fn visual_mode_help() {
" s |Set selected commits to be squashed",
" f |Set selected commits to be fixed-up",
" d |Set selected commits to be dropped",
" x |Set selected commits to be cut / split (git-revise)",
" i |Set selected commits to be staged in the index (git-revise)",
" Delete |Completely remove the selected lines",
" Controlz|Undo the last change",
" Controly|Redo the previous undone change",
Expand Down
Loading