diff options
author | Stephan Dilly <dilly.stephan@gmail.com> | 2021-05-24 11:07:32 +0200 |
---|---|---|
committer | Stephan Dilly <dilly.stephan@gmail.com> | 2021-05-24 11:07:32 +0200 |
commit | a5b63e593645e00f2d127d71706873ddf0df558e (patch) | |
tree | 3a3f3bd5b52aac0ef96fd5b5dfbe3e8761dabfa4 /src/ui | |
parent | 0dd1afb9db1855fc84c54d4dad58a6676fac06e4 (diff) |
support common nav for syntax view (closes #725)
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/mod.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 2b4646cd..7734b08d 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -5,6 +5,7 @@ mod stateful_paragraph; pub mod style; mod syntax_text; +use filetree::MoveSelection; pub use scrollbar::draw_scrollbar; pub use scrolllist::{draw_list, draw_list_block}; pub use stateful_paragraph::{ @@ -13,6 +14,8 @@ pub use stateful_paragraph::{ pub use syntax_text::{AsyncSyntaxJob, SyntaxText}; use tui::layout::{Constraint, Direction, Layout, Rect}; +use crate::keys::SharedKeyConfig; + /// return the scroll position (line) necessary to have the `selection` in view if it is not already pub const fn calc_scroll_top( current_top: usize, @@ -109,3 +112,29 @@ pub fn centered_rect_absolute( height.min(r.height), ) } + +/// +pub fn common_nav( + key: crossterm::event::KeyEvent, + key_config: &SharedKeyConfig, +) -> Option<MoveSelection> { + if key == key_config.move_down { + Some(MoveSelection::Down) + } else if key == key_config.move_up { + Some(MoveSelection::Up) + } else if key == key_config.page_up { + Some(MoveSelection::PageUp) + } else if key == key_config.page_down { + Some(MoveSelection::PageDown) + } else if key == key_config.move_right { + Some(MoveSelection::Right) + } else if key == key_config.move_left { + Some(MoveSelection::Left) + } else if key == key_config.home || key == key_config.shift_up { + Some(MoveSelection::Top) + } else if key == key_config.end || key == key_config.shift_down { + Some(MoveSelection::End) + } else { + None + } +} |