diff --git a/src/app.rs b/src/app.rs index a44b318..e47c5fd 100644 --- a/src/app.rs +++ b/src/app.rs @@ -609,13 +609,9 @@ impl App { let mut paths = Vec::new(); let entity = entity_opt.unwrap_or_else(|| self.tab_model.active()); if let Some(tab) = self.tab_model.data::(entity) { - if let Some(ref items) = tab.items_opt() { - for item in items.iter() { - if item.selected { - if let Some(Location::Path(path)) = &item.location_opt { - paths.push(path.clone()); - } - } + for location in tab.selected_locations() { + if let Some(path) = location.path_opt() { + paths.push(path.to_path_buf()); } } } diff --git a/src/tab.rs b/src/tab.rs index 8a2c220..fd78a09 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -1463,10 +1463,33 @@ impl Tab { self.items_opt.as_mut() } - pub fn set_items(&mut self, items: Vec) { + pub fn set_items(&mut self, mut items: Vec) { + let selected = self.selected_locations(); + for item in items.iter_mut() { + item.selected = false; + if let Some(location) = &item.location_opt { + if selected.contains(location) { + item.selected = true; + } + } + } self.items_opt = Some(items); } + pub fn selected_locations(&self) -> Vec { + let mut locations = Vec::new(); + if let Some(ref items) = self.items_opt { + for item in items.iter() { + if item.selected { + if let Some(location) = &item.location_opt { + locations.push(location.clone()); + } + } + } + } + locations + } + pub fn select_all(&mut self) { *self.cached_selected.borrow_mut() = None; if let Some(ref mut items) = self.items_opt {