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

0 commit comments

Comments
 (0)