summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-03-14 11:49:37 +0100
committerRobin Jarry <robin@jarry.cc>2022-03-14 23:59:58 +0100
commit2a19c30879de90b8b902a2804204cfac15c1cd90 (patch)
tree8e048de650c3cbb1ce9134e851a3fda07d3033a3 /lib
parent7d9ae369774c471d4527e4a52e94585301cb751e (diff)
downloadaerc-2a19c30879de90b8b902a2804204cfac15c1cd90.zip
store: allow consecutive filter and search queries
Enable consecutive filter and search queries. Filter narrows down message list consecutively and clears search results. Search applies to the current message list. Fixes: https://todo.sr.ht/~rjarry/aerc/24 Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Inwit <inwit@sindominio.net> Tested-by: Moritz Poldrack <git@moritz.sh> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib')
-rw-r--r--lib/msgstore.go28
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 5a86d41..ddc2d56 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -32,6 +32,7 @@ type MessageStore struct {
// Search/filter results
results []uint32
resultIndex int
+ filtered []uint32
filter bool
defaultSortCriteria []*types.SortCriterion
@@ -358,7 +359,7 @@ func (store *MessageStore) runThreadBuilder() {
}
var uids []uint32
if store.filter {
- uids = store.results
+ uids = store.filtered
} else {
uids = store.uids
}
@@ -449,7 +450,7 @@ func (store *MessageStore) Uids() []uint32 {
}
if store.filter {
- return store.results
+ return store.filtered
}
return store.uids
}
@@ -620,8 +621,18 @@ func (store *MessageStore) Search(args []string, cb func([]uint32)) {
}, func(msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.SearchResults:
- sort.SortBy(msg.Uids, store.uids)
- cb(msg.Uids)
+ allowedUids := store.Uids()
+ uids := make([]uint32, 0, len(msg.Uids))
+ for _, uid := range msg.Uids {
+ for _, uidCheck := range allowedUids {
+ if uid == uidCheck {
+ uids = append(uids, uid)
+ break
+ }
+ }
+ }
+ sort.SortBy(uids, allowedUids)
+ cb(uids)
}
})
}
@@ -633,7 +644,8 @@ func (store *MessageStore) ApplySearch(results []uint32) {
}
func (store *MessageStore) ApplyFilter(results []uint32) {
- store.results = results
+ store.results = nil
+ store.filtered = results
store.filter = true
store.update()
// any marking is now invalid
@@ -643,6 +655,7 @@ func (store *MessageStore) ApplyFilter(results []uint32) {
func (store *MessageStore) ApplyClear() {
store.results = nil
+ store.filtered = nil
store.filter = false
if store.BuildThreads() {
store.runThreadBuilder()
@@ -660,9 +673,10 @@ func (store *MessageStore) nextPrevResult(delta int) {
if store.resultIndex < 0 {
store.resultIndex = len(store.results) - 1
}
- for i, uid := range store.uids {
+ uids := store.Uids()
+ for i, uid := range uids {
if store.results[len(store.results)-store.resultIndex-1] == uid {
- store.Select(len(store.uids) - i - 1)
+ store.Select(len(uids) - i - 1)
break
}
}