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>
This commit is contained in:
Koni Marti 2022-03-14 11:49:37 +01:00 committed by Robin Jarry
parent 7d9ae36977
commit 2a19c30879
1 changed files with 21 additions and 7 deletions

View File

@ -32,6 +32,7 @@ type MessageStore struct {
// Search/filter results // Search/filter results
results []uint32 results []uint32
resultIndex int resultIndex int
filtered []uint32
filter bool filter bool
defaultSortCriteria []*types.SortCriterion defaultSortCriteria []*types.SortCriterion
@ -358,7 +359,7 @@ func (store *MessageStore) runThreadBuilder() {
} }
var uids []uint32 var uids []uint32
if store.filter { if store.filter {
uids = store.results uids = store.filtered
} else { } else {
uids = store.uids uids = store.uids
} }
@ -449,7 +450,7 @@ func (store *MessageStore) Uids() []uint32 {
} }
if store.filter { if store.filter {
return store.results return store.filtered
} }
return store.uids return store.uids
} }
@ -620,8 +621,18 @@ func (store *MessageStore) Search(args []string, cb func([]uint32)) {
}, func(msg types.WorkerMessage) { }, func(msg types.WorkerMessage) {
switch msg := msg.(type) { switch msg := msg.(type) {
case *types.SearchResults: case *types.SearchResults:
sort.SortBy(msg.Uids, store.uids) allowedUids := store.Uids()
cb(msg.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) { func (store *MessageStore) ApplyFilter(results []uint32) {
store.results = results store.results = nil
store.filtered = results
store.filter = true store.filter = true
store.update() store.update()
// any marking is now invalid // any marking is now invalid
@ -643,6 +655,7 @@ func (store *MessageStore) ApplyFilter(results []uint32) {
func (store *MessageStore) ApplyClear() { func (store *MessageStore) ApplyClear() {
store.results = nil store.results = nil
store.filtered = nil
store.filter = false store.filter = false
if store.BuildThreads() { if store.BuildThreads() {
store.runThreadBuilder() store.runThreadBuilder()
@ -660,9 +673,10 @@ func (store *MessageStore) nextPrevResult(delta int) {
if store.resultIndex < 0 { if store.resultIndex < 0 {
store.resultIndex = len(store.results) - 1 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 { if store.results[len(store.results)-store.resultIndex-1] == uid {
store.Select(len(store.uids) - i - 1) store.Select(len(uids) - i - 1)
break break
} }
} }