Preserve selections through external changes, part of #500
This commit is contained in:
parent
b91088482b
commit
03b6b6bb45
2 changed files with 27 additions and 8 deletions
25
src/tab.rs
25
src/tab.rs
|
|
@ -1463,10 +1463,33 @@ impl Tab {
|
|||
self.items_opt.as_mut()
|
||||
}
|
||||
|
||||
pub fn set_items(&mut self, items: Vec<Item>) {
|
||||
pub fn set_items(&mut self, mut items: Vec<Item>) {
|
||||
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<Location> {
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue