Fix cancel_input bug, scope selection on datasets, is_marked perf

- cancel_input: mode was set to Normal before checking if Search,
  so search query was never cleared on Esc
- select_group/unselect_group/invert: use dataset full_name as scope
  when cursor is on a dataset (previously used parent_path which
  matched nothing)
- is_marked: avoid unnecessary String allocation per comparison
This commit is contained in:
kidev 2026-02-20 20:31:26 +01:00
parent bddd44f3ca
commit 24960398db
2 changed files with 19 additions and 18 deletions

Binary file not shown.

View File

@ -351,7 +351,7 @@ impl App {
} }
pub fn is_marked(&self, name: &str) -> bool { pub fn is_marked(&self, name: &str) -> bool {
self.marked.contains(&name.to_string()) self.marked.iter().any(|x| x == name)
} }
pub fn delete_marked(&mut self) -> Result<()> { pub fn delete_marked(&mut self) -> Result<()> {
@ -438,8 +438,9 @@ impl App {
} }
pub fn cancel_input(&mut self) { pub fn cancel_input(&mut self) {
let was_search = self.input_mode == InputMode::Search;
self.input_mode = InputMode::Normal; self.input_mode = InputMode::Normal;
if self.input_mode == InputMode::Search { if was_search {
self.search_query.clear(); self.search_query.clear();
self.search_matches.clear(); self.search_matches.clear();
} }
@ -585,13 +586,22 @@ impl App {
} }
} }
// Select/Unselect Group (like MC) - works in current scope // Get the scope parent: if cursor is on a dataset, use its full_name;
pub fn select_group(&mut self) { // if on a snapshot, use its parent_path (the owning dataset)
let current_parent = if let Some(real_idx) = self.nth_visible(self.selected) { fn current_scope_parent(&self) -> Option<String> {
self.tree_items.get(real_idx).map(|ti| ti.parent_path.clone()) if let Some(real_idx) = self.nth_visible(self.selected) {
self.tree_items.get(real_idx).map(|ti| match &ti.item {
ListItem::Dataset(d) => d.full_name.clone(),
ListItem::Snapshot(_) => ti.parent_path.clone(),
})
} else { } else {
None None
}; }
}
// Select/Unselect Group (like MC) - works in current scope
pub fn select_group(&mut self) {
let current_parent = self.current_scope_parent();
let mut count = 0; let mut count = 0;
for ti in &self.tree_items { for ti in &self.tree_items {
@ -614,11 +624,7 @@ impl App {
} }
pub fn unselect_group(&mut self) { pub fn unselect_group(&mut self) {
let current_parent = if let Some(real_idx) = self.nth_visible(self.selected) { let current_parent = self.current_scope_parent();
self.tree_items.get(real_idx).map(|ti| ti.parent_path.clone())
} else {
None
};
let visible_names: Vec<String> = self.tree_items let visible_names: Vec<String> = self.tree_items
.iter() .iter()
@ -641,12 +647,7 @@ impl App {
} }
pub fn invert_selection(&mut self) { pub fn invert_selection(&mut self) {
// Get current scope (parent dataset of selected item) let current_parent = self.current_scope_parent();
let current_parent = if let Some(real_idx) = self.nth_visible(self.selected) {
self.tree_items.get(real_idx).map(|ti| ti.parent_path.clone())
} else {
None
};
let mut count = 0; let mut count = 0;
for ti in &self.tree_items { for ti in &self.tree_items {