Skip to content

Commit e1d1a4e

Browse files
committed
WIP: add cut action for git-revise
1 parent f9b62a4 commit e1d1a4e

File tree

14 files changed

+50
-8
lines changed

14 files changed

+50
-8
lines changed

readme/customization.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Most keys can be changed to any printable character or supported special charact
115115
| `inputActionPick` | p | String | Key for setting action to pick |
116116
| `inputActionReword` | r | String | Key for setting action to reword |
117117
| `inputActionSquash` | s | String | Key for setting action to squash |
118+
| `inputActionCut` | x | String | Key for setting action to cut (git-revise) |
118119
| `inputActionIndex` | i | String | Key for setting action to index (git-revise) |
119120
| `inputConfirmNo` | n | String | Key for rejecting a confirmation |
120121
| `inputConfirmYes` | y | String | Key for confirming a confirmation |

src/config/key_bindings.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub(crate) struct KeyBindings {
2020
pub(crate) abort: Vec<String>,
2121
/// Key bindings for the break action.
2222
pub(crate) action_break: Vec<String>,
23+
/// Key bindings for the cut action.
24+
pub(crate) action_cut: Vec<String>,
2325
/// Key bindings for the drop action.
2426
pub(crate) action_drop: Vec<String>,
2527
/// Key bindings for the edit action.
@@ -128,6 +130,7 @@ impl KeyBindings {
128130
Ok(Self {
129131
abort: get_input(git_config, "interactive-rebase-tool.inputAbort", "q")?,
130132
action_break: get_input(git_config, "interactive-rebase-tool.inputActionBreak", "b")?,
133+
action_cut: get_input(git_config, "interactive-rebase-tool.inputActionCut", "x")?,
131134
action_drop: get_input(git_config, "interactive-rebase-tool.inputActionDrop", "d")?,
132135
action_edit: get_input(git_config, "interactive-rebase-tool.inputActionEdit", "e")?,
133136
action_fixup: get_input(git_config, "interactive-rebase-tool.inputActionFixup", "f")?,

src/config/theme.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub(crate) struct Theme {
3131
pub(crate) character_vertical_spacing: String,
3232
/// The color for the break action.
3333
pub(crate) color_action_break: Color,
34+
/// The color for the cut action.
35+
pub(crate) color_action_cut: Color,
3436
/// The color for the drop action.
3537
pub(crate) color_action_drop: Color,
3638
/// The color for the edit action.
@@ -85,6 +87,7 @@ impl Theme {
8587
"~",
8688
)?,
8789
color_action_break: get_color(git_config, "interactive-rebase-tool.breakColor", Color::LightWhite)?,
90+
color_action_cut: get_color(git_config, "interactive-rebase-tool.cutColor", Color::DarkRed)?,
8891
color_action_drop: get_color(git_config, "interactive-rebase-tool.dropColor", Color::LightRed)?,
8992
color_action_edit: get_color(git_config, "interactive-rebase-tool.editColor", Color::LightBlue)?,
9093
color_action_exec: get_color(git_config, "interactive-rebase-tool.execColor", Color::LightWhite)?,

src/display.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use crate::config::Theme;
3434
#[derive(Debug)]
3535
pub(crate) struct Display<T: Tui> {
3636
action_break: (Colors, Colors),
37+
action_cut: (Colors, Colors),
3738
action_drop: (Colors, Colors),
3839
action_edit: (Colors, Colors),
3940
action_exec: (Colors, Colors),
@@ -78,6 +79,12 @@ impl<T: Tui> Display<T> {
7879
theme.color_background,
7980
theme.color_selected_background,
8081
);
82+
let action_cut = register_selectable_color_pairs(
83+
color_mode,
84+
theme.color_action_cut,
85+
theme.color_background,
86+
theme.color_selected_background,
87+
);
8188
let action_drop = register_selectable_color_pairs(
8289
color_mode,
8390
theme.color_action_drop,
@@ -183,6 +190,7 @@ impl<T: Tui> Display<T> {
183190

184191
Self {
185192
action_break,
193+
action_cut,
186194
action_drop,
187195
action_edit,
188196
action_exec,
@@ -244,6 +252,7 @@ impl<T: Tui> Display<T> {
244252
if selected {
245253
match color {
246254
DisplayColor::ActionBreak => self.action_break.1,
255+
DisplayColor::ActionCut => self.action_cut.1,
247256
DisplayColor::ActionDrop => self.action_drop.1,
248257
DisplayColor::ActionEdit => self.action_edit.1,
249258
DisplayColor::ActionExec => self.action_exec.1,
@@ -268,6 +277,7 @@ impl<T: Tui> Display<T> {
268277
else {
269278
match color {
270279
DisplayColor::ActionBreak => self.action_break.0,
280+
DisplayColor::ActionCut => self.action_cut.0,
271281
DisplayColor::ActionDrop => self.action_drop.0,
272282
DisplayColor::ActionEdit => self.action_edit.0,
273283
DisplayColor::ActionExec => self.action_exec.0,

src/display/display_color.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
pub(crate) 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/input/key_bindings.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ pub(crate) struct KeyBindings {
4040
pub(crate) abort: Vec<Event>,
4141
/// Key bindings for the break action.
4242
pub(crate) action_break: Vec<Event>,
43+
/// Key bindings for the cut action.
44+
pub(crate) action_cut: Vec<Event>,
4345
/// Key bindings for the drop action.
4446
pub(crate) action_drop: Vec<Event>,
4547
/// Key bindings for the edit action.
@@ -123,6 +125,7 @@ impl KeyBindings {
123125
search_previous: map_keybindings(&key_bindings.search_previous),
124126
abort: map_keybindings(&key_bindings.abort),
125127
action_break: map_keybindings(&key_bindings.action_break),
128+
action_cut: map_keybindings(&key_bindings.action_cut),
126129
action_drop: map_keybindings(&key_bindings.action_drop),
127130
action_edit: map_keybindings(&key_bindings.action_edit),
128131
action_fixup: map_keybindings(&key_bindings.action_fixup),

src/input/standard_event.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ pub(crate) enum StandardEvent {
4949
ForceRebase,
5050
/// The break action meta event.
5151
ActionBreak,
52+
/// The cut (git-revise) action meta event.
53+
ActionCut,
5254
/// The drop action meta event.
5355
ActionDrop,
5456
/// The edit action meta event.

src/modules/list.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ impl List {
554554
match event {
555555
e if key_bindings.abort.contains(&e) => Event::from(StandardEvent::Abort),
556556
e if key_bindings.action_break.contains(&e) => Event::from(StandardEvent::ActionBreak),
557+
e if key_bindings.action_cut.contains(&e) => Event::from(StandardEvent::ActionCut),
557558
e if key_bindings.action_drop.contains(&e) => Event::from(StandardEvent::ActionDrop),
558559
e if key_bindings.action_edit.contains(&e) => Event::from(StandardEvent::ActionEdit),
559560
e if key_bindings.action_fixup.contains(&e) => Event::from(StandardEvent::ActionFixup),
@@ -643,6 +644,7 @@ impl List {
643644
Event::Standard(standard_event) => {
644645
match standard_event {
645646
StandardEvent::Abort => self.abort(&mut results),
647+
StandardEvent::ActionCut => self.set_selected_line_action(Action::Cut),
646648
StandardEvent::ActionDrop => self.set_selected_line_action(Action::Drop),
647649
StandardEvent::ActionEdit => self.set_selected_line_action(Action::Edit),
648650
StandardEvent::ActionFixup => self.set_selected_line_action(Action::Fixup),

src/modules/list/search.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ impl Searchable for Search {
5959

6060
let has_hash_match = match action {
6161
Action::Break | Action::Noop | Action::Label | Action::Reset | Action::Merge | Action::Exec => false,
62-
Action::Drop
62+
Action::Cut
63+
| Action::Drop
6364
| Action::Edit
6465
| Action::Fixup
6566
| Action::Index
@@ -70,7 +71,8 @@ impl Searchable for Search {
7071
};
7172
let has_content_match = match action {
7273
Action::Break | Action::Noop => false,
73-
Action::Drop
74+
Action::Cut
75+
| Action::Drop
7476
| Action::Edit
7577
| Action::Fixup
7678
| Action::Index

src/modules/list/tests/help.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fn normal_mode_help() {
4040
" s |Set selected commits to be squashed",
4141
" f |Set selected commits to be fixed-up",
4242
" d |Set selected commits to be dropped",
43+
" x |Set selected commits to be cut / split (git-revise)",
4344
" i |Set selected commits to be staged in the index (git-revise)",
4445
" E |Edit an exec, label, reset or merge action's content",
4546
" I |Insert a new line",
@@ -106,6 +107,7 @@ fn visual_mode_help() {
106107
" s |Set selected commits to be squashed",
107108
" f |Set selected commits to be fixed-up",
108109
" d |Set selected commits to be dropped",
110+
" x |Set selected commits to be cut / split (git-revise)",
109111
" i |Set selected commits to be staged in the index (git-revise)",
110112
" Delete |Completely remove the selected lines",
111113
" Controlz|Undo the last change",

src/modules/list/utils.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ fn build_help_lines(key_bindings: &KeyBindings, selector: HelpLinesSelector) ->
127127
"Set selected commits to be dropped",
128128
HelpLinesSelector::Common,
129129
),
130+
(
131+
&key_bindings.action_cut,
132+
"Set selected commits to be cut / split (git-revise)",
133+
HelpLinesSelector::Common,
134+
),
130135
(
131136
&key_bindings.action_index,
132137
"Set selected commits to be staged in the index (git-revise)",
@@ -190,6 +195,7 @@ pub(super) fn get_list_visual_mode_help_lines(key_bindings: &KeyBindings) -> Vec
190195
const fn get_action_color(action: Action) -> DisplayColor {
191196
match action {
192197
Action::Break => DisplayColor::ActionBreak,
198+
Action::Cut => DisplayColor::ActionCut,
193199
Action::Drop => DisplayColor::ActionDrop,
194200
Action::Edit => DisplayColor::ActionEdit,
195201
Action::Exec => DisplayColor::ActionExec,
@@ -214,7 +220,7 @@ pub(super) fn get_line_action_maximum_width(todo_file: &TodoFile) -> usize {
214220
let action_length = match line.get_action() {
215221
// allow these to overflow their bounds
216222
&Action::Exec | &Action::UpdateRef => 0,
217-
&Action::Drop | &Action::Edit | &Action::Noop | &Action::Pick => 4,
223+
&Action::Cut | &Action::Drop | &Action::Edit | &Action::Noop | &Action::Pick => 4,
218224
&Action::Break | &Action::Label | &Action::Reset | &Action::Merge | &Action::Index => 5,
219225
&Action::Fixup => {
220226
if line.option().is_some() {
@@ -303,7 +309,7 @@ pub(super) fn get_todo_line_segments(
303309

304310
// render hash
305311
match *action {
306-
Action::Drop | Action::Edit | Action::Fixup | Action::Index | Action::Pick | Action::Reword | Action::Squash => {
312+
Action::Cut | Action::Drop | Action::Edit | Action::Fixup | Action::Index | Action::Pick | Action::Reword | Action::Squash => {
307313
let action_width = if is_full_width { 8 } else { 3 };
308314
let max_index = cmp::min(line.get_hash().len(), action_width);
309315
let search_hash_match = search_match.map_or(false, |m| m.hash());

src/todo_file.rs

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

153153
match *action {
154154
Action::Break | Action::Noop => {},
155-
Action::Drop
155+
Action::Cut
156+
| Action::Drop
156157
| Action::Fixup
157158
| Action::Edit
158159
| Action::Index

src/todo_file/action.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::todo_file::ParseError;
88
pub(crate) 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.
@@ -43,6 +45,7 @@ impl Action {
4345
String::from(match self {
4446
Self::Break => "b",
4547
Self::Drop => "d",
48+
Self::Cut => "c",
4649
Self::Edit => "e",
4750
Self::Exec => "x",
4851
Self::Fixup => "f",
@@ -63,7 +66,7 @@ impl Action {
6366
pub(crate) const fn is_static(self) -> bool {
6467
match self {
6568
Self::Break | Self::Exec | Self::Noop | Self::Reset | Self::Label | Self::Merge | Self::UpdateRef => true,
66-
Self::Drop | Self::Edit | Self::Index | Self::Fixup | Self::Pick | Self::Reword | Self::Squash => false,
69+
Self::Cut | Self::Drop | Self::Edit | Self::Index | Self::Fixup | Self::Pick | Self::Reword | Self::Squash => false,
6770
}
6871
}
6972
}
@@ -72,6 +75,7 @@ impl Display for Action {
7275
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
7376
write!(f, "{}", match *self {
7477
Self::Break => "break",
78+
Self::Cut => "cut",
7579
Self::Drop => "drop",
7680
Self::Edit => "edit",
7781
Self::Exec => "exec",

src/todo_file/line.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl Line {
9595
Ok(match action {
9696
Action::Noop => Self::new_noop(),
9797
Action::Break => Self::new_break(),
98-
Action::Pick | Action::Reword | Action::Edit | Action::Squash | Action::Drop | Action::Index => {
98+
Action::Pick | Action::Reword | Action::Edit | Action::Squash | Action::Drop | Action::Cut | Action::Index => {
9999
Self::new(action, line_parser.next()?, line_parser.take_remaining(), None)
100100
},
101101
Action::Fixup => {
@@ -192,6 +192,7 @@ impl Line {
192192
match self.action {
193193
Action::Exec | Action::Index | Action::Label | Action::Reset | Action::Merge | Action::UpdateRef => true,
194194
Action::Break
195+
| Action::Cut
195196
| Action::Drop
196197
| Action::Edit
197198
| Action::Fixup
@@ -212,7 +213,7 @@ impl Line {
212213
#[must_use]
213214
pub(crate) fn to_text(&self) -> String {
214215
match self.action {
215-
Action::Drop | Action::Edit | Action::Fixup | Action::Index | Action::Pick | Action::Reword | Action::Squash => {
216+
Action::Cut | Action::Drop | Action::Edit | Action::Fixup | Action::Index | Action::Pick | Action::Reword | Action::Squash => {
216217
if let Some(opt) = self.option.as_ref() {
217218
format!("{} {opt} {} {}", self.action, self.hash, self.content)
218219
}

0 commit comments

Comments
 (0)