diff --git a/src/components/filetree.rs b/src/components/filetree.rs index cc522141..8bba9d45 100644 --- a/src/components/filetree.rs +++ b/src/components/filetree.rs @@ -89,7 +89,7 @@ impl FileTreeComponent { /// pub fn file_count(&self) -> usize { - self.tree.tree.len() + self.tree.tree.file_count() } /// diff --git a/src/components/utils/filetree.rs b/src/components/utils/filetree.rs index a52a0b9e..48c17fd2 100644 --- a/src/components/utils/filetree.rs +++ b/src/components/utils/filetree.rs @@ -136,7 +136,10 @@ impl Ord for FileTreeItem { /// #[derive(Default)] -pub struct FileTreeItems(Vec); +pub struct FileTreeItems { + items: Vec, + file_count: usize, +} impl FileTreeItems { /// @@ -144,7 +147,7 @@ impl FileTreeItems { list: &[StatusItem], collapsed: &BTreeSet<&String>, ) -> Result { - let mut nodes = Vec::with_capacity(list.len()); + let mut items = Vec::with_capacity(list.len()); let mut paths_added = BTreeSet::new(); for e in list { @@ -153,26 +156,34 @@ impl FileTreeItems { Self::push_dirs( item_path, - &mut nodes, + &mut items, &mut paths_added, collapsed, )?; } - nodes.push(FileTreeItem::new_file(e)?); + items.push(FileTreeItem::new_file(e)?); } - Ok(Self(nodes)) + Ok(Self { + items, + file_count: list.len(), + }) } /// pub(crate) const fn items(&self) -> &Vec { - &self.0 + &self.items } /// pub(crate) fn len(&self) -> usize { - self.0.len() + self.items.len() + } + + /// + pub fn file_count(&self) -> usize { + self.file_count } /// @@ -184,7 +195,7 @@ impl FileTreeItems { if let Some(parent_path) = Path::new(path).parent() { let parent_path = parent_path.to_str().unwrap(); for i in (0..=index).rev() { - let item = &self.0[i]; + let item = &self.items[i]; let item_path = &item.info.full_path; if item_path == parent_path { return i; @@ -227,7 +238,7 @@ impl FileTreeItems { impl IndexMut for FileTreeItems { fn index_mut(&mut self, idx: usize) -> &mut Self::Output { - &mut self.0[idx] + &mut self.items[idx] } } @@ -235,7 +246,7 @@ impl Index for FileTreeItems { type Output = FileTreeItem; fn index(&self, idx: usize) -> &Self::Output { - &self.0[idx] + &self.items[idx] } } @@ -264,7 +275,7 @@ mod tests { FileTreeItems::new(&items, &BTreeSet::new()).unwrap(); assert_eq!( - res.0, + res.items, vec![FileTreeItem { info: TreeItemInfo { path: items[0].path.clone(), @@ -284,8 +295,8 @@ mod tests { let res = FileTreeItems::new(&items, &BTreeSet::new()).unwrap(); - assert_eq!(res.0.len(), 2); - assert_eq!(res.0[1].info.path, items[1].path); + assert_eq!(res.items.len(), 2); + assert_eq!(res.items[1].info.path, items[1].path); } #[test] @@ -296,7 +307,7 @@ mod tests { let res = FileTreeItems::new(&items, &BTreeSet::new()) .unwrap() - .0 + .items .iter() .map(|i| i.info.full_path.clone()) .collect::>(); @@ -316,7 +327,7 @@ mod tests { let list = FileTreeItems::new(&items, &BTreeSet::new()).unwrap(); let mut res = list - .0 + .items .iter() .map(|i| (i.info.indent, i.info.path.as_str())); @@ -335,7 +346,7 @@ mod tests { let list = FileTreeItems::new(&items, &BTreeSet::new()).unwrap(); let mut res = list - .0 + .items .iter() .map(|i| (i.info.indent, i.info.path.as_str())); @@ -353,7 +364,7 @@ mod tests { let res = FileTreeItems::new(&items, &BTreeSet::new()) .unwrap() - .0 + .items .iter() .map(|i| i.info.full_path.clone()) .collect::>();