mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-19 09:22:12 +00:00
fix
This commit is contained in:
1 parent
1bfd319758
commit
005cc7b305
1 file changed
+13
-13
@@ -124,9 +124,9 @@ impl Editor for Cleaner<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes what the clean left empty: the emptied segments, the tracks that lost all their
|
/// Removes what the clean left empty: the emptied segments and the tracks that lost all their
|
||||||
/// segments and the files that lost something and have nothing left. The selection falls back
|
/// segments. A file is never removed, even if nothing is left in it: it stays, empty. The
|
||||||
/// to the closest element still existing.
|
/// selection falls back to the closest element still existing.
|
||||||
fn prune(state: &mut State, emptied: &HashSet<TrackSegmentId>, wpt_files: &HashSet<FileId>) {
|
fn prune(state: &mut State, emptied: &HashSet<TrackSegmentId>, wpt_files: &HashSet<FileId>) {
|
||||||
let ids: Vec<FileId> = state
|
let ids: Vec<FileId> = state
|
||||||
.files
|
.files
|
||||||
@@ -142,19 +142,13 @@ fn prune(state: &mut State, emptied: &HashSet<TrackSegmentId>, wpt_files: &HashS
|
|||||||
.collect();
|
.collect();
|
||||||
for id in ids {
|
for id in ids {
|
||||||
let mut file = (*state.files[&id]).clone();
|
let mut file = (*state.files[&id]).clone();
|
||||||
let lost_something = !emptied.is_empty() || wpt_files.contains(&id);
|
|
||||||
file.trk.retain_mut(|trk| {
|
file.trk.retain_mut(|trk| {
|
||||||
let len = trk.trkseg.len();
|
let len = trk.trkseg.len();
|
||||||
trk.trkseg.retain(|seg| !emptied.contains(&seg.id));
|
trk.trkseg.retain(|seg| !emptied.contains(&seg.id));
|
||||||
trk.trkseg.len() == len || !trk.trkseg.is_empty()
|
trk.trkseg.len() == len || !trk.trkseg.is_empty()
|
||||||
});
|
});
|
||||||
if lost_something && file.trk.is_empty() && file.wpt.is_empty() {
|
|
||||||
state.files.remove(&id);
|
|
||||||
state.order.0.retain(|f| *f != id);
|
|
||||||
} else {
|
|
||||||
state.files.insert(id, Rc::new(file));
|
state.files.insert(id, Rc::new(file));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
*state.selection = fixed_selection(state);
|
*state.selection = fixed_selection(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,10 +291,16 @@ mod tests {
|
|||||||
.apply(&mut fx.state())
|
.apply(&mut fx.state())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(count(&fx, id), 0);
|
assert_eq!(count(&fx, id), 0);
|
||||||
// nothing is left of the file
|
// nothing is left in the file, which stays and is still selected
|
||||||
assert!(!fx.files.contains_key(&id));
|
let file = &fx.files[&id];
|
||||||
assert!(fx.order.0.is_empty());
|
assert!(file.trk.is_empty() && file.wpt.is_empty());
|
||||||
assert_eq!(fx.selection, Selection::Empty);
|
assert_eq!(fx.order.0, [id]);
|
||||||
|
assert_eq!(
|
||||||
|
fx.selection,
|
||||||
|
Selection::File {
|
||||||
|
file_ids: HashSet::from([id])
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in new issue
Block a user