Skip to content

Commit e86b282

Browse files
committed
WIP: add index action for git-revise
1 parent 3203b73 commit e86b282

File tree

17 files changed

+60
-6
lines changed

17 files changed

+60
-6
lines changed

readme/customization.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Most keys can be changed to any printable character or supported special charact
113113
| `inputActionPick` | p | String | Key for setting action to pick |
114114
| `inputActionReword` | r | String | Key for setting action to reword |
115115
| `inputActionSquash` | s | String | Key for setting action to squash |
116+
| `inputActionIndex` | i | String | Key for setting action to index (git-revise) |
116117
| `inputConfirmNo` | n | String | Key for rejecting a confirmation |
117118
| `inputConfirmYes` | y | String | Key for confirming a confirmation |
118119
| `inputEdit` | E | String | Key for entering edit mode |

src/config/src/key_bindings.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub struct KeyBindings {
2525
pub action_edit: Vec<String>,
2626
/// Key bindings for the fixup action.
2727
pub action_fixup: Vec<String>,
28+
/// Key bindings for the index action.
29+
pub action_index: Vec<String>,
2830
/// Key bindings for the pick action.
2931
pub action_pick: Vec<String>,
3032
/// Key bindings for the reword action.
@@ -136,6 +138,7 @@ impl KeyBindings {
136138
action_drop: get_input(git_config, "interactive-rebase-tool.inputActionDrop", "d")?,
137139
action_edit: get_input(git_config, "interactive-rebase-tool.inputActionEdit", "e")?,
138140
action_fixup: get_input(git_config, "interactive-rebase-tool.inputActionFixup", "f")?,
141+
action_index: get_input(git_config, "interactive-rebase-tool.inputActionIndex", "i")?,
139142
action_pick: get_input(git_config, "interactive-rebase-tool.inputActionPick", "p")?,
140143
action_reword: get_input(git_config, "interactive-rebase-tool.inputActionReword", "r")?,
141144
action_squash: get_input(git_config, "interactive-rebase-tool.inputActionSquash", "s")?,
@@ -256,6 +259,7 @@ mod tests {
256259
config_test!(action_drop, "inputActionDrop", "d");
257260
config_test!(action_edit, "inputActionEdit", "e");
258261
config_test!(action_fixup, "inputActionFixup", "f");
262+
config_test!(action_index, "inputActionIndex", "i");
259263
config_test!(action_pick, "inputActionPick", "p");
260264
config_test!(action_reword, "inputActionReword", "r");
261265
config_test!(action_squash, "inputActionSquash", "s");

src/config/src/theme.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub struct Theme {
3838
pub color_action_exec: Color,
3939
/// The color for the fixup action.
4040
pub color_action_fixup: Color,
41+
/// The color for the fixup action.
42+
pub color_action_index: Color,
4143
/// The color for the pick action.
4244
pub color_action_pick: Color,
4345
/// The color for the reword action.
@@ -94,6 +96,7 @@ impl Theme {
9496
color_action_edit: get_color(git_config, "interactive-rebase-tool.editColor", Color::LightBlue)?,
9597
color_action_exec: get_color(git_config, "interactive-rebase-tool.execColor", Color::LightWhite)?,
9698
color_action_fixup: get_color(git_config, "interactive-rebase-tool.fixupColor", Color::LightMagenta)?,
99+
color_action_index: get_color(git_config, "interactive-rebase-tool.indexColor", Color::DarkGreen)?,
97100
color_action_pick: get_color(git_config, "interactive-rebase-tool.pickColor", Color::LightGreen)?,
98101
color_action_reword: get_color(git_config, "interactive-rebase-tool.rewordColor", Color::LightYellow)?,
99102
color_action_squash: get_color(git_config, "interactive-rebase-tool.squashColor", Color::LightCyan)?,
@@ -219,6 +222,7 @@ mod tests {
219222
config_test!(color_action_edit, "editColor", Color::LightBlue);
220223
config_test!(color_action_exec, "execColor", Color::LightWhite);
221224
config_test!(color_action_fixup, "fixupColor", Color::LightMagenta);
225+
config_test!(color_action_index, "indexColor", Color::DarkGreen);
222226
config_test!(color_action_pick, "pickColor", Color::LightGreen);
223227
config_test!(color_action_reword, "rewordColor", Color::LightYellow);
224228
config_test!(color_action_squash, "squashColor", Color::LightCyan);

src/core/src/events/app_key_bindings.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub(crate) struct AppKeyBindings {
2121
pub(crate) action_edit: Vec<Event>,
2222
/// Key bindings for the fixup action.
2323
pub(crate) action_fixup: Vec<Event>,
24+
/// Key bindings for the index action.
25+
pub(crate) action_index: Vec<Event>,
2426
/// Key bindings for the pick action.
2527
pub(crate) action_pick: Vec<Event>,
2628
/// Key bindings for the reword action.
@@ -84,6 +86,7 @@ impl CustomKeybinding for AppKeyBindings {
8486
action_drop: map_keybindings(&key_bindings.action_drop),
8587
action_edit: map_keybindings(&key_bindings.action_edit),
8688
action_fixup: map_keybindings(&key_bindings.action_fixup),
89+
action_index: map_keybindings(&key_bindings.action_index),
8790
action_pick: map_keybindings(&key_bindings.action_pick),
8891
action_reword: map_keybindings(&key_bindings.action_reword),
8992
action_squash: map_keybindings(&key_bindings.action_squash),

src/core/src/events/meta_event.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub(crate) enum MetaEvent {
1818
ActionEdit,
1919
/// The fixup action meta event.
2020
ActionFixup,
21+
/// The index (git-revise) action meta event.
22+
ActionIndex,
2123
/// The pick action meta event.
2224
ActionPick,
2325
/// The reword action meta event.

src/core/src/modules/list/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ impl List {
520520
e if key_bindings.custom.action_drop.contains(&e) => Event::from(MetaEvent::ActionDrop),
521521
e if key_bindings.custom.action_edit.contains(&e) => Event::from(MetaEvent::ActionEdit),
522522
e if key_bindings.custom.action_fixup.contains(&e) => Event::from(MetaEvent::ActionFixup),
523+
e if key_bindings.custom.action_index.contains(&e) => Event::from(MetaEvent::ActionIndex),
523524
e if key_bindings.custom.action_pick.contains(&e) => Event::from(MetaEvent::ActionPick),
524525
e if key_bindings.custom.action_reword.contains(&e) => Event::from(MetaEvent::ActionReword),
525526
e if key_bindings.custom.action_squash.contains(&e) => Event::from(MetaEvent::ActionSquash),
@@ -608,6 +609,7 @@ impl List {
608609
MetaEvent::ActionDrop => self.set_selected_line_action(Action::Drop),
609610
MetaEvent::ActionEdit => self.set_selected_line_action(Action::Edit),
610611
MetaEvent::ActionFixup => self.set_selected_line_action(Action::Fixup),
612+
MetaEvent::ActionIndex => self.set_selected_line_action(Action::Index),
611613
MetaEvent::ActionPick => self.set_selected_line_action(Action::Pick),
612614
MetaEvent::ActionReword => self.set_selected_line_action(Action::Reword),
613615
MetaEvent::ActionSquash => self.set_selected_line_action(Action::Squash),

src/core/src/modules/list/tests/help.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ fn normal_mode_help() {
4343
" s |Set selected commits to be squashed",
4444
" f |Set selected commits to be fixed-up",
4545
" d |Set selected commits to be dropped",
46+
" i |Set selected commits to be staged in the index (git-revise)",
4647
" E |Edit an exec, label, reset or merge action's content",
4748
" I |Insert a new line",
4849
" Delete |Completely remove the selected lines",
@@ -108,6 +109,7 @@ fn visual_mode_help() {
108109
" s |Set selected commits to be squashed",
109110
" f |Set selected commits to be fixed-up",
110111
" d |Set selected commits to be dropped",
112+
" i |Set selected commits to be staged in the index (git-revise)",
111113
" Delete |Completely remove the selected lines",
112114
" Controlz|Undo the last change",
113115
" Controly|Redo the previous undone change",

src/core/src/modules/list/tests/read_event.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ fn search() {
4949
#[case::actionpick('p', MetaEvent::ActionPick)]
5050
#[case::actionreword('r', MetaEvent::ActionReword)]
5151
#[case::actionsquash('s', MetaEvent::ActionSquash)]
52+
#[case::actionindex('i', MetaEvent::ActionIndex)]
5253
#[case::edit('E', MetaEvent::Edit)]
5354
#[case::forceabort('Q', MetaEvent::ForceAbort)]
5455
#[case::forcerebase('W', MetaEvent::ForceRebase)]

src/core/src/modules/list/utils.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ fn build_help_lines(key_bindings: &KeyBindings, selector: HelpLinesSelector) ->
122122
"Set selected commits to be dropped",
123123
HelpLinesSelector::Common,
124124
),
125+
(
126+
&key_bindings.action_index,
127+
"Set selected commits to be staged in the index (git-revise)",
128+
HelpLinesSelector::Common,
129+
),
125130
(
126131
&key_bindings.edit,
127132
"Edit an exec, label, reset or merge action's content",
@@ -184,6 +189,7 @@ const fn get_action_color(action: Action) -> DisplayColor {
184189
Action::Edit => DisplayColor::ActionEdit,
185190
Action::Exec => DisplayColor::ActionExec,
186191
Action::Fixup => DisplayColor::ActionFixup,
192+
Action::Index => DisplayColor::ActionIndex,
187193
Action::Pick => DisplayColor::ActionPick,
188194
Action::Reword => DisplayColor::ActionReword,
189195
Action::Squash => DisplayColor::ActionSquash,
@@ -204,7 +210,7 @@ pub(super) fn get_line_action_maximum_width(todo_file: &TodoFile) -> usize {
204210
// allow these to overflow their bounds
205211
&Action::Exec | &Action::UpdateRef => 0,
206212
&Action::Drop | &Action::Edit | &Action::Noop | &Action::Pick => 4,
207-
&Action::Break | &Action::Label | &Action::Reset | &Action::Merge => 5,
213+
&Action::Break | &Action::Label | &Action::Reset | &Action::Merge | &Action::Index => 5,
208214
&Action::Fixup => {
209215
if line.option().is_some() {
210216
8 // "fixup -C" = 8
@@ -293,7 +299,7 @@ pub(super) fn get_todo_line_segments(
293299

294300
// render hash
295301
match *action {
296-
Action::Drop | Action::Edit | Action::Fixup | Action::Pick | Action::Reword | Action::Squash => {
302+
Action::Drop | Action::Edit | Action::Fixup | Action::Index | Action::Pick | Action::Reword | Action::Squash => {
297303
let action_width = if is_full_width { 8 } else { 3 };
298304
let max_index = cmp::min(line.get_hash().len(), action_width);
299305
let search_match = search_term.map_or(false, |term| line.get_hash().starts_with(term));

src/core/src/testutil/create_test_keybindings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub(crate) fn create_test_custom_keybindings() -> AppKeyBindings {
1313
action_drop: vec![Event::from(KeyCode::Char('d'))],
1414
action_edit: vec![Event::from(KeyCode::Char('e'))],
1515
action_fixup: vec![Event::from(KeyCode::Char('f'))],
16+
action_index: vec![Event::from(KeyCode::Char('i'))],
1617
action_pick: vec![Event::from(KeyCode::Char('p'))],
1718
action_reword: vec![Event::from(KeyCode::Char('r'))],
1819
action_squash: vec![Event::from(KeyCode::Char('s'))],

0 commit comments

Comments
 (0)