summaryrefslogtreecommitdiffstats
path: root/src
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
parentd78e36a0648f580ad950e6dc26b886de7fed180b (diff)
add H, L and M vim actions
Diffstat (limited to 'src')
-rw-r--r--src/commands/cursor_move.rs46
-rw-r--r--src/key_command/command.rs3
-rw-r--r--src/key_command/constants.rs3
-rw-r--r--src/key_command/impl_appcommand.rs3
-rw-r--r--src/key_command/impl_appexecute.rs4
-rw-r--r--src/key_command/impl_comment.rs4
-rw-r--r--src/key_command/impl_from_str.rs12
-rw-r--r--src/ui/mod.rs30
-rw-r--r--src/ui/preview_area.rs18
-rw-r--r--src/ui/rect.rs7
10 files changed, 102 insertions, 28 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(())
}
diff --git a/src/key_command/command.rs b/src/key_command/command.rs
index dd1eaca..0829a09 100644
--- a/src/key_command/command.rs
+++ b/src/key_command/command.rs
@@ -28,6 +28,9 @@ pub enum Command {
CursorMoveEnd,
CursorMovePageUp(f64),
CursorMovePageDown(f64),
+ CursorMovePageHome,
+ CursorMovePageMiddle,
+ CursorMovePageEnd,
ParentCursorMoveUp(usize),
ParentCursorMoveDown(usize),
diff --git a/src/key_command/constants.rs b/src/key_command/constants.rs
index 29d1591..74ada44 100644
--- a/src/key_command/constants.rs
+++ b/src/key_command/constants.rs
@@ -40,6 +40,9 @@ cmd_constants![
(CMD_CURSOR_MOVE_END, "cursor_move_end"),
(CMD_CURSOR_MOVE_PAGEUP, "cursor_move_page_up"),
(CMD_CURSOR_MOVE_PAGEDOWN, "cursor_move_page_down"),
+ (CMD_CURSOR_MOVE_PAGEHOME, "cursor_move_page_home"),
+ (CMD_CURSOR_MOVE_PAGEMIDDLE, "cursor_move_page_middle"),
+ (CMD_CURSOR_MOVE_PAGEEND, "cursor_move_page_end"),
(CMD_PARENT_CURSOR_MOVE_UP, "parent_cursor_move_up"),
(CMD_PARENT_CURSOR_MOVE_DOWN, "parent_cursor_move_down"),
(CMD_PREVIEW_CURSOR_MOVE_UP, "preview_cursor_move_up"),
diff --git a/src/key_command/impl_appcommand.rs b/src/key_command/impl_appcommand.rs
index d4e9f28..478b8e1 100644
--- a/src/key_command/impl_appcommand.rs
+++ b/src/key_command/impl_appcommand.rs
@@ -34,6 +34,9 @@ impl AppCommand for Command {
Self::CursorMoveEnd => CMD_CURSOR_MOVE_END,
Self::CursorMovePageUp(_) => CMD_CURSOR_MOVE_PAGEUP,
Self::CursorMovePageDown(_) => CMD_CURSOR_MOVE_PAGEDOWN,
+ Self::CursorMovePageHome => CMD_CURSOR_MOVE_PAGEUP,
+ Self::CursorMovePageMiddle => CMD_CURSOR_MOVE_PAGEDOWN,
+ Self::CursorMovePageEnd => CMD_CURSOR_MOVE_PAGEDOWN,
Self::ParentCursorMoveUp(_) => CMD_PARENT_CURSOR_MOVE_UP,
Self::ParentCursorMoveDown(_) => CMD_PARENT_CURSOR_MOVE_DOWN,
diff --git a/src/key_command/impl_appexecute.rs b/src/key_command/impl_appexecute.rs
index 6b652b5..bb2e752 100644
--- a/src/key_command/impl_appexecute.rs
+++ b/src/key_command/impl_appexecute.rs
@@ -45,6 +45,10 @@ impl AppExecute for Command {
Self::CursorMovePageUp(p) => cursor_move::page_up(context, backend, *p),
Self::CursorMovePageDown(p) => cursor_move::page_down(context, backend, *p),
+ Self::CursorMovePageHome => cursor_move::page_home(context, backend),
+ Self::CursorMovePageMiddle => cursor_move::page_middle(context, backend),
+ Self::CursorMovePageEnd => cursor_move::page_end(context, backend),
+
Self::ParentCursorMoveUp(u) => parent_cursor_move::parent_up(context, *u),
Self::ParentCursorMoveDown(u) => parent_cursor_move::parent_down(context, *u),
diff --git a/src/key_command/impl_comment.rs b/src/key_command/impl_comment.rs
index 99234f7..b7d3cc5 100644
--- a/src/key_command/impl_comment.rs
+++ b/src/key_command/impl_comment.rs
@@ -47,6 +47,10 @@ impl CommandComment for Command {
Self::CursorMovePageUp(_) => "Move cursor one page up",
Self::CursorMovePageDown(_) => "Move cursor one page down",
+ Self::CursorMovePageHome => "Move cursor to top of page",
+ Self::CursorMovePageMiddle => "Move cursor to middle of page",
+ Self::CursorMovePageEnd => "Move cursor to bottom of page",
+
Self::ParentCursorMoveUp(_) => "Cursor up in parent list",
Self::ParentCursorMoveDown(_) => "Cursor down in parent list",
diff --git a/src/key_command/impl_from_str.rs b/src/key_command/impl_from_str.rs
index 8bd6ff5..5fd86ac 100644
--- a/src/key_command/impl_from_str.rs
+++ b/src/key_command/impl_from_str.rs
@@ -49,6 +49,18 @@ impl std::str::FromStr for Command {
simple_command_conversion_case!(command, CMD_CURSOR_MOVE_HOME, Self::CursorMoveHome);
simple_command_conversion_case!(command, CMD_CURSOR_MOVE_END, Self::CursorMoveEnd);
+ simple_command_conversion_case!(
+ command,
+ CMD_CURSOR_MOVE_PAGEHOME,
+ Self::CursorMovePageHome
+ );
+ simple_command_conversion_case!(
+ command,
+ CMD_CURSOR_MOVE_PAGEMIDDLE,
+ Self::CursorMovePageMiddle
+ );
+ simple_command_conversion_case!(command, CMD_CURSOR_MOVE_PAGEEND, Self::CursorMovePageEnd);
+
simple_command_conversion_case!(command, CMD_CUT_FILES, Self::CutFiles);
simple_command_conversion_case!(command, CMD_DELETE_FILES, Self::DeleteFiles);
diff --git a/src/ui/mod.rs b/src/ui/mod.rs
index c71feb6..2b19584 100644
--- a/src/ui/mod.rs
+++ b/src/ui/mod.rs
@@ -1,30 +1,10 @@
-use std::path;
-
+mod preview_area;
+mod rect;
mod tui_backend;
+
pub mod views;
pub mod widgets;
+pub use preview_area::*;
+pub use rect::*;
pub use tui_backend::*;
-
-#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
-pub struct Rect {
- pub x: u16,
- pub y: u16,
- pub width: u16,
- pub height: u16,
-}
-
-#[derive(Debug, Clone)]
-pub struct PreviewArea {
- pub file_preview_path: path::PathBuf,
- pub preview_area: Rect,
-}
-
-impl PreviewArea {
- pub fn new(file_preview_path: path::PathBuf, preview_area: Rect) -> Self {
- Self {
- file_preview_path,
- preview_area,
- }
- }
-}
diff --git a/src/ui/preview_area.rs b/src/ui/preview_area.rs
new file mode 100644
index 0000000..faf0269
--- /dev/null
+++ b/src/ui/preview_area.rs
@@ -0,0 +1,18 @@
+use std::path;
+
+use super::Rect;
+
+#[derive(Debug, Clone)]
+pub struct PreviewArea {
+ pub file_preview_path: path::PathBuf,
+ pub preview_area: Rect,
+}
+
+impl PreviewArea {
+ pub fn new(file_preview_path: path::PathBuf, preview_area: Rect) -> Self {
+ Self {
+ file_preview_path,
+ preview_area,
+ }
+ }
+}
diff --git a/src/ui/rect.rs b/src/ui/rect.rs
new file mode 100644
index 0000000..32d317c
--- /dev/null
+++ b/src/ui/rect.rs
@@ -0,0 +1,7 @@
+#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
+pub struct Rect {
+ pub x: u16,
+ pub y: u16,
+ pub width: u16,
+ pub height: u16,
+}