Skip to content

Commit

Permalink
Add bindings 'H' and 'G' to go to the top/bottom of any pane
Browse files Browse the repository at this point in the history
Fixes #78
  • Loading branch information
Byron committed Feb 15, 2021
1 parent 8cc2f44 commit 8b606ac
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#### v2.11.0

* Add binding capital 'H' to go to the top of any pane/list
* Add binding capital 'G' to go to the bottom of any pane/list

#### v2.10.10 - Fix --version flag

It looks like the latest BETAs of clap removed setting the version implicitly.
Expand Down
8 changes: 7 additions & 1 deletion src/interactive/app/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ impl AppState {
self.dispatch_to_mark_pane(key, window, traversal, *display, terminal)
}
FocussedPane::Help => {
window.help_pane.as_mut().expect("help pane").key(key);
window
.help_pane
.as_mut()
.expect("help pane")
.process_events(key);
}
FocussedPane::Main => match key {
Char('O') => self.open_that(traversal),
Expand Down Expand Up @@ -138,6 +142,8 @@ impl AppState {
Char('o') | Char('l') | Char('\n') | Right => {
self.enter_node_with_traversal(traversal)
}
Char('H') => self.change_entry_selection(CursorDirection::ToTop),
Char('G') => self.change_entry_selection(CursorDirection::ToBottom),
Ctrl('u') | PageUp => self.change_entry_selection(CursorDirection::PageUp),
Char('k') | Up => self.change_entry_selection(CursorDirection::Up),
Char('j') | Down => self.change_entry_selection(CursorDirection::Down),
Expand Down
6 changes: 5 additions & 1 deletion src/interactive/app/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ pub enum CursorDirection {
Down,
Up,
PageUp,
ToTop,
ToBottom,
}

impl CursorDirection {
pub fn move_cursor(&self, n: usize) -> usize {
use CursorDirection::*;
match self {
ToTop => 0,
ToBottom => usize::MAX,
Down => n.saturating_add(1),
Up => n.saturating_sub(1),
PageDown => n.saturating_add(10),
Expand Down Expand Up @@ -202,7 +206,7 @@ impl AppState {
) where
B: Backend,
{
let res = window.mark_pane.take().and_then(|p| p.key(key));
let res = window.mark_pane.take().and_then(|p| p.process_events(key));
window.mark_pane = match res {
Some((pane, mode)) => match mode {
Some(MarkMode::Delete) => {
Expand Down
6 changes: 5 additions & 1 deletion src/interactive/widgets/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ fn margin(r: Rect, margin: u16) -> Rect {
}

impl HelpPane {
pub fn key(&mut self, key: Key) {
pub fn process_events(&mut self, key: Key) {
match key {
Char('H') => self.scroll_help(CursorDirection::ToTop),
Char('G') => self.scroll_help(CursorDirection::ToBottom),
Ctrl('u') | PageUp => self.scroll_help(CursorDirection::PageUp),
Char('k') | Up => self.scroll_help(CursorDirection::Up),
Char('j') | Down => self.scroll_help(CursorDirection::Down),
Expand Down Expand Up @@ -120,6 +122,8 @@ impl HelpPane {
hotkey("<Page Down>", "^", None);
hotkey("Ctrl + u", "move up 10 entries at once", None);
hotkey("<Page Up>", "^", None);
hotkey("H", "Move to the top of the entries list", None);
hotkey("G", "Move to the bottomw of the entries list", None);
spacer();
}
title("Keys for display");
Expand Down
4 changes: 3 additions & 1 deletion src/interactive/widgets/mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ impl MarkPane {
pub fn marked(&self) -> &EntryMarkMap {
&self.marked
}
pub fn key(mut self, key: Key) -> Option<(Self, Option<MarkMode>)> {
pub fn process_events(mut self, key: Key) -> Option<(Self, Option<MarkMode>)> {
let action = None;
match key {
Ctrl('r') => return self.prepare_deletion(),
Char('x') | Char('d') | Char(' ') => {
return self.remove_selected().map(|s| (s, action))
}
Char('H') => self.change_selection(CursorDirection::ToTop),
Char('G') => self.change_selection(CursorDirection::ToBottom),
Ctrl('u') | PageUp => self.change_selection(CursorDirection::PageUp),
Char('k') | Up => self.change_selection(CursorDirection::Up),
Char('j') | Down => self.change_selection(CursorDirection::Down),
Expand Down

0 comments on commit 8b606ac

Please sign in to comment.