Skip to content

Commit

Permalink
don't bump timeline when adding notes
Browse files Browse the repository at this point in the history
This is quite different than Damus iOS. The timeline will continually
add new items without bumping scroll position, thanks to
egui-virtual-list's `items_inserted_at_start` function.

Closes: #38
Fixes: #59
Signed-off-by: William Casarin <jb55@jb55.com>
  • Loading branch information
jb55 committed May 16, 2024
1 parent 0e0e5d0 commit 4fc6e22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn try_process_event(damus: &mut Damus, ctx: &egui::Context) -> Result<()> {
let txn = Transaction::new(&damus.ndb)?;
let mut unknown_ids: HashSet<UnknownId> = HashSet::new();
for timeline in 0..damus.timelines.len() {
if let Err(err) = poll_notes_for_timeline(damus, &txn, timeline, &mut unknown_ids) {
if let Err(err) = poll_notes_for_timeline(ctx, damus, &txn, timeline, &mut unknown_ids) {
error!("{}", err);
}
}
Expand Down Expand Up @@ -238,6 +238,7 @@ fn get_unknown_note_ids<'a>(
}

fn poll_notes_for_timeline<'a>(
ctx: &egui::Context,
damus: &mut Damus,
txn: &'a Transaction,
timeline: usize,
Expand Down Expand Up @@ -268,8 +269,20 @@ fn poll_notes_for_timeline<'a>(
})
.collect();

damus.timelines[timeline].notes =
timeline::merge_sorted_vecs(&damus.timelines[timeline].notes, &new_refs);
let timeline = &mut damus.timelines[timeline];
let prev_items = timeline.notes.len();
timeline.notes = timeline::merge_sorted_vecs(&timeline.notes, &new_refs);
let new_items = timeline.notes.len() - prev_items;

// TODO: technically items could have been added inbetween
timeline
.list
.clone()
.lock()
.unwrap()
.items_inserted_at_start(new_items);

ctx.request_repaint();

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions src/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ pub fn timeline_view(ui: &mut egui::Ui, app: &mut Damus, timeline: usize) {
ui.add_space(3.0);

egui::ScrollArea::vertical()
.animated(false)
.scroll_bar_visibility(ScrollBarVisibility::AlwaysVisible)
.show(ui, |ui| {
let len = app.timelines[timeline].notes.len();
Expand Down

0 comments on commit 4fc6e22

Please sign in to comment.