aboutsummaryrefslogtreecommitdiffstats
path: root/lib/msgstore.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-08-12 23:15:42 +0200
committerRobin Jarry <robin@jarry.cc>2022-08-22 10:01:46 +0200
commit588be1a28422a6c431f11f820af73e99f11342c6 (patch)
tree4d1d2e94e5e71b5c48426fe17cebe1ca5832b452 /lib/msgstore.go
parentd138da0c9fe40ae1adb152da4a22bea2fb86be19 (diff)
downloadaerc-588be1a28422a6c431f11f820af73e99f11342c6.tar.gz
store: improve cursor position
Improve cursor re-positioning while filtering with and without threads. Reposition cursor in client-side threading mode with a callback that is set during store.NextPrev(). Run callback when the threads are constructed in order to reposition the cursor correctly. The callback is deactivated when store.Select() is called. Steps to reproduce two issues: * Reproduce issue 1: 1. Activate client-side threading 2. Apply a filter, e.g. :filter -f Koni 3. Move cursor around so that a message is highlighted 4. clear filter with :clear 5. The cursor is expected to remain on the selected message but is actually not * Reproduce issue 2: 1. Activate client-side threading 2. Go the end of the message list 2. Apply a filter, e.g. :filter -f Koni 5. The cursor is now at the end of the filtered results instead of at the beginning This patch fixes both of those issues. Tested in regular and threaded view according to the following check list (expected behavior in parenthesis): 1. Apply filter from a message that remains in the filter (cursor on message, message selected) 2. Apply filter from a message that will not remain (cursor at the top, no message selected) 3. Clear filter (cursor remains on message, message selected) 4. Scroll line-by-line (threads: cursor remains on line, does not "jump" with message) 5. Search (cursor on first result) Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'lib/msgstore.go')
-rw-r--r--lib/msgstore.go48
1 files changed, 26 insertions, 22 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index d47c14fc..2832346c 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -53,7 +53,9 @@ type MessageStore struct {
threadBuilderDebounce *time.Timer
threadBuilderDelay time.Duration
+ threadCallback func()
+ // threads mutex protects the store.threads and store.threadCallback
threadsMutex sync.Mutex
}
@@ -343,6 +345,8 @@ func (store *MessageStore) SetThreadedView(thread bool) {
if store.buildThreads {
if store.threadedView {
store.runThreadBuilder()
+ } else if store.threadBuilderDebounce != nil {
+ store.threadBuilderDebounce.Stop()
}
return
}
@@ -376,35 +380,19 @@ 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
+ // save local threads to the message store variable and
+ // run callback if defined (callback should reposition cursor)
store.threadsMutex.Lock()
store.threads = th
+ if store.threadCallback != nil {
+ store.threadCallback()
+ }
store.threadsMutex.Unlock()
- // invalidate message list so that it is redrawn with the new
- // threads and selected message
+ // invalidate message list
if store.onUpdate != nil {
store.onUpdate(store)
}
@@ -543,6 +531,11 @@ func (store *MessageStore) SelectedUid() uint32 {
}
func (store *MessageStore) Select(uid uint32) {
+ store.threadsMutex.Lock()
+ if store.threadCallback != nil {
+ store.threadCallback = nil
+ }
+ store.threadsMutex.Unlock()
store.selectedUid = uid
if store.marker != nil {
store.marker.UpdateVisualMark()
@@ -572,6 +565,16 @@ func (store *MessageStore) NextPrev(delta int) {
store.Select(uids[newIdx])
+ if store.BuildThreads() && store.ThreadedView() {
+ store.threadsMutex.Lock()
+ store.threadCallback = func() {
+ if uids := store.Uids(); len(uids) > newIdx {
+ store.selectedUid = uids[newIdx]
+ }
+ }
+ store.threadsMutex.Unlock()
+ }
+
if store.marker != nil {
store.marker.UpdateVisualMark()
}
@@ -672,6 +675,7 @@ func (store *MessageStore) Sort(criteria []*types.SortCriterion, cb func(types.W
store.Sorting = true
handle_return := func(msg types.WorkerMessage) {
+ store.Select(store.SelectedUid())
store.Sorting = false
if cb != nil {
cb(msg)