summaryrefslogtreecommitdiffstats
path: root/src/commands
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2022-04-20 11:19:34 -0400
committerJeff Zhao <jeff.no.zhao@gmail.com>2022-04-20 11:20:34 -0400
commit763815418ac3acd56aa7e936c48861ae6e73ca40 (patch)
treef8213b7ffaf588dc49ad83f502b5db42f2c435e2 /src/commands
parentd78e36a0648f580ad950e6dc26b886de7fed180b (diff)
add H, L and M vim actions
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/cursor_move.rs46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs
index 5757b47..64809c5 100644
--- a/src/commands/cursor_move.rs
+++ b/src/commands/cursor_move.rs
@@ -166,14 +166,54 @@ pub fn page_down(
let page_size = get_page_size(context, backend).unwrap_or(10) as f64 * proportion;
let page_size = page_size as usize;
- let movement = context
+ let new_index = context
.tab_context_ref()
.curr_tab_ref()
.curr_list_ref()
.and_then(|list| list.get_index().map(|idx| idx.saturating_add(page_size)));
- if let Some(s) = movement {
- cursor_move(context, s);
+ if let Some(idx) = new_index {
+ cursor_move(context, idx);
+ }
+ Ok(())
+}
+
+pub fn page_home(context: &mut AppContext, _: &mut TuiBackend) -> JoshutoResult {
+ let new_index = context
+ .tab_context_ref()
+ .curr_tab_ref()
+ .curr_list_ref()
+ .map(|curr_list| curr_list.first_index_for_viewport());
+ if let Some(idx) = new_index {
+ cursor_move(context, idx);
+ }
+ Ok(())
+}
+
+pub fn page_middle(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult {
+ let movement = get_page_size(context, backend).unwrap_or(10) / 2;
+
+ let new_index = context
+ .tab_context_ref()
+ .curr_tab_ref()
+ .curr_list_ref()
+ .map(|curr_list| curr_list.first_index_for_viewport() + movement);
+ if let Some(idx) = new_index {
+ cursor_move(context, idx);
+ }
+ Ok(())
+}
+
+pub fn page_end(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult {
+ let movement = get_page_size(context, backend).unwrap_or(10) - 1;
+
+ let new_index = context
+ .tab_context_ref()
+ .curr_tab_ref()
+ .curr_list_ref()
+ .map(|curr_list| curr_list.first_index_for_viewport() + movement);
+ if let Some(idx) = new_index {
+ cursor_move(context, idx);
}
Ok(())
}