~rjarry/aerc

2a19c30879de90b8b902a2804204cfac15c1cd90 — Koni Marti 4 months ago 7d9ae36
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>
1 files changed, 21 insertions(+), 7 deletions(-)

M lib/msgstore.go
M lib/msgstore.go => lib/msgstore.go +21 -7
@@ 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
		}
	}