diff options
author | qkzk <qu3nt1n@gmail.com> | 2023-02-05 16:30:51 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2023-02-05 16:30:51 +0100 |
commit | ed87ec24fc2c0a3f732edf425d43614ac5fb4609 (patch) | |
tree | 6c250e42e001ed6516069195c30b1ee385ab4ecf /src | |
parent | ccbcfaf33494597635a841c8488333ba8e5be4c4 (diff) |
tree move up/down 10 lines at a time with pageup pagedownrefactored-colors
Diffstat (limited to 'src')
-rw-r--r-- | src/action_map.rs | 6 | ||||
-rw-r--r-- | src/event_exec.rs | 34 | ||||
-rw-r--r-- | src/preview.rs | 26 | ||||
-rw-r--r-- | src/tab.rs | 17 |
4 files changed, 65 insertions, 18 deletions
diff --git a/src/action_map.rs b/src/action_map.rs index 216c8b7..f84d60b 100644 --- a/src/action_map.rs +++ b/src/action_map.rs @@ -124,8 +124,8 @@ impl ActionMap { ActionMap::NewFile => EventExec::event_new_file(current_tab), ActionMap::NvimFilepicker => EventExec::event_nvim_filepicker(current_tab), ActionMap::OpenFile => EventExec::event_open_file(status), - ActionMap::PageDown => EventExec::event_page_down(status), - ActionMap::PageUp => EventExec::event_page_up(status), + ActionMap::PageDown => EventExec::event_page_down(status, colors), + ActionMap::PageUp => EventExec::event_page_up(status, colors), ActionMap::Preview => EventExec::event_preview(status, colors), ActionMap::Quit => EventExec::event_quit(current_tab), ActionMap::RefreshView => EventExec::event_refreshview(status, colors), @@ -148,7 +148,7 @@ impl ActionMap { ActionMap::TrashEmpty => EventExec::exec_trash_empty(status), ActionMap::TrashOpen => EventExec::event_trash_open(status), ActionMap::Tree => EventExec::event_tree(status, colors), - ActionMap::TreeFold => EventExec::event_tree_fold(status, colors), + ActionMap::TreeFold => EventExec::event_tree_fold(current_tab, colors), ActionMap::TreeFoldAll => EventExec::event_tree_fold_all(status, colors), ActionMap::TreeUnFoldAll => EventExec::event_tree_unfold_all(status, colors), ActionMap::OpenConfig => EventExec::event_open_config(status), diff --git a/src/event_exec.rs b/src/event_exec.rs index 2fa9e37..bfa13c7 100644 --- a/src/event_exec.rs +++ b/src/event_exec.rs @@ -1133,7 +1133,7 @@ impl EventExec { Mode::Navigate(Navigate::EncryptedDrive) => { EventExec::event_encrypted_drive_prev(status) } - Mode::Tree => EventExec::event_select_prev(status, colors)?, + Mode::Tree => EventExec::event_select_prev(status.selected(), colors)?, Mode::InputCompleted(_) => { status.selected().completion.prev(); } @@ -1155,7 +1155,7 @@ impl EventExec { EventExec::event_encrypted_drive_next(status) } Mode::InputCompleted(_) => status.selected().completion.next(), - Mode::Tree => EventExec::event_select_next(status, colors)?, + Mode::Tree => EventExec::event_select_next(status.selected(), colors)?, _ => (), }; Ok(()) @@ -1234,18 +1234,20 @@ impl EventExec { } /// Move up 10 lines in normal mode and preview. - pub fn event_page_up(status: &mut Status) -> FmResult<()> { + pub fn event_page_up(status: &mut Status, colors: &Colors) -> FmResult<()> { match status.selected().mode { Mode::Normal | Mode::Preview => EventExec::page_up(status.selected()), + Mode::Tree => EventExec::event_tree_page_up(status.selected(), colors)?, _ => (), }; Ok(()) } /// Move down 10 lines in normal & preview mode. - pub fn event_page_down(status: &mut Status) -> FmResult<()> { + pub fn event_page_down(status: &mut Status, colors: &Colors) -> FmResult<()> { match status.selected().mode { Mode::Normal | Mode::Preview => EventExec::page_down(status.selected()), + Mode::Tree => EventExec::event_tree_page_down(status.selected(), colors)?, _ => (), }; Ok(()) @@ -1481,13 +1483,11 @@ impl EventExec { /// Fold the current node of the tree. /// Has no effect on "file" nodes. - pub fn event_tree_fold(status: &mut Status, colors: &Colors) -> FmResult<()> { - let tab = status.selected(); - + pub fn event_tree_fold(tab: &mut Tab, colors: &Colors) -> FmResult<()> { let (tree, _, _) = tab.directory.tree.explore_position(false); tree.node.toggle_fold(); tab.directory.make_preview(colors); - Self::event_select_next(status, colors) + Self::event_select_next(tab, colors) } /// Unfold every child node in the tree. @@ -1526,13 +1526,23 @@ impl EventExec { } /// Select the next sibling of the current node. - pub fn event_select_next(status: &mut Status, colors: &Colors) -> FmResult<()> { - status.selected().tree_select_next(colors) + pub fn event_select_next(tab: &mut Tab, colors: &Colors) -> FmResult<()> { + tab.tree_select_next(colors) } /// Select the previous sibling of the current node. - pub fn event_select_prev(status: &mut Status, colors: &Colors) -> FmResult<()> { - status.selected().tree_select_prev(colors) + pub fn event_select_prev(tab: &mut Tab, colors: &Colors) -> FmResult<()> { + tab.tree_select_prev(colors) + } + + /// Move up 10 lines in the tree + pub fn event_tree_page_up(tab: &mut Tab, colors: &Colors) -> FmResult<()> { + tab.tree_page_up(colors) + } + + /// Move down 10 lines in the tree + pub fn event_tree_page_down(tab: &mut Tab, colors: &Colors) -> FmResult<()> { + tab.tree_page_down(colors) } /// Select the last leaf of the tree and reset the view. diff --git a/src/preview.rs b/src/preview.rs index f469361..8300dbb 100644 --- a/src/preview.rs +++ b/src/preview.rs @@ -602,7 +602,7 @@ impl Directory { if self.selected_index + 1 < self.content.len() { self.selected_index += 1; } - self.update_tree_from_index(colors) + self.update_tree_position_from_index(colors) } /// Select the previous sibling if any. @@ -611,10 +611,30 @@ impl Directory { if self.selected_index > 0 { self.selected_index -= 1; } - self.update_tree_from_index(colors) + self.update_tree_position_from_index(colors) } - pub fn update_tree_from_index(&mut self, colors: &Colors) -> FmResult<()> { + /// Move up 10 times. + pub fn page_up(&mut self, colors: &Colors) -> FmResult<()> { + if self.selected_index > 10 { + self.selected_index -= 10; + } else { + self.selected_index = 1; + } + self.update_tree_position_from_index(colors) + } + + /// Move down 10 times + pub fn page_down(&mut self, colors: &Colors) -> FmResult<()> { + self.selected_index += 10; + if self.selected_index >= self.content.len() { + self.selected_index = self.content.len() - 1; + } + self.update_tree_position_from_index(colors) + } + + /// Update the position of the selected element from its index. + pub fn update_tree_position_from_index(&mut self, colors: &Colors) -> FmResult<()> { self.tree.position = self.tree.position_from_index(self.selected_index); let (_, _, node) = self.tree.select_from_position()?; self.tree.current_node = node; @@ -283,6 +283,18 @@ impl Tab { self.directory.select_parent(colors) } + /// Move down 10 times in the tree + pub fn tree_page_down(&mut self, colors: &Colors) -> FmResult<()> { + self.directory.unselect_children(); + self.directory.page_down(colors) + } + + /// Move up 10 times in the tree + pub fn tree_page_up(&mut self, colors: &Colors) -> FmResult<()> { + self.directory.unselect_children(); + self.directory.page_up(colors) + } + /// Select the next sibling. pub fn tree_select_next(&mut self, colors: &Colors) -> FmResult<()> { self.directory.unselect_children(); @@ -353,16 +365,21 @@ impl Tab { Ok(()) } + /// Set a new mode and save the last one pub fn set_mode(&mut self, new_mode: Mode) { self.previous_mode = self.mode; self.mode = new_mode; } + /// Reset the last mode. + /// The last mode is set to normal again. pub fn reset_mode(&mut self) { self.mode = self.previous_mode; self.previous_mode = Mode::Normal; } + /// Returns true if the current mode requires 2 windows. + /// Only Tree, Normal & Preview doesn't require 2 windows. pub fn need_second_window(&self) -> bool { !matches!(self.mode, Mode::Normal | Mode::Tree | Mode::Preview) } |