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
8 changes: 8 additions & 0 deletions KEY_CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ Create a `key_bindings.ron` file like this:
)
```

Horizontal diff paging defaults to `Ctrl+Left` and `Ctrl+Right`. Override
`page_left` and `page_right` to use different bindings:
```
(
page_left: Some(( code: Left, modifiers: "ALT")),
page_right: Some(( code: Right, modifiers: "ALT")),
)

The config file format based on the [Ron file format](https://github.com/ron-rs/ron).
The location of the file depends on your OS:
* `$HOME/.config/gitui/key_bindings.ron` (mac)
Expand Down
20 changes: 18 additions & 2 deletions src/components/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,8 @@ impl Component for DiffComponent {
_force_all: bool,
) -> CommandBlocking {
out.push(CommandInfo::new(
strings::commands::scroll(&self.key_config),
self.can_scroll(),
strings::commands::diff_scroll(&self.key_config),
self.can_scroll() || self.max_scroll_right() > 0,
self.focused(),
));
out.push(CommandInfo::new(
Expand Down Expand Up @@ -861,6 +861,22 @@ impl Component for DiffComponent {
{
self.move_selection(ScrollType::PageDown);
Ok(EventState::Consumed)
} else if key_match(
e,
self.key_config.keys.page_right,
) {
self.horizontal_scroll.move_page(
HorizontalScrollType::Right,
self.current_size.get().0.into(),
);
Ok(EventState::Consumed)
} else if key_match(e, self.key_config.keys.page_left)
{
self.horizontal_scroll.move_page(
HorizontalScrollType::Left,
self.current_size.get().0.into(),
);
Ok(EventState::Consumed)
} else if key_match(
e,
self.key_config.keys.move_right,
Expand Down
39 changes: 39 additions & 0 deletions src/components/utils/scroll_horizontal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,34 @@ impl HorizontalScroll {
true
}

pub fn move_page(
&self,
move_type: HorizontalScrollType,
page_width: usize,
) -> bool {
let old = self.right.get();
let max = self.max_right.get();
let page_width = page_width.saturating_sub(1).max(1);

let new_scroll_right = match move_type {
HorizontalScrollType::Left => {
old.saturating_sub(page_width)
}
HorizontalScrollType::Right => {
old.saturating_add(page_width)
}
};

let new_scroll_right = new_scroll_right.clamp(0, max);

if new_scroll_right == old {
return false;
}

self.right.set(new_scroll_right);

true
}
pub fn update(
&self,
selection: usize,
Expand Down Expand Up @@ -130,4 +158,15 @@ mod tests {
fn test_scroll_zero_width() {
assert_eq!(calc_scroll_right(4, 0, 4, 3), 0);
}

#[test]
fn test_scroll_page_left_right() {
let scroll = HorizontalScroll::new();
scroll.update_no_selection(100, 20);

assert!(scroll.move_page(HorizontalScrollType::Right, 20));
assert_eq!(scroll.get_right(), 19);
assert!(scroll.move_page(HorizontalScrollType::Left, 20));
assert_eq!(scroll.get_right(), 0);
}
}
4 changes: 4 additions & 0 deletions src/keys/key_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pub struct KeysList {
pub popup_down: GituiKeyEvent,
pub page_down: GituiKeyEvent,
pub page_up: GituiKeyEvent,
pub page_left: GituiKeyEvent,
pub page_right: GituiKeyEvent,
pub shift_up: GituiKeyEvent,
pub shift_down: GituiKeyEvent,
pub enter: GituiKeyEvent,
Expand Down Expand Up @@ -162,6 +164,8 @@ impl Default for KeysList {
popup_down: GituiKeyEvent::new(KeyCode::Down, KeyModifiers::empty()),
page_down: GituiKeyEvent::new(KeyCode::PageDown, KeyModifiers::empty()),
page_up: GituiKeyEvent::new(KeyCode::PageUp, KeyModifiers::empty()),
page_left: GituiKeyEvent::new(KeyCode::Left, KeyModifiers::CONTROL),
page_right: GituiKeyEvent::new(KeyCode::Right, KeyModifiers::CONTROL),
shift_up: GituiKeyEvent::new(KeyCode::Up, KeyModifiers::SHIFT),
shift_down: GituiKeyEvent::new(KeyCode::Down, KeyModifiers::SHIFT),
enter: GituiKeyEvent::new(KeyCode::Enter, KeyModifiers::empty()),
Expand Down
15 changes: 15 additions & 0 deletions src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,21 @@ pub mod commands {
CMD_GROUP_GENERAL,
)
}
pub fn diff_scroll(key_config: &SharedKeyConfig) -> CommandText {
CommandText::new(
format!(
"Scroll [{}{}{}{}{}{}]",
key_config.get_hint(key_config.keys.move_up),
key_config.get_hint(key_config.keys.move_down),
key_config.get_hint(key_config.keys.page_up),
key_config.get_hint(key_config.keys.page_down),
key_config.get_hint(key_config.keys.page_left),
key_config.get_hint(key_config.keys.page_right)
),
"scroll vertically or horizontally in diff",
CMD_GROUP_DIFF,
)
}
pub fn commit_list_mark(
key_config: &SharedKeyConfig,
marked: bool,
Expand Down