summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-01-23 22:19:13 +0100
committerqkzk <qu3nt1n@gmail.com>2023-01-23 22:19:13 +0100
commitb68ae5ae8e5b62062b977f17243531746b0bdbde (patch)
tree36b6faa9cd12a00b6ebe254219da6da22b41de6b /src
parentb5e5f95536a5c1db3d985a85c0d9e7db9b9bbb24 (diff)
almost works. Still have to select next twice after a fold...
Diffstat (limited to 'src')
-rw-r--r--src/preview.rs38
-rw-r--r--src/tab.rs4
-rw-r--r--src/tree.rs5
3 files changed, 30 insertions, 17 deletions
diff --git a/src/preview.rs b/src/preview.rs
index 8573ee9..db6fb9e 100644
--- a/src/preview.rs
+++ b/src/preview.rs
@@ -575,28 +575,32 @@ impl Directory {
self.tree.unselect_children()
}
- /// Select the next sibling if any.
- pub fn select_next_sibling(&mut self, colors: &Colors) -> FmResult<()> {
- if self.selected_index < self.content.len() {
- self.selected_index += 1;
+ /// Select the "next" element of the tree if any.
+ /// This is the element immediatly below the current one.
+ pub fn select_next(&mut self, colors: &Colors) -> FmResult<()> {
+ let step = 1;
+ if self.selected_index + step < self.content.len() {
+ self.selected_index += step;
}
- // self.tree.select_next_sibling()?;
self.tree.position = self.tree.position_from_index(self.selected_index);
- info!(
- "index: {} position {:?}",
- self.selected_index, self.tree.position
- );
self.tree.unselect_children();
let (_, _, node) = self.tree.select_from_position()?;
self.tree.current_node = node;
let res: usize;
(res, self.content) = self.tree.into_navigable_content(colors);
- info!("res {}, index {}", res, self.selected_index);
+ info!(
+ "index: {} res: {} position {:?} node {}",
+ self.selected_index,
+ res,
+ self.tree.position,
+ self.tree.current_node.filename()
+ );
Ok(())
}
/// Select the previous sibling if any.
- pub fn select_prev_sibling(&mut self, colors: &Colors) -> FmResult<()> {
+ /// This is the element immediatly below the current one.
+ pub fn select_prev(&mut self, colors: &Colors) -> FmResult<()> {
if self.selected_index > 0 {
self.selected_index -= 1;
}
@@ -606,11 +610,17 @@ impl Directory {
self.selected_index, self.tree.position
);
self.tree.unselect_children();
- self.tree.select_from_position()?;
- // self.tree.select_prev_sibling()?;
+ let (_, _, node) = self.tree.select_from_position()?;
+ self.tree.current_node = node;
let res: usize;
(res, self.content) = self.tree.into_navigable_content(colors);
- info!("res {}, index {}", res, self.selected_index);
+ info!(
+ "index: {} res: {} position {:?} node {}",
+ self.selected_index,
+ res,
+ self.tree.position,
+ self.tree.current_node.filename()
+ );
Ok(())
}
diff --git a/src/tab.rs b/src/tab.rs
index 505194b..a6ed366 100644
--- a/src/tab.rs
+++ b/src/tab.rs
@@ -270,13 +270,13 @@ impl Tab {
/// Select the next sibling.
pub fn tree_select_next_sibling(&mut self, colors: &Colors) -> FmResult<()> {
self.directory.unselect_children();
- self.directory.select_next_sibling(colors)
+ self.directory.select_next(colors)
}
/// Select the previous siblging
pub fn tree_select_prev_sibling(&mut self, colors: &Colors) -> FmResult<()> {
self.directory.unselect_children();
- self.directory.select_prev_sibling(colors)
+ self.directory.select_prev(colors)
}
/// Select the first child if any.
diff --git a/src/tree.rs b/src/tree.rs
index 4454f01..0afef15 100644
--- a/src/tree.rs
+++ b/src/tree.rs
@@ -53,9 +53,10 @@ impl ColoredString {
pub struct Node {
pub fileinfo: FileInfo,
pub position: Vec<usize>,
- folded: bool,
+ pub folded: bool,
is_dir: bool,
index: Option<usize>,
+ pub nb_leaves: usize,
}
impl Node {
@@ -178,6 +179,7 @@ impl Tree {
position: parent_position,
folded: false,
index: None,
+ nb_leaves: leaves.len(),
};
let position = vec![0];
let current_node = node.clone();
@@ -214,6 +216,7 @@ impl Tree {
folded: false,
is_dir: false,
index: None,
+ nb_leaves: 0,
};
let leaves = vec![];
let position = vec![0];