summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Oram <dev@mitmaro.ca>2022-11-26 22:15:28 -0330
committerTim Oram <dev@mitmaro.ca>2022-11-27 22:43:21 -0330
commit84b0afd7f36d3ad1530cd82dec639b5fff86a73d (patch)
tree7f8864531295c7dc2c9e68f73b13a58cf2c8e913
parentb2fc83657dc2a893e384110e73778988f975cb5a (diff)
Add display and toggle of fixup flags in list view
-rw-r--r--src/config/src/key_bindings.rs12
-rw-r--r--src/core/src/events/app_key_bindings.rs6
-rw-r--r--src/core/src/events/meta_event.rs4
-rw-r--r--src/core/src/modules/list/mod.rs38
-rw-r--r--src/core/src/modules/list/tests/mod.rs1
-rw-r--r--src/core/src/modules/list/tests/read_event.rs25
-rw-r--r--src/core/src/modules/list/tests/render.rs26
-rw-r--r--src/core/src/modules/list/tests/toggle_option.rs50
-rw-r--r--src/core/src/modules/list/utils.rs23
-rw-r--r--src/core/src/testutil/create_test_keybindings.rs2
10 files changed, 169 insertions, 18 deletions
diff --git a/src/config/src/key_bindings.rs b/src/config/src/key_bindings.rs
index dfec777..ce6fd26 100644
--- a/src/config/src/key_bindings.rs
+++ b/src/config/src/key_bindings.rs
@@ -106,6 +106,10 @@ pub struct KeyBindings {
pub toggle_visual_mode: Vec<String>,
/// Key bindings for undoing a change.
pub undo: Vec<String>,
+ /// Key bindings for the fixup specific action to toggle the c option.
+ pub fixup_keep_message_with_editor: Vec<String>,
+ /// Key bindings for the fixup specific action to toggle the c option.
+ pub fixup_keep_message: Vec<String>,
}
impl KeyBindings {
@@ -171,6 +175,12 @@ impl KeyBindings {
show_diff: get_input(git_config, "interactive-rebase-tool.inputShowDiff", "d")?,
toggle_visual_mode: get_input(git_config, "interactive-rebase-tool.inputToggleVisualMode", "v")?,
undo: get_input(git_config, "interactive-rebase-tool.inputUndo", "control+z")?,
+ fixup_keep_message_with_editor: get_input(
+ git_config,
+ "interactive-rebase-tool.fixupKeepMessageWithEditor",
+ "U",
+ )?,
+ fixup_keep_message: get_input(git_config, "interactive-rebase-tool.fixupKeepMessage", "u")?,
})
}
}
@@ -285,5 +295,7 @@ mod tests {
config_test!(show_diff, "inputShowDiff", "d");
config_test!(toggle_visual_mode, "inputToggleVisualMode", "v");
config_test!(undo, "inputUndo", "Controlz");
+ config_test!(fixup_keep_message_with_editor, "fixupKeepMessageWithEditor", "U");
+ config_test!(fixup_keep_message, "fixupKeepMessage", "u");
}
}
diff --git a/src/core/src/events/app_key_bindings.rs b/src/core/src/events/app_key_bindings.rs
index ab04975..e1440f1 100644
--- a/src/core/src/events/app_key_bindings.rs
+++ b/src/core/src/events/app_key_bindings.rs
@@ -69,6 +69,10 @@ pub(crate) struct AppKeyBindings {
pub(crate) show_diff: Vec<Event>,
/// Key bindings for toggling visual mode.
pub(crate) toggle_visual_mode: Vec<Event>,
+ /// Key bindings for the fixup specific action to toggle the c option.
+ pub(crate) fixup_keep_message: Vec<Event>,
+ /// Key biding for the fixup specific action to toggle the C option.
+ pub(crate) fixup_keep_message_with_editor: Vec<Event>,
}
impl CustomKeybinding for AppKeyBindings {
@@ -104,6 +108,8 @@ impl CustomKeybinding for AppKeyBindings {
show_diff: map_keybindings(&key_bindings.show_diff),
toggle_visual_mode: map_keybindings(&key_bindings.toggle_visual_mode),
confirm_yes: map_keybindings(&key_bindings.confirm_yes),
+ fixup_keep_message: map_keybindings(&key_bindings.fixup_keep_message),
+ fixup_keep_message_with_editor: map_keybindings(&key_bindings.fixup_keep_message_with_editor),
}
}
}
diff --git a/src/core/src/events/meta_event.rs b/src/core/src/events/meta_event.rs
index e7759a6..542731f 100644
--- a/src/core/src/events/meta_event.rs
+++ b/src/core/src/events/meta_event.rs
@@ -58,6 +58,10 @@ pub(crate) enum MetaEvent {
ToggleVisualMode,
/// The insert line meta event.
InsertLine,
+ /// Fixup specific action to toggle the c option.
+ FixupKeepMessage,
+ /// Fixup specific action to toggle the C option.
+ FixupKeepMessageWithEditor,
/// The no meta event.
No,
/// The yes meta event.
diff --git a/src/core/src/modules/list/mod.rs b/src/core/src/modules/list/mod.rs
index 2420c72..dd59349 100644
--- a/src/core/src/modules/list/mod.rs
+++ b/src/core/src/modules/list/mod.rs
@@ -51,6 +51,7 @@ pub(crate) struct List {
normal_mode_help: Help,
search: Search,
search_bar: SearchBar,
+ selected_line_action: Option<Action>,
state: ListState,
view_data: ViewData,
visual_index_start: Option<usize>,
@@ -58,6 +59,11 @@ pub(crate) struct List {
}
impl Module for List {
+ fn activate(&mut self, todo_file: &TodoFile, _: State) -> Results {
+ self.selected_line_action = todo_file.get_selected_line().map(|line| *line.get_action());
+ Results::new()
+ }
+
fn build_view_data(&mut self, context: &RenderContext, todo_file: &TodoFile) -> &ViewData {
match self.state {
ListState::Normal => self.get_normal_mode_view_data(todo_file, context),
@@ -109,7 +115,7 @@ impl Module for List {
fn read_event(&self, event: Event, key_bindings: &KeyBindings) -> Event {
select!(
- default || Self::read_event_default(event, key_bindings),
+ default || self.read_event_default(event, key_bindings),
|| (self.state == ListState::Edit).then_some(event),
|| self.normal_mode_help.read_event(event),
|| self.visual_mode_help.read_event(event),
@@ -132,6 +138,7 @@ impl List {
normal_mode_help: Help::new_from_keybindings(&get_list_normal_mode_help_lines(&config.key_bindings)),
search: Search::new(),
search_bar: SearchBar::new(),
+ selected_line_action: None,
state: ListState::Normal,
view_data,
visual_index_start: None,
@@ -141,6 +148,7 @@ impl List {
fn set_cursor(&mut self, todo_file: &mut TodoFile, cursor: usize) {
todo_file.set_selected_line_index(cursor);
+ self.selected_line_action = todo_file.get_selected_line().map(|line| *line.get_action());
self.search.set_search_start_hint(cursor);
}
@@ -335,6 +343,15 @@ impl List {
}
}
+ #[allow(clippy::unused_self)]
+ fn toggle_option(&mut self, option: &str, todo_file: &mut TodoFile) {
+ todo_file.update_range(
+ todo_file.get_selected_line_index(),
+ todo_file.get_selected_line_index(),
+ &EditContext::new().option(option),
+ );
+ }
+
fn edit(&mut self, todo_file: &mut TodoFile) {
if let Some(selected_line) = todo_file.get_selected_line() {
if selected_line.is_editable() {
@@ -447,7 +464,22 @@ impl List {
}
#[allow(clippy::cognitive_complexity)]
- fn read_event_default(event: Event, key_bindings: &KeyBindings) -> Event {
+ fn read_event_default(&self, event: Event, key_bindings: &KeyBindings) -> Event {
+ // handle action level events
+ if let Some(action) = self.selected_line_action {
+ if action == Action::Fixup {
+ match event {
+ e if key_bindings.custom.fixup_keep_message.contains(&e) => {
+ return Event::from(MetaEvent::FixupKeepMessage);
+ },
+ e if key_bindings.custom.fixup_keep_message_with_editor.contains(&e) => {
+ return Event::from(MetaEvent::FixupKeepMessageWithEditor);
+ },
+ _ => {},
+ }
+ }
+ }
+
match event {
e if key_bindings.custom.abort.contains(&e) => Event::from(MetaEvent::Abort),
e if key_bindings.custom.action_break.contains(&e) => Event::from(MetaEvent::ActionBreak),
@@ -600,6 +632,8 @@ impl List {
MetaEvent::Edit => self.edit(rebase_todo),
MetaEvent::InsertLine => self.insert_line(&mut results),
MetaEvent::ShowCommit => self.show_commit(&mut results, rebase_todo),
+ MetaEvent::FixupKeepMessage => self.toggle_option("-C", rebase_todo),
+ MetaEvent::FixupKeepMessageWithEditor => self.toggle_option("-c", rebase_todo),
_ => {},
}
}
diff --git a/src/core/src/modules/list/tests/mod.rs b/src/core/src/modules/list/tests/mod.rs
index 5ea9808..fe57250 100644
--- a/src/core/src/modules/list/tests/mod.rs
+++ b/src/core/src/modules/list/tests/mod.rs
@@ -13,6 +13,7 @@ mod search;
mod show_commit;
mod swap_lines;
mod toggle_break;
+mod toggle_option;
mod undo_redo;
mod visual_mode;
diff --git a/src/core/src/modules/list/tests/read_event.rs b/src/core/src/modules/list/tests/read_event.rs
index 8affa16..6ddddb0 100644
--- a/src/core/src/modules/list/tests/read_event.rs
+++ b/src/core/src/modules/list/tests/read_event.rs
@@ -70,8 +70,6 @@ fn default_events_single_char(#[case] binding: char, #[case] expected: MetaEvent
});
}
-// Move
-
#[rstest]
#[case::movecursordown(KeyCode::Down, MetaEvent::MoveCursorDown)]
#[case::movecursorpagedown(KeyCode::PageDown, MetaEvent::MoveCursorPageDown)]
@@ -89,6 +87,29 @@ fn default_events_special(#[case] code: KeyCode, #[case] expected: MetaEvent) {
});
}
+#[rstest]
+#[case::abort('u', MetaEvent::FixupKeepMessage)]
+#[case::abort('U', MetaEvent::FixupKeepMessageWithEditor)]
+#[case::abort('p', MetaEvent::ActionPick)]
+fn fixup_events(#[case] binding: char, #[case] expected: MetaEvent) {
+ read_event_test(Event::from(binding), |mut context| {
+ let mut module = create_list_module();
+ module.selected_line_action = Some(Action::Fixup);
+ assert_eq!(context.read_event(&mut module), Event::from(expected));
+ });
+}
+
+#[rstest]
+#[case::abort('u')]
+#[case::abort('U')]
+fn fixup_events_with_non_fixpo_event(#[case] binding: char) {
+ read_event_test(Event::from(binding), |mut context| {
+ let mut module = create_list_module();
+ module.selected_line_action = Some(Action::Pick);
+ assert_eq!(context.read_event(&mut module), Event::from(binding));
+ });
+}
+
#[test]
fn mouse_move_down() {
read_event_test(
diff --git a/src/core/src/modules/list/tests/render.rs b/src/core/src/modules/list/tests/render.rs
index a75104e..55c07d2 100644
--- a/src/core/src/modules/list/tests/render.rs
+++ b/src/core/src/modules/list/tests/render.rs
@@ -24,6 +24,7 @@ fn full() {
"pick aaaaaaaa comment 1",
"drop bbbbbbbb comment 2",
"fixup cccccccc comment 3",
+ "fixup -c cccccccb comment 3b",
"exec echo 'foo'",
"pick dddddddd comment 4",
"reword eeeeeeee comment 5",
@@ -43,18 +44,19 @@ fn full() {
view_data,
"{TITLE}{HELP}",
"{BODY}",
- "{Selected}{Normal} > {ActionPick}pick {Normal}aaaaaaaa comment 1{Pad( )}",
- "{Normal} {ActionDrop}drop {Normal}bbbbbbbb comment 2",
- "{Normal} {ActionFixup}fixup {Normal}cccccccc comment 3",
- "{Normal} {ActionExec}exec {Normal}echo 'foo'",
- "{Normal} {ActionPick}pick {Normal}dddddddd comment 4",
- "{Normal} {ActionReword}reword {Normal}eeeeeeee comment 5",
+ "{Selected}{Normal} > {ActionPick}pick {Normal}aaaaaaaa comment 1{Pad( )}",
+ "{Normal} {ActionDrop}drop {Normal}bbbbbbbb comment 2",
+ "{Normal} {ActionFixup}fixup {Normal}cccccccc comment 3",
+ "{Normal} {ActionFixup}fixup -c {Normal}cccccccb comment 3b",
+ "{Normal} {ActionExec}exec {Normal}echo 'foo'",
+ "{Normal} {ActionPick}pick {Normal}dddddddd comment 4",
+ "{Normal} {ActionReword}reword {Normal}eeeeeeee comment 5",
"{Normal} {ActionBreak}break",
- "{Normal} {ActionSquash}squash {Normal}ffffffff comment 6",
- "{Normal} {ActionEdit}edit {Normal}11111111 comment 7",
- "{Normal} {ActionLabel}label {Normal}ref",
- "{Normal} {ActionReset}reset {Normal}ref",
- "{Normal} {ActionMerge}merge {Normal}command",
+ "{Normal} {ActionSquash}squash {Normal}ffffffff comment 6",
+ "{Normal} {ActionEdit}edit {Normal}11111111 comment 7",
+ "{Normal} {ActionLabel}label {Normal}ref",
+ "{Normal} {ActionReset}reset {Normal}ref",
+ "{Normal} {ActionMerge}merge {Normal}command",
"{Normal} {ActionUpdateRef}update-ref {Normal}reference"
);
},
@@ -68,6 +70,7 @@ fn compact() {
"pick aaaaaaaa comment 1",
"drop bbbbbbbb comment 2",
"fixup cccccccc comment 3",
+ "fixup -c cccccccb comment 3b",
"exec echo 'foo'",
"pick dddddddd comment 4",
"reword eeeeeeee comment 5",
@@ -91,6 +94,7 @@ fn compact() {
"{Selected}{Normal}>{ActionPick}p {Normal}aaa comment 1{Pad( )}",
"{Normal} {ActionDrop}d {Normal}bbb comment 2",
"{Normal} {ActionFixup}f {Normal}ccc comment 3",
+ "{Normal} {ActionFixup}f*{Normal}ccc comment 3b",
"{Normal} {ActionExec}x {Normal}echo 'foo'",
"{Normal} {ActionPick}p {Normal}ddd comment 4",
"{Normal} {ActionReword}r {Normal}eee comment 5",
diff --git a/src/core/src/modules/list/tests/toggle_option.rs b/src/core/src/modules/list/tests/toggle_option.rs
new file mode 100644
index 0000000..8cf46c8
--- /dev/null
+++ b/src/core/src/modules/list/tests/toggle_option.rs
@@ -0,0 +1,50 @@
+use claim::{assert_none, assert_some, assert_some_eq};
+
+use super::*;
+use crate::testutil::module_test;
+
+#[test]
+fn on_fixup_keep_message() {
+ module_test(
+ &["fixup aaa c1"],
+ &[Event::from(MetaEvent::FixupKeepMessage)],
+ |mut test_context| {
+ let mut module = List::new(&Config::new());
+ let _ = test_context.activate(&mut module, State::List);
+ let _ = test_context.handle_all_events(&mut module);
+ let line = test_context.todo_file_context.todo_file().get_line(0).unwrap();
+ assert_some_eq!(line.option(), "-C");
+ },
+ );
+}
+
+#[test]
+fn on_fixup_keep_message_with_editor() {
+ module_test(
+ &["fixup aaa c1"],
+ &[Event::from(MetaEvent::FixupKeepMessageWithEditor)],
+ |mut test_context| {
+ let mut module = List::new(&Config::new());
+ let _ = test_context.activate(&mut module, State::List);
+ let _ = test_context.handle_all_events(&mut module);
+ let line = test_context.todo_file_context.todo_file().get_line(0).unwrap();
+ assert_some_eq!(line.option(), "-c");
+ },
+ );
+}
+
+#[test]
+fn after_select_line() {
+ module_test(
+ &["fixup aaa c1", "fixup aaa c2", "fixup aaa c3"],
+ &[Event::from(MetaEvent::MoveCursorDown), Event::from('u')],
+ |mut test_context| {
+ let mut module = List::new(&Config::new());
+ let _ = test_context.activate(&mut module, State::List);
+ let _ = test_context.handle_all_events(&mut module);
+ assert_none!(test_context.todo_file_context.todo_file().get_line(0).unwrap().option());
+ assert_some!(test_context.todo_file_context.todo_file().get_line(1).unwrap().option());
+ assert_none!(test_context.todo_file_context.todo_file().get_line(2).unwrap().option());
+ },
+ );
+}
diff --git a/src/core/src/modules/list/utils.rs b/src/core/src/modules/list/utils.rs
index c69bbeb..707d791 100644
--- a/src/core/src/modules/list/utils.rs
+++ b/src/core/src/modules/list/utils.rs
@@ -204,7 +204,15 @@ pub(super) fn get_line_action_maximum_width(todo_file: &TodoFile) -> usize {
// allow these to overflow their bounds
&Action::Exec | &Action::UpdateRef => 0,
&Action::Drop | &Action::Edit | &Action::Noop | &Action::Pick => 4,
- &Action::Fixup | &Action::Break | &Action::Label | &Action::Reset | &Action::Merge => 5,
+ &Action::Break | &Action::Label | &Action::Reset | &Action::Merge => 5,
+ &Action::Fixup => {
+ if line.option().is_some() {
+ 8 // "fixup -C" = 8
+ }
+ else {
+ 5
+ }
+ },
&Action::Reword | &Action::Squash => 6,
};
if max_width < action_length {
@@ -261,10 +269,19 @@ pub(super) fn get_todo_line_segments(
));
let action_name = if is_full_width {
- format!("{:maximum_action_width$} ", action.to_string())
+ if let Some(opt) = line.option() {
+ format!("{:maximum_action_width$} ", format!("{action} {opt}"))
+ }
+ else {
+ format!("{:maximum_action_width$} ", action.to_string())
+ }
}
else {
- format!("{:1} ", action.to_abbreviation())
+ format!(
+ "{:1}{}",
+ action.to_abbreviation(),
+ if line.option().is_some() { "*" } else { " " }
+ )
};
segments.push(LineSegment::new_with_color(
diff --git a/src/core/src/testutil/create_test_keybindings.rs b/src/core/src/testutil/create_test_keybindings.rs
index 6f6b05d..6b70ea8 100644
--- a/src/core/src/testutil/create_test_keybindings.rs
+++ b/src/core/src/testutil/create_test_keybindings.rs
@@ -37,5 +37,7 @@ pub(crate) fn create_test_custom_keybindings() -> AppKeyBindings {
show_commit: vec![Event::from(KeyCode::Char('c'))],
show_diff: vec![Event::from(KeyCode::Char('d'))],
toggle_visual_mode: vec![Event::from(KeyCode::Char('v'))],
+ fixup_keep_message: vec![Event::from(KeyCode::Char('u'))],
+ fixup_keep_message_with_editor: vec![Event::from(KeyCode::Char('U'))],
}
}