Skip to content

Commit

Permalink
fix: crash on delete records
Browse files Browse the repository at this point in the history
  • Loading branch information
rfuzzo committed Apr 14, 2023
1 parent bdf79c4 commit 9902b75
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/views/records_list_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ impl TemplateApp {
// editor for a specific plugin
if let Some(data) = self.plugins.get_mut(&self.current_plugin_id) {
// a plugin was found
//if let Some(_current_record_id) = &data.current_record_id {
if (_search_text != self.search_text) || data.sorted_records.is_empty() {
// regenerate records
let mut filtered_records_by_tag: HashMap<String, Vec<String>> = HashMap::default();
Expand Down Expand Up @@ -69,15 +68,15 @@ impl TemplateApp {
}

// logic
let mut records_to_delete = vec![];
let mut record_ids_to_delete = vec![];

// the record list
egui::ScrollArea::vertical().show(ui, |ui| {
// order by tags
for tag in tags {
let records_of_tag: Vec<&TES3Object> = data.sorted_records[&tag]
.iter()
.map(|e| data.records.get(e).unwrap())
.filter_map(|e| data.records.get(e))
.collect();

if records_of_tag.is_empty() {
Expand All @@ -89,8 +88,8 @@ impl TemplateApp {
// add records
// sort

for recordt in records_of_tag.iter() {
let record = *recordt;
for record_ptr in records_of_tag.iter() {
let record = *record_ptr;
let id = get_unique_id(record);

// annotations
Expand All @@ -114,9 +113,7 @@ impl TemplateApp {
response.clone().context_menu(|ui| {
if ui.button("Delete").clicked() {
// delete a record
if !records_to_delete.contains(&id) {
records_to_delete.push(id.clone());
}
record_ids_to_delete.push(id.clone());
ui.close_menu();
}
});
Expand Down Expand Up @@ -159,9 +156,7 @@ impl TemplateApp {
if ui.button("Delete all").clicked() {
for r in records_of_tag.iter() {
let id = get_unique_id(r);
if !records_to_delete.contains(&id) {
records_to_delete.push(id.clone());
}
record_ids_to_delete.push(id.clone());
}
ui.close_menu();
}
Expand All @@ -172,10 +167,10 @@ impl TemplateApp {
});

// delete stuff
for k in records_to_delete {
record_ids_to_delete.dedup();
for k in record_ids_to_delete {
data.records.remove(&k);
}
//}
}
}
}
Expand Down

0 comments on commit 9902b75

Please sign in to comment.