notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 4fc6e225caacce70042b42fc926429ae96b45736
parent 0e0e5d0eaa74e17ce7dfa477969f05b5ac009d93
Author: William Casarin <jb55@jb55.com>
Date:   Thu, 16 May 2024 10:26:36 -0700

don't bump timeline when adding notes

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: https://github.com/damus-io/notedeck/issues/38
Fixes: https://github.com/damus-io/notedeck/issues/59
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/app.rs | 19++++++++++++++++---
Msrc/timeline.rs | 1+
2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/app.rs b/src/app.rs @@ -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); } } @@ -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, @@ -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(()) } diff --git a/src/timeline.rs b/src/timeline.rs @@ -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();