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'))],

src/display/src/display_color.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub enum DisplayColor {
1212
ActionExec,
1313
/// The color for the fixup action.
1414
ActionFixup,
15+
/// The color for the index action.
16+
ActionIndex,
1517
/// The color for the pick action.
1618
ActionPick,
1719
/// The color for the reword action.

src/display/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ pub struct Display<T: Tui> {
178178
action_edit: (Colors, Colors),
179179
action_exec: (Colors, Colors),
180180
action_fixup: (Colors, Colors),
181+
action_index: (Colors, Colors),
181182
action_label: (Colors, Colors),
182183
action_merge: (Colors, Colors),
183184
action_pick: (Colors, Colors),
@@ -242,6 +243,12 @@ impl<T: Tui> Display<T> {
242243
theme.color_background,
243244
theme.color_selected_background,
244245
);
246+
let action_index = register_selectable_color_pairs(
247+
color_mode,
248+
theme.color_action_index,
249+
theme.color_background,
250+
theme.color_selected_background,
251+
);
245252
let action_pick = register_selectable_color_pairs(
246253
color_mode,
247254
theme.color_action_pick,
@@ -321,6 +328,7 @@ impl<T: Tui> Display<T> {
321328
action_edit,
322329
action_exec,
323330
action_fixup,
331+
action_index,
324332
action_label,
325333
action_merge,
326334
action_pick,
@@ -385,6 +393,7 @@ impl<T: Tui> Display<T> {
385393
DisplayColor::ActionEdit => self.action_edit.1,
386394
DisplayColor::ActionExec => self.action_exec.1,
387395
DisplayColor::ActionFixup => self.action_fixup.1,
396+
DisplayColor::ActionIndex => self.action_index.1,
388397
DisplayColor::ActionPick => self.action_pick.1,
389398
DisplayColor::ActionReword => self.action_reword.1,
390399
DisplayColor::ActionSquash => self.action_squash.1,
@@ -408,6 +417,7 @@ impl<T: Tui> Display<T> {
408417
DisplayColor::ActionEdit => self.action_edit.0,
409418
DisplayColor::ActionExec => self.action_exec.0,
410419
DisplayColor::ActionFixup => self.action_fixup.0,
420+
DisplayColor::ActionIndex => self.action_index.0,
411421
DisplayColor::ActionPick => self.action_pick.0,
412422
DisplayColor::ActionReword => self.action_reword.0,
413423
DisplayColor::ActionSquash => self.action_squash.0,
@@ -575,6 +585,13 @@ mod tests {
575585
CrosstermColor::Magenta,
576586
CrosstermColor::AnsiValue(237)
577587
)]
588+
#[case::action_index(DisplayColor::ActionIndex, false, CrosstermColor::DarkGreen, CrosstermColor::Reset)]
589+
#[case::action_index_selected(
590+
DisplayColor::ActionIndex,
591+
true,
592+
CrosstermColor::DarkGreen,
593+
CrosstermColor::AnsiValue(237)
594+
)]
578595
#[case::action_pick(DisplayColor::ActionPick, false, CrosstermColor::Green, CrosstermColor::Reset)]
579596
#[case::action_pick_selected(
580597
DisplayColor::ActionPick,

src/todo_file/src/action.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pub enum Action {
1616
Exec,
1717
/// A fixup action.
1818
Fixup,
19+
/// A index action for git-revise.
20+
Index,
1921
/// A noop action.
2022
Noop,
2123
/// A pick action.
@@ -45,6 +47,7 @@ impl Action {
4547
Self::Edit => "e",
4648
Self::Exec => "x",
4749
Self::Fixup => "f",
50+
Self::Index => "i",
4851
Self::Label => "l",
4952
Self::Merge => "m",
5053
Self::Noop => "n",
@@ -62,7 +65,7 @@ impl Action {
6265
pub const fn is_static(self) -> bool {
6366
match self {
6467
Self::Break | Self::Exec | Self::Noop | Self::Reset | Self::Label | Self::Merge | Self::UpdateRef => true,
65-
Self::Drop | Self::Edit | Self::Fixup | Self::Pick | Self::Reword | Self::Squash => false,
68+
Self::Drop | Self::Edit | Self::Index | Self::Fixup | Self::Pick | Self::Reword | Self::Squash => false,
6669
}
6770
}
6871
}
@@ -76,6 +79,7 @@ impl Display for Action {
7679
Self::Edit => "edit",
7780
Self::Exec => "exec",
7881
Self::Fixup => "fixup",
82+
Self::Index => "index",
7983
Self::Label => "label",
8084
Self::Merge => "merge",
8185
Self::Noop => "noop",
@@ -95,10 +99,12 @@ impl TryFrom<&str> for Action {
9599
fn try_from(s: &str) -> Result<Self, Self::Error> {
96100
match s {
97101
"break" | "b" => Ok(Self::Break),
102+
// "cut" => Ok(Self::Cut),
98103
"drop" | "d" => Ok(Self::Drop),
99104
"edit" | "e" => Ok(Self::Edit),
100105
"exec" | "x" => Ok(Self::Exec),
101106
"fixup" | "f" => Ok(Self::Fixup),
107+
"index" => Ok(Self::Index),
102108
"noop" | "n" => Ok(Self::Noop),
103109
"pick" | "p" => Ok(Self::Pick),
104110
"reword" | "r" => Ok(Self::Reword),

src/todo_file/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ impl TodoFile {
282282
Action::Drop
283283
| Action::Fixup
284284
| Action::Edit
285+
| Action::Index
285286
| Action::Pick
286287
| Action::Reword
287288
| Action::Squash => {

src/todo_file/src/line.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl Line {
102102
Ok(match action {
103103
Action::Noop => Self::new_noop(),
104104
Action::Break => Self::new_break(),
105-
Action::Pick | Action::Reword | Action::Edit | Action::Squash | Action::Drop => {
105+
Action::Pick | Action::Reword | Action::Edit | Action::Squash | Action::Drop | Action::Index => {
106106
Self::new(action, line_parser.next()?, line_parser.take_remaining(), None)
107107
},
108108
Action::Fixup => {
@@ -207,7 +207,7 @@ impl Line {
207207
#[inline]
208208
pub const fn is_editable(&self) -> bool {
209209
match self.action {
210-
Action::Exec | Action::Label | Action::Reset | Action::Merge | Action::UpdateRef => true,
210+
Action::Exec | Action::Index | Action::Label | Action::Reset | Action::Merge | Action::UpdateRef => true,
211211
Action::Break
212212
| Action::Drop
213213
| Action::Edit
@@ -231,7 +231,7 @@ impl Line {
231231
#[inline]
232232
pub fn to_text(&self) -> String {
233233
match self.action {
234-
Action::Drop | Action::Edit | Action::Fixup | Action::Pick | Action::Reword | Action::Squash => {
234+
Action::Drop | Action::Edit | Action::Fixup | Action::Index | Action::Pick | Action::Reword | Action::Squash => {
235235
if let Some(opt) = self.option.as_ref() {
236236
format!("{} {opt} {} {}", self.action, self.hash, self.content)
237237
}

src/todo_file/src/search.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl Search {
4040
Action::Drop
4141
| Action::Edit
4242
| Action::Fixup
43+
| Action::Index
4344
| Action::Pick
4445
| Action::Reword
4546
| Action::Squash

src/view/src/testutil/render_view_line.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub(crate) fn render_style(line_segment: &LineSegment) -> String {
8383
DisplayColor::DiffWhitespaceColor => String::from("DiffWhitespaceColor"),
8484
DisplayColor::IndicatorColor => String::from("IndicatorColor"),
8585
DisplayColor::Normal => String::from("Normal"),
86+
DisplayColor::ActionIndex => String::from("ActionIndex"),
8687
DisplayColor::ActionLabel => String::from("ActionLabel"),
8788
DisplayColor::ActionReset => String::from("ActionReset"),
8889
DisplayColor::ActionMerge => String::from("ActionMerge"),

0 commit comments

Comments
 (0)