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>
This commit is contained in:
Koni Marti 2022-07-26 15:41:15 +02:00 committed by Robin Jarry
parent 866867c616
commit cfbb548fb8
1 changed files with 24 additions and 0 deletions

View File

@ -399,12 +399,36 @@ func (store *MessageStore) runThreadBuilder() {
} }
} }
store.threadBuilderDebounce = time.AfterFunc(store.threadBuilderDelay, func() { 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) 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.threadsMutex.Lock()
store.threads = th store.threads = th
store.threadsMutex.Unlock() store.threadsMutex.Unlock()
// invalidate message list so that it is redrawn with the new
// threads and selected message
if store.onUpdate != nil { if store.onUpdate != nil {
store.onUpdate(store) store.onUpdate(store)
} }