Skip to content

Commit 0ab5166

Browse files
committed
WIP: add cut action for git-revise
1 parent e86b282 commit 0ab5166

File tree

17 files changed

+51
-7
lines changed

17 files changed

+51
-7
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+
| `inputActionCut` | x | String | Key for setting action to cut (git-revise) |
116117
| `inputActionIndex` | i | String | Key for setting action to index (git-revise) |
117118
| `inputConfirmNo` | n | String | Key for rejecting a confirmation |
118119
| `inputConfirmYes` | y | String | Key for confirming a confirmation |

src/config/src/key_bindings.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub struct KeyBindings {
1919
pub abort: Vec<String>,
2020
/// Key bindings for the break action.
2121
pub action_break: Vec<String>,
22+
/// Key bindings for the cut action.
23+
pub action_cut: Vec<String>,
2224
/// Key bindings for the drop action.
2325
pub action_drop: Vec<String>,
2426
/// Key bindings for the edit action.
@@ -135,6 +137,7 @@ impl KeyBindings {
135137
Ok(Self {
136138
abort: get_input(git_config, "interactive-rebase-tool.inputAbort", "q")?,
137139
action_break: get_input(git_config, "interactive-rebase-tool.inputActionBreak", "b")?,
140+
action_cut: get_input(git_config, "interactive-rebase-tool.inputActionCut", "x")?,
138141
action_drop: get_input(git_config, "interactive-rebase-tool.inputActionDrop", "d")?,
139142
action_edit: get_input(git_config, "interactive-rebase-tool.inputActionEdit", "e")?,
140143
action_fixup: get_input(git_config, "interactive-rebase-tool.inputActionFixup", "f")?,

src/config/src/theme.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub struct Theme {
3030
pub character_vertical_spacing: String,
3131
/// The color for the break action.
3232
pub color_action_break: Color,
33+
/// The color for the cut action.
34+
pub color_action_cut: Color,
3335
/// The color for the drop action.
3436
pub color_action_drop: Color,
3537
/// The color for the edit action.
@@ -92,6 +94,7 @@ impl Theme {
9294
"~",
9395
)?,
9496
color_action_break: get_color(git_config, "interactive-rebase-tool.breakColor", Color::LightWhite)?,
97+
color_action_cut: get_color(git_config, "interactive-rebase-tool.cutColor", Color::DarkRed)?,
9598
color_action_drop: get_color(git_config, "interactive-rebase-tool.dropColor", Color::LightRed)?,
9699
color_action_edit: get_color(git_config, "interactive-rebase-tool.editColor", Color::LightBlue)?,
97100
color_action_exec: get_color(git_config, "interactive-rebase-tool.execColor", Color::LightWhite)?,

src/core/src/events/app_key_bindings.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub(crate) struct AppKeyBindings {
1515
pub(crate) abort: Vec<Event>,
1616
/// Key bindings for the break action.
1717
pub(crate) action_break: Vec<Event>,
18+
/// Key bindings for the cut action.
19+
pub(crate) action_cut: Vec<Event>,
1820
/// Key bindings for the drop action.
1921
pub(crate) action_drop: Vec<Event>,
2022
/// Key bindings for the edit action.
@@ -83,6 +85,7 @@ impl CustomKeybinding for AppKeyBindings {
8385
Self {
8486
abort: map_keybindings(&key_bindings.abort),
8587
action_break: map_keybindings(&key_bindings.action_break),
88+
action_cut: map_keybindings(&key_bindings.action_cut),
8689
action_drop: map_keybindings(&key_bindings.action_drop),
8790
action_edit: map_keybindings(&key_bindings.action_edit),
8891
action_fixup: map_keybindings(&key_bindings.action_fixup),

src/core/src/events/meta_event.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub(crate) enum MetaEvent {
1212
ForceRebase,
1313
/// The break action meta event.
1414
ActionBreak,
15+
/// The cut (git-revise) action meta event.
16+
ActionCut,
1517
/// The drop action meta event.
1618
ActionDrop,
1719
/// The edit action meta event.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ impl List {
517517
match event {
518518
e if key_bindings.custom.abort.contains(&e) => Event::from(MetaEvent::Abort),
519519
e if key_bindings.custom.action_break.contains(&e) => Event::from(MetaEvent::ActionBreak),
520+
e if key_bindings.custom.action_cut.contains(&e) => Event::from(MetaEvent::ActionCut),
520521
e if key_bindings.custom.action_drop.contains(&e) => Event::from(MetaEvent::ActionDrop),
521522
e if key_bindings.custom.action_edit.contains(&e) => Event::from(MetaEvent::ActionEdit),
522523
e if key_bindings.custom.action_fixup.contains(&e) => Event::from(MetaEvent::ActionFixup),
@@ -606,6 +607,7 @@ impl List {
606607
Event::MetaEvent(meta_event) => {
607608
match meta_event {
608609
MetaEvent::Abort => self.abort(&mut results),
610+
MetaEvent::ActionCut => self.set_selected_line_action(Action::Cut),
609611
MetaEvent::ActionDrop => self.set_selected_line_action(Action::Drop),
610612
MetaEvent::ActionEdit => self.set_selected_line_action(Action::Edit),
611613
MetaEvent::ActionFixup => self.set_selected_line_action(Action::Fixup),

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+
" x |Set selected commits to be cut / split (git-revise)",
4647
" i |Set selected commits to be staged in the index (git-revise)",
4748
" E |Edit an exec, label, reset or merge action's content",
4849
" I |Insert a new line",
@@ -109,6 +110,7 @@ fn visual_mode_help() {
109110
" s |Set selected commits to be squashed",
110111
" f |Set selected commits to be fixed-up",
111112
" d |Set selected commits to be dropped",
113+
" x |Set selected commits to be cut / split (git-revise)",
112114
" i |Set selected commits to be staged in the index (git-revise)",
113115
" Delete |Completely remove the selected lines",
114116
" Controlz|Undo the last 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::actioncut('x', MetaEvent::ActionCut)]
5253
#[case::actionindex('i', MetaEvent::ActionIndex)]
5354
#[case::edit('E', MetaEvent::Edit)]
5455
#[case::forceabort('Q', MetaEvent::ForceAbort)]

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_cut,
127+
"Set selected commits to be cut / split (git-revise)",
128+
HelpLinesSelector::Common,
129+
),
125130
(
126131
&key_bindings.action_index,
127132
"Set selected commits to be staged in the index (git-revise)",
@@ -185,6 +190,7 @@ pub(super) fn get_list_visual_mode_help_lines(key_bindings: &KeyBindings) -> Vec
185190
const fn get_action_color(action: Action) -> DisplayColor {
186191
match action {
187192
Action::Break => DisplayColor::ActionBreak,
193+
Action::Cut => DisplayColor::ActionCut,
188194
Action::Drop => DisplayColor::ActionDrop,
189195
Action::Edit => DisplayColor::ActionEdit,
190196
Action::Exec => DisplayColor::ActionExec,
@@ -209,7 +215,7 @@ pub(super) fn get_line_action_maximum_width(todo_file: &TodoFile) -> usize {
209215
let action_length = match line.get_action() {
210216
// allow these to overflow their bounds
211217
&Action::Exec | &Action::UpdateRef => 0,
212-
&Action::Drop | &Action::Edit | &Action::Noop | &Action::Pick => 4,
218+
&Action::Cut | &Action::Drop | &Action::Edit | &Action::Noop | &Action::Pick => 4,
213219
&Action::Break | &Action::Label | &Action::Reset | &Action::Merge | &Action::Index => 5,
214220
&Action::Fixup => {
215221
if line.option().is_some() {
@@ -299,7 +305,7 @@ pub(super) fn get_todo_line_segments(
299305

300306
// render hash
301307
match *action {
302-
Action::Drop | Action::Edit | Action::Fixup | Action::Index | Action::Pick | Action::Reword | Action::Squash => {
308+
Action::Cut | Action::Drop | Action::Edit | Action::Fixup | Action::Index | Action::Pick | Action::Reword | Action::Squash => {
303309
let action_width = if is_full_width { 8 } else { 3 };
304310
let max_index = cmp::min(line.get_hash().len(), action_width);
305311
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
@@ -10,6 +10,7 @@ pub(crate) fn create_test_custom_keybindings() -> AppKeyBindings {
1010
AppKeyBindings {
1111
abort: vec![Event::from(KeyCode::Char('q'))],
1212
action_break: vec![Event::from(KeyCode::Char('b'))],
13+
action_cut: vec![Event::from(KeyCode::Char('x'))],
1314
action_drop: vec![Event::from(KeyCode::Char('d'))],
1415
action_edit: vec![Event::from(KeyCode::Char('e'))],
1516
action_fixup: vec![Event::from(KeyCode::Char('f'))],

src/display/src/display_color.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
pub enum DisplayColor {
55
/// The color for the break action.
66
ActionBreak,
7+
/// The color for the cut action.
8+
ActionCut,
79
/// The color for the drop action.
810
ActionDrop,
911
/// The color for the edit action.

src/display/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ pub use self::{
174174
#[derive(Debug)]
175175
pub struct Display<T: Tui> {
176176
action_break: (Colors, Colors),
177+
action_cut: (Colors, Colors),
177178
action_drop: (Colors, Colors),
178179
action_edit: (Colors, Colors),
179180
action_exec: (Colors, Colors),
@@ -219,6 +220,12 @@ impl<T: Tui> Display<T> {
219220
theme.color_background,
220221
theme.color_selected_background,
221222
);
223+
let action_cut = register_selectable_color_pairs(
224+
color_mode,
225+
theme.color_action_cut,
226+
theme.color_background,
227+
theme.color_selected_background,
228+
);
222229
let action_drop = register_selectable_color_pairs(
223230
color_mode,
224231
theme.color_action_drop,
@@ -324,6 +331,7 @@ impl<T: Tui> Display<T> {
324331

325332
Self {
326333
action_break,
334+
action_cut,
327335
action_drop,
328336
action_edit,
329337
action_exec,
@@ -389,6 +397,7 @@ impl<T: Tui> Display<T> {
389397
if selected {
390398
match color {
391399
DisplayColor::ActionBreak => self.action_break.1,
400+
DisplayColor::ActionCut => self.action_cut.1,
392401
DisplayColor::ActionDrop => self.action_drop.1,
393402
DisplayColor::ActionEdit => self.action_edit.1,
394403
DisplayColor::ActionExec => self.action_exec.1,
@@ -413,6 +422,7 @@ impl<T: Tui> Display<T> {
413422
else {
414423
match color {
415424
DisplayColor::ActionBreak => self.action_break.0,
425+
DisplayColor::ActionCut => self.action_cut.0,
416426
DisplayColor::ActionDrop => self.action_drop.0,
417427
DisplayColor::ActionEdit => self.action_edit.0,
418428
DisplayColor::ActionExec => self.action_exec.0,

src/todo_file/src/action.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::errors::ParseError;
88
pub enum Action {
99
/// A break action.
1010
Break,
11+
/// A cut action for git-revise.
12+
Cut,
1113
/// A drop action.
1214
Drop,
1315
/// An edit action.
@@ -44,6 +46,7 @@ impl Action {
4446
String::from(match self {
4547
Self::Break => "b",
4648
Self::Drop => "d",
49+
Self::Cut => "c",
4750
Self::Edit => "e",
4851
Self::Exec => "x",
4952
Self::Fixup => "f",
@@ -65,7 +68,7 @@ impl Action {
6568
pub const fn is_static(self) -> bool {
6669
match self {
6770
Self::Break | Self::Exec | Self::Noop | Self::Reset | Self::Label | Self::Merge | Self::UpdateRef => true,
68-
Self::Drop | Self::Edit | Self::Index | Self::Fixup | Self::Pick | Self::Reword | Self::Squash => false,
71+
Self::Cut | Self::Drop | Self::Edit | Self::Index | Self::Fixup | Self::Pick | Self::Reword | Self::Squash => false,
6972
}
7073
}
7174
}
@@ -75,6 +78,7 @@ impl Display for Action {
7578
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
7679
write!(f, "{}", match *self {
7780
Self::Break => "break",
81+
Self::Cut => "cut",
7882
Self::Drop => "drop",
7983
Self::Edit => "edit",
8084
Self::Exec => "exec",

src/todo_file/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ impl TodoFile {
279279

280280
match *action {
281281
Action::Break | Action::Noop => {},
282-
Action::Drop
282+
Action::Cut
283+
| Action::Drop
283284
| Action::Fixup
284285
| Action::Edit
285286
| Action::Index

src/todo_file/src/line.rs

Lines changed: 3 additions & 2 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 | Action::Index => {
105+
Action::Pick | Action::Reword | Action::Edit | Action::Squash | Action::Drop | Action::Cut | Action::Index => {
106106
Self::new(action, line_parser.next()?, line_parser.take_remaining(), None)
107107
},
108108
Action::Fixup => {
@@ -209,6 +209,7 @@ impl Line {
209209
match self.action {
210210
Action::Exec | Action::Index | Action::Label | Action::Reset | Action::Merge | Action::UpdateRef => true,
211211
Action::Break
212+
| Action::Cut
212213
| Action::Drop
213214
| Action::Edit
214215
| Action::Fixup
@@ -231,7 +232,7 @@ impl Line {
231232
#[inline]
232233
pub fn to_text(&self) -> String {
233234
match self.action {
234-
Action::Drop | Action::Edit | Action::Fixup | Action::Index | Action::Pick | Action::Reword | Action::Squash => {
235+
Action::Cut | Action::Drop | Action::Edit | Action::Fixup | Action::Index | Action::Pick | Action::Reword | Action::Squash => {
235236
if let Some(opt) = self.option.as_ref() {
236237
format!("{} {opt} {} {}", self.action, self.hash, self.content)
237238
}

src/todo_file/src/search.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ impl Search {
3737
for (i, line) in rebase_todo.lines_iter().enumerate() {
3838
match *line.get_action() {
3939
Action::Break | Action::Noop => continue,
40-
Action::Drop
40+
Action::Cut
41+
| Action::Drop
4142
| Action::Edit
4243
| Action::Fixup
4344
| Action::Index

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::ActionCut => String::from("ActionCut"),
8687
DisplayColor::ActionIndex => String::from("ActionIndex"),
8788
DisplayColor::ActionLabel => String::from("ActionLabel"),
8889
DisplayColor::ActionReset => String::from("ActionReset"),

0 commit comments

Comments
 (0)