reset virtual list if notes are spliced into timeline

Calling egui_virtual_list's `items_inserted_at_start` is incorrect if we
insert notes inbetween other notes in the timeline. To prevent our list
getting confused, let's handle this case explicitly by calling 'reset'
when we splice notes in.

Ideally we would update egui_virtual_list to handle spliced-in items,
but we will leave that to a future update.
This commit is contained in:
William Casarin
2024-06-08 12:07:29 -05:00
parent 0eec8c8c2b
commit d576082297
2 changed files with 42 additions and 36 deletions

View File

@@ -35,6 +35,7 @@ impl PartialOrd for NoteRef {
}
}
#[derive(Copy, Clone, Eq, PartialEq)]
pub enum ViewFilter {
Notes,
NotesAndReplies,
@@ -306,13 +307,24 @@ pub fn timeline_view(ui: &mut egui::Ui, app: &mut Damus, timeline: usize) {
});
}
pub fn merge_sorted_vecs<T: Ord + Copy>(vec1: &[T], vec2: &[T]) -> Vec<T> {
pub enum MergeKind {
FrontInsert,
Spliced,
}
pub fn merge_sorted_vecs<T: Ord + Copy>(vec1: &[T], vec2: &[T]) -> (Vec<T>, MergeKind) {
let mut merged = Vec::with_capacity(vec1.len() + vec2.len());
let mut i = 0;
let mut j = 0;
let mut result: Option<MergeKind> = None;
while i < vec1.len() && j < vec2.len() {
if vec1[i] <= vec2[j] {
if result.is_none() && j < vec2.len() {
// if we're pushing from our large list and still have
// some left in vec2, then this is a splice
result = Some(MergeKind::Spliced);
}
merged.push(vec1[i]);
i += 1;
} else {
@@ -329,5 +341,5 @@ pub fn merge_sorted_vecs<T: Ord + Copy>(vec1: &[T], vec2: &[T]) -> Vec<T> {
merged.extend_from_slice(&vec2[j..]);
}
merged
(merged, result.unwrap_or(MergeKind::FrontInsert))
}