Fix search highlight indices after tree rebuild (v0.2.2)
This commit is contained in:
parent
6d94330830
commit
bddd44f3ca
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "zfsdu"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
edition = "2021"
|
||||
description = "ncdu-like disk usage viewer for ZFS with snapshot management"
|
||||
authors = ["Florian Schermer"]
|
||||
|
||||
Binary file not shown.
24
src/app.rs
24
src/app.rs
@ -212,6 +212,7 @@ impl App {
|
||||
pub fn rebuild_tree(&mut self) {
|
||||
self.tree_items = Self::build_tree_view(&self.root_entries, 0, &[], &self.expanded, "");
|
||||
self.apply_filter();
|
||||
self.refresh_search_matches();
|
||||
self.ensure_valid_selection();
|
||||
}
|
||||
|
||||
@ -561,6 +562,29 @@ impl App {
|
||||
self.search_matches.contains(&real_index)
|
||||
}
|
||||
|
||||
fn refresh_search_matches(&mut self) {
|
||||
if self.search_query.is_empty() {
|
||||
return;
|
||||
}
|
||||
self.search_matches.clear();
|
||||
let query = self.search_query.to_lowercase();
|
||||
for (i, tree_item) in self.tree_items.iter().enumerate() {
|
||||
if tree_item.visible {
|
||||
let name = tree_item.item.full_name().to_lowercase();
|
||||
if name.contains(&query) {
|
||||
self.search_matches.push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if !self.search_matches.is_empty() {
|
||||
if self.current_match >= self.search_matches.len() {
|
||||
self.current_match = self.search_matches.len() - 1;
|
||||
}
|
||||
} else {
|
||||
self.current_match = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Select/Unselect Group (like MC) - works in current scope
|
||||
pub fn select_group(&mut self) {
|
||||
let current_parent = if let Some(real_idx) = self.nth_visible(self.selected) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user