From 1f453094a93d4e4c0bfc00bc0a61d448b7963ddd Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 21 May 2022 20:53:28 +0200 Subject: [PATCH] selection: don't call deselect_dive() from delete_single_dive() delete_single_dive() is one of those remnants from before the undo-code. Now it is only called in two contexts: 1) When clearing the whole dive log. 2) When importing dives from the cloud on mobile. In the first case, the selection is cleared before deleting the dives. In the second case, let's just do the same. Thus, we can remove the last call to the deselect_dive() function that does some complex calculations concerning the current dive and divecomputer. Signed-off-by: Berthold Stoeger --- core/divelist.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/divelist.c b/core/divelist.c index e4d68b616..d55c4a182 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -773,8 +773,6 @@ void delete_single_dive(int idx) struct dive *dive = get_dive(idx); if (!dive) return; /* this should never happen */ - if (dive->selected) - deselect_dive(dive); remove_dive_from_trip(dive, divelog.trips); unregister_dive_from_dive_site(dive); delete_dive_from_table(divelog.dives, idx); @@ -973,6 +971,9 @@ void add_imported_dives(struct divelog *import_log, int flags) process_imported_dives(import_log, flags, &dives_to_add, &dives_to_remove, &trips_to_add, &dive_sites_to_add, devices_to_add); + /* Start by deselecting all dives, so that we don't end up with an invalid selection */ + select_single_dive(NULL); + /* Add new dives to trip and site to get reference count correct. */ for (i = 0; i < dives_to_add.nr; i++) { struct dive *d = dives_to_add.dives[i];