aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-07-26 15:41:15 +0200
committerRobin Jarry <robin@jarry.cc>2022-07-26 22:22:56 +0200
commitcfbb548fb86fb81b69809f9f1b68bbb60e823a40 (patch)
tree499d4bbf8d1f36b908302284ff07e6a06d0783db
parent866867c6160b2701a2ddd74480d2a62d15b2ffe6 (diff)
downloadaerc-cfbb548fb86fb81b69809f9f1b68bbb60e823a40.tar.gz
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 <akspecs@gmail.com> Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Akspecs <akspecs@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--lib/msgstore.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 32acfb42..783ce5d0 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)
}