From cfbb548fb86fb81b69809f9f1b68bbb60e823a40 Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Tue, 26 Jul 2022 15:41:15 +0200 Subject: [PATCH] threads: match regular view scrolling behavior Try to keep the position in the message list when scrolling through threaded messages to match the scrolling behavior of the regular view. This only needs to be implemented for the client-side threading since we have to rebuild the threads when new messages arrive. Reported-by: akspecs Signed-off-by: Koni Marti Acked-by: Akspecs Acked-by: Robin Jarry --- lib/msgstore.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/msgstore.go b/lib/msgstore.go index 32acfb4..783ce5d 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -399,12 +399,36 @@ func (store *MessageStore) runThreadBuilder() { } } store.threadBuilderDebounce = time.AfterFunc(store.threadBuilderDelay, func() { + + // temporarily deactiviate the selector in the message list by + // setting SelectedUid to the MagicUid + oldUid := store.SelectedUid() + store.Select(MagicUid) + + // Get the current index (we want to stay at that position in + // the updated uid list to provide a similar scrolling + // experience to the user as in the regular view + idx := store.FindIndexByUid(oldUid) + + // build new threads th := store.builder.Threads(store.uids) + // try to select the same index in the updated uid list; if + // index is out of bound, stay at the selected message + rebuildUids := store.builder.Uids() + if idx >= 0 && idx < len(rebuildUids) { + store.Select(rebuildUids[idx]) + } else { + store.Select(oldUid) + } + + // save local threads to the message store variable store.threadsMutex.Lock() store.threads = th store.threadsMutex.Unlock() + // invalidate message list so that it is redrawn with the new + // threads and selected message if store.onUpdate != nil { store.onUpdate(store) }