Skip to content
Open
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
1 change: 0 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ impl<'a> App<'a> {
{
return Ok(true);
}
//
// Tab switching
else if key.code == KeyCode::Char('l') {
self.set_next_tab_with_offset(commander, 1)?;
Expand Down
16 changes: 16 additions & 0 deletions src/keybinds/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use super::Shortcut;
#[derive(Debug, Clone, serde::Deserialize)]
pub struct KeybindsConfig {
pub log_tab: Option<LogTabKeybindsConfig>,
pub files_tab: Option<FilesTabKeybindsConfig>,
}

#[derive(Debug, Clone, serde::Deserialize)]
Expand Down Expand Up @@ -51,3 +52,18 @@ pub struct LogTabKeybindsConfig {

pub open_help: Option<Keybind>,
}

#[derive(Debug, Clone, serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct FilesTabKeybindsConfig {
pub scroll_down: Option<Keybind>,
pub scroll_up: Option<Keybind>,
pub scroll_down_half: Option<Keybind>,
pub scroll_up_half: Option<Keybind>,

pub focus_current: Option<Keybind>,
pub toggle_diff_format: Option<Keybind>,

pub refresh: Option<Keybind>,
pub open_help: Option<Keybind>,
}
91 changes: 91 additions & 0 deletions src/keybinds/files_tab.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
use std::str::FromStr;

use ratatui::crossterm::event::KeyEvent;

use crate::{make_keybinds_help, set_keybinds, update_keybinds};

use super::{config::FilesTabKeybindsConfig, keybinds_store::KeybindsStore, Shortcut};

#[derive(Debug)]
pub struct FilesTabKeybinds {
// todo: probably split keys for different contexts, e.g when describe_textarea is opened
keys: KeybindsStore<FilesTabEvent>,
}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum FilesTabEvent {
ScrollDown,
ScrollUp,
ScrollDownHalf,
ScrollUpHalf,

FocusCurrent,
ToggleDiffFormat,

Refresh,
OpenHelp,

Unbound,
}

impl Default for FilesTabKeybinds {
fn default() -> Self {
let mut keys = KeybindsStore::<FilesTabEvent>::default();
set_keybinds!(
keys,
FilesTabEvent::ScrollDown => "j",
FilesTabEvent::ScrollDown => "down",
FilesTabEvent::ScrollUp => "k",
FilesTabEvent::ScrollUp => "up",
FilesTabEvent::ScrollDownHalf => "shift+j",
FilesTabEvent::ScrollUpHalf => "shift+k",
FilesTabEvent::FocusCurrent => "@",
// todo: move to DetailsKeybindings
FilesTabEvent::ToggleDiffFormat => "w",
FilesTabEvent::Refresh => "shift+r",
FilesTabEvent::Refresh => "f5",
FilesTabEvent::OpenHelp => "?",
);

Self { keys }
}
}

impl FilesTabKeybinds {
pub fn match_event(&self, event: KeyEvent) -> FilesTabEvent {
if let Some(action) = self.keys.match_event(event) {
action
} else {
FilesTabEvent::Unbound
}
}
pub fn extend_from_config(&mut self, config: &FilesTabKeybindsConfig) {
update_keybinds!(
self.keys,
FilesTabEvent::ScrollDown => config.scroll_down,
FilesTabEvent::ScrollUp => config.scroll_up,
FilesTabEvent::ScrollDownHalf => config.scroll_down_half,
FilesTabEvent::ScrollUpHalf => config.scroll_up_half,
FilesTabEvent::FocusCurrent => config.focus_current,
FilesTabEvent::ToggleDiffFormat => config.toggle_diff_format,
FilesTabEvent::Refresh => config.refresh,
FilesTabEvent::OpenHelp => config.open_help,
);
}
pub fn make_main_panel_help(&self) -> Vec<(String, String)> {
make_keybinds_help!(
self.keys,
FilesTabEvent::ScrollDown => "scroll down",
FilesTabEvent::ScrollUp => "scroll up",
FilesTabEvent::ScrollDownHalf => "scroll down by ½ page",
FilesTabEvent::ScrollUpHalf => "scroll up by ½ page",
FilesTabEvent::FocusCurrent => "view files from current change",
FilesTabEvent::Refresh => "refresh",
)
}
}

#[test]
fn test_files_tab_keybinds_default() {
let _ = FilesTabKeybinds::default();
}
1 change: 1 addition & 0 deletions src/keybinds/log_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl LogTabKeybinds {
LogTabEvent::ScrollUpHalf => "scroll up by ½ page",
LogTabEvent::OpenFiles => "see files",
LogTabEvent::FocusCurrent => "current change",
LogTabEvent::Refresh => "refresh",
LogTabEvent::EditRevset => "set revset",
LogTabEvent::Describe => "describe change",
LogTabEvent::EditChange { ignore_immutable: false } => "edit change",
Expand Down
2 changes: 2 additions & 0 deletions src/keybinds/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use std::{fmt::Display, str::FromStr};
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};

pub use config::{Keybind, KeybindsConfig};
pub use files_tab::{FilesTabEvent, FilesTabKeybinds};
pub use log_tab::{LogTabEvent, LogTabKeybinds};

mod config;
mod files_tab;
mod keybinds_store;
mod log_tab;

Expand Down
28 changes: 27 additions & 1 deletion src/ui/details_panel.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ratatui::{
crossterm::event::{KeyCode, KeyEvent, KeyModifiers},
crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind},
layout::Rect,
text::Text,
widgets::{Paragraph, Wrap},
Expand All @@ -18,10 +18,16 @@ pub struct DetailsPanel {
pub enum DetailsPanelEvent {
ScrollDown,
ScrollUp,

ScrollDownRows(isize),
ScrollUpRows(isize),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not eliminate ScrollDown / -Up ? ScrollDownRows is more accurate.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use it as "default" scroll


ScrollDownHalfPage,
ScrollUpHalfPage,

ScrollDownPage,
ScrollUpPage,

ToggleWrap,
}

Expand Down Expand Up @@ -62,6 +68,8 @@ impl DetailsPanel {
match details_panel_event {
DetailsPanelEvent::ScrollDown => self.scroll(1),
DetailsPanelEvent::ScrollUp => self.scroll(-1),
DetailsPanelEvent::ScrollDownRows(i) => self.scroll(i),
DetailsPanelEvent::ScrollUpRows(i) => self.scroll(-i),
DetailsPanelEvent::ScrollDownHalfPage => self.scroll(self.height as isize / 2),
DetailsPanelEvent::ScrollUpHalfPage => {
self.scroll((self.height as isize / 2).saturating_neg())
Expand Down Expand Up @@ -99,4 +107,22 @@ impl DetailsPanel {

true
}

pub fn match_mouse_event(
&self,
event: MouseEvent,
is_big_scroll: bool,
) -> Option<DetailsPanelEvent> {
const DETAILS_SCROLL: isize = 3;

match event.kind {
MouseEventKind::ScrollUp if is_big_scroll => Some(DetailsPanelEvent::ScrollUpHalfPage),
MouseEventKind::ScrollUp => Some(DetailsPanelEvent::ScrollUpRows(DETAILS_SCROLL)),
MouseEventKind::ScrollDown if is_big_scroll => {
Some(DetailsPanelEvent::ScrollDownHalfPage)
}
MouseEventKind::ScrollDown => Some(DetailsPanelEvent::ScrollDownRows(DETAILS_SCROLL)),
_ => None,
}
}
}
Loading