Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/commander/jj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ impl Commander {
.context("Failed executing jj describe")
}

/// Rebase changes. Maps to `jj rebase -s <rev> -d <rev>` or similar
#[instrument(level = "trace", skip(self))]
pub fn run_rebase(
&mut self,
src_mode: &str,
src_rev: &str,
tgt_mode: &str,
tgt_rev: &str,
) -> Result<()> {
Ok(self.execute_void_jj_command(vec!["rebase", src_mode, src_rev, tgt_mode, tgt_rev])?)
}

/// Squash changes. Maps to `jj squash -u --into <revision>`
#[instrument(level = "trace", skip(self))]
pub fn run_squash(&mut self, revision: &str, ignore_immutable: bool) -> Result<()> {
Expand Down
1 change: 1 addition & 0 deletions src/keybinds/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct LogTabKeybindsConfig {
pub edit_revset: Option<Keybind>,
pub set_bookmark: Option<Keybind>,
pub open_files: Option<Keybind>,
pub rebase: Option<Keybind>,

pub push: Option<Keybind>,
pub push_new: Option<Keybind>,
Expand Down
4 changes: 4 additions & 0 deletions src/keybinds/log_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub enum LogTabEvent {
CreateNew {
describe: bool,
},
Rebase,
Squash {
ignore_immutable: bool,
},
Expand Down Expand Up @@ -77,6 +78,7 @@ impl Default for LogTabKeybinds {
LogTabEvent::Refresh => "f5",
LogTabEvent::CreateNew { describe: false } => "n",
LogTabEvent::CreateNew { describe: true } => "shift+n",
LogTabEvent::Rebase => "ctrl+r",
LogTabEvent::Squash { ignore_immutable: false } => "s",
LogTabEvent::Squash { ignore_immutable: true } => "shift+s",
LogTabEvent::EditChange { ignore_immutable: false } => "e",
Expand Down Expand Up @@ -131,6 +133,7 @@ impl LogTabKeybinds {
LogTabEvent::EditRevset => config.edit_revset,
LogTabEvent::SetBookmark => config.set_bookmark,
LogTabEvent::OpenFiles => config.open_files,
LogTabEvent::Rebase => config.rebase,
event_push(false, false) => config.push,
event_push(false, true) => config.push_new,
event_push(true, false) => config.push_all,
Expand All @@ -156,6 +159,7 @@ impl LogTabKeybinds {
LogTabEvent::CreateNew { describe: false } => "new change",
LogTabEvent::CreateNew { describe: true } => "new with message",
LogTabEvent::Abandon => "abandon change",
LogTabEvent::Rebase => "rebase @ to the selected change",
LogTabEvent::Squash { ignore_immutable: false } => "squash @ into the selected change",
LogTabEvent::Squash { ignore_immutable: true } => "squash @ into the selected change ignoring immutability",
LogTabEvent::SetBookmark => "set bookmark",
Expand Down
1 change: 1 addition & 0 deletions src/keybinds/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub use log_tab::{LogTabEvent, LogTabKeybinds};
mod config;
mod keybinds_store;
mod log_tab;
pub mod rebase_popup;

/*#[derive(Debug)]
pub struct Keybinds {
Expand Down
73 changes: 73 additions & 0 deletions src/keybinds/rebase_popup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*! Key bindings specific for rebase popup */

use ratatui::crossterm::event::KeyEvent;
use std::str::FromStr; // used by set_keybinds macro

use super::{Shortcut, keybinds_store::KeybindsStore};
use crate::set_keybinds;

/// How should rebase cut revisions from source
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum CutOption {
IncludeDescendants, // -s
IncludeBranch, // -b
SingleRevision, // -r
}

/// How should rebase paste revisions at target
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum PasteOption {
NewBranch, // -d
InsertAfter, // -A
InsertBefore, // -B
}

/// Actions available inside a RebasePopup
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum PopupAction {
None,
Ok,
Cancel,
SetSourceMode(CutOption),
SetTargetMode(PasteOption),
}

fn default_keybinds() -> KeybindsStore<PopupAction> {
let mut keys = KeybindsStore::<PopupAction>::default();
set_keybinds!(
keys,
PopupAction::Ok => "enter",
PopupAction::Cancel => "esc",
PopupAction::Cancel => "q",
PopupAction::SetSourceMode(CutOption::IncludeDescendants) => "s",
PopupAction::SetSourceMode(CutOption::IncludeBranch) => "b",
PopupAction::SetSourceMode(CutOption::SingleRevision) => "r",
PopupAction::SetTargetMode(PasteOption::NewBranch) => "d",
PopupAction::SetTargetMode(PasteOption::InsertAfter) => "shift+a",
PopupAction::SetTargetMode(PasteOption::InsertBefore) => "shift+b",
);
keys
}

#[derive(Debug)]
pub struct Keybinds {
keys: KeybindsStore<PopupAction>,
}

impl Default for Keybinds {
fn default() -> Self {
Self {
keys: default_keybinds(),
}
}
}

impl Keybinds {
pub fn match_event(&self, event: KeyEvent) -> PopupAction {
if let Some(action) = self.keys.match_event(event) {
action
} else {
PopupAction::None
}
}
}
49 changes: 48 additions & 1 deletion src/ui/log_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::{
message_popup::MessagePopup,
panel::DetailsPanel,
panel::LogPanel,
rebase_popup::RebasePopup,
utils::{centered_rect, centered_rect_line_height, tabs_to_spaces},
},
};
Expand Down Expand Up @@ -66,6 +67,8 @@ pub struct LogTab<'a> {
describe_textarea: Option<TextArea<'a>>,
describe_after_new: bool,

rebase_popup: Option<RebasePopup>,

squash_ignore_immutable: bool,

edit_ignore_immutable: bool,
Expand Down Expand Up @@ -121,6 +124,8 @@ impl<'a> LogTab<'a> {
describe_textarea: None,
describe_after_new: false,

rebase_popup: None,

squash_ignore_immutable: false,

edit_ignore_immutable: false,
Expand Down Expand Up @@ -195,6 +200,14 @@ impl<'a> LogTab<'a> {
.open();
self.describe_after_new = describe;
}
LogTabEvent::Rebase => {
let source_change = commander.get_current_head()?;
let target_change = &self.head;
self.rebase_popup = Some(RebasePopup::new(
source_change.clone(),
target_change.clone(),
));
}
LogTabEvent::Squash { ignore_immutable } => {
if self.head.change_id == commander.get_current_head()?.change_id {
return Ok(ComponentInputResult::HandledAction(
Expand Down Expand Up @@ -604,6 +617,13 @@ impl Component for LogTab<'_> {
}
}

// Draw rebase popup
{
if let Some(log_rebase_popup) = &mut self.rebase_popup {
log_rebase_popup.render_widget(f)
}
}

Ok(())
}

Expand Down Expand Up @@ -657,7 +677,34 @@ impl Component for LogTab<'_> {
return Ok(ComponentInputResult::Handled);
}

if let Event::Key(key) = event {
if let Some(rebase_popup) = &mut self.rebase_popup {
let handled = rebase_popup.handle_input(commander, event.clone());
if handled.is_err() {
// Close popup and show error message
self.rebase_popup = None;
let msg = handled.err().unwrap();
let error_message = msg.to_string().into_text()?;
return Ok(ComponentInputResult::HandledAction(
ComponentAction::SetPopup(Some(Box::new(MessagePopup {
title: "Error".into(),
messages: error_message,
text_align: None,
}))),
));
}
if handled.ok() == Some(true) {
// when handle_input returns true,
// the popup should be closed
self.rebase_popup = None;
return Ok(ComponentInputResult::HandledAction(
ComponentAction::RefreshTab(),
));
}
return Ok(ComponentInputResult::Handled);
}

if let Event::Key(key) = &event {
let key = *key;
if key.kind != KeyEventKind::Press {
return Ok(ComponentInputResult::Handled);
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod help_popup;
pub mod log_tab;
pub mod message_popup;
pub mod panel;
pub mod rebase_popup;
pub mod styles;
pub mod utils;

Expand Down
Loading
Loading