summaryrefslogtreecommitdiffstats
path: root/src/tree.rs
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-11-06 14:16:46 +0100
committerqkzk <qu3nt1n@gmail.com>2023-11-06 14:16:46 +0100
commit9cf0ab8802c0c51d0da0c9dc41973932245c5737 (patch)
tree0abbf6647dbad190bc613613bd69d954d6b7c7a7 /src/tree.rs
parentc56e73e440c4b35a81ff170bc13ce22c5f84cdd3 (diff)
FIX: filename in first line
Diffstat (limited to 'src/tree.rs')
-rw-r--r--src/tree.rs60
1 files changed, 32 insertions, 28 deletions
diff --git a/src/tree.rs b/src/tree.rs
index e437bdd..08de5e7 100644
--- a/src/tree.rs
+++ b/src/tree.rs
@@ -155,26 +155,6 @@ impl Tree {
}
}
- fn increment_required_height(&mut self) {
- if self.required_height < usize::MAX {
- self.required_height += 1
- }
- }
-
- fn decrement_required_height(&mut self) {
- if self.required_height > Self::DEFAULT_REQUIRED_HEIGHT {
- self.required_height -= 1
- }
- }
-
- fn set_required_height_to_max(&mut self) {
- self.required_height = usize::MAX
- }
-
- fn reset_required_height(&mut self) {
- self.required_height = Self::DEFAULT_REQUIRED_HEIGHT
- }
-
pub fn empty() -> Self {
Self {
root_path: PathBuf::default(),
@@ -193,6 +173,18 @@ impl Tree {
self.nodes.get(&self.selected)
}
+ pub fn directory_of_selected(&self) -> Option<&Path> {
+ if self.selected.is_dir() && !self.selected.is_symlink() {
+ Some(self.selected.as_path())
+ } else {
+ self.selected.parent()
+ }
+ }
+
+ pub fn selected_path_relative_to_root(&self) -> Result<&Path> {
+ Ok(self.selected.strip_prefix(&self.root_path)?)
+ }
+
/// Select next sibling or the next sibling of the parent
pub fn select_next(&mut self) -> Result<()> {
log::info!("select_next START {sel}", sel = self.selected.display());
@@ -360,6 +352,26 @@ impl Tree {
self.set_required_height_to_max()
}
+ fn increment_required_height(&mut self) {
+ if self.required_height < usize::MAX {
+ self.required_height += 1
+ }
+ }
+
+ fn decrement_required_height(&mut self) {
+ if self.required_height > Self::DEFAULT_REQUIRED_HEIGHT {
+ self.required_height -= 1
+ }
+ }
+
+ fn set_required_height_to_max(&mut self) {
+ self.required_height = usize::MAX
+ }
+
+ fn reset_required_height(&mut self) {
+ self.required_height = Self::DEFAULT_REQUIRED_HEIGHT
+ }
+
/// Fold selected node
pub fn toggle_fold(&mut self) {
if let Some(node) = self.nodes.get_mut(&self.selected) {
@@ -379,14 +391,6 @@ impl Tree {
}
}
- pub fn directory_of_selected(&self) -> Option<&Path> {
- if self.selected.is_dir() && !self.selected.is_symlink() {
- Some(self.selected.as_path())
- } else {
- self.selected.parent()
- }
- }
-
// FIX: can only find the first match and nothing else
pub fn search_first_match(&mut self, pattern: &str) {
let initial_selected = self.selected.to_owned();