sort: keep sort criteria applied to folder

Keep the sort criteria applied to the selected folder until the default
sort order should be restored. Call the sort command without arguments
to restore the default sort order.

The current behavior is that the default sort order is restored as soon
as the folder reloads. This happens often and then the results of the
sort command are lost. This makes the sort command not very
user-friendly. Instead, we should keep the sort criteria applied until
the user explicitly wants to restore the default sort order again.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Koni Marti 2022-03-24 23:12:14 +01:00 committed by Robin Jarry
parent af2a70983c
commit e50ab59284
3 changed files with 16 additions and 8 deletions

View file

@ -7,6 +7,7 @@ import (
"git.sr.ht/~rjarry/aerc/commands" "git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/lib/sort" "git.sr.ht/~rjarry/aerc/lib/sort"
"git.sr.ht/~rjarry/aerc/widgets" "git.sr.ht/~rjarry/aerc/widgets"
"git.sr.ht/~rjarry/aerc/worker/types"
) )
type Sort struct{} type Sort struct{}
@ -70,9 +71,15 @@ func (Sort) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("Messages still loading.") return errors.New("Messages still loading.")
} }
sortCriteria, err := sort.GetSortCriteria(args[1:]) var err error
if err != nil { var sortCriteria []*types.SortCriterion
return err if len(args[1:]) == 0 {
sortCriteria = acct.GetSortCriteria()
} else {
sortCriteria, err = sort.GetSortCriteria(args[1:])
if err != nil {
return err
}
} }
aerc.SetStatus("Sorting") aerc.SetStatus("Sorting")

View file

@ -35,7 +35,7 @@ type MessageStore struct {
filtered []uint32 filtered []uint32
filter bool filter bool
defaultSortCriteria []*types.SortCriterion sortCriteria []*types.SortCriterion
thread bool thread bool
buildThreads bool buildThreads bool
@ -77,7 +77,7 @@ func NewMessageStore(worker *types.Worker,
thread: thread, thread: thread,
defaultSortCriteria: defaultSortCriteria, sortCriteria: defaultSortCriteria,
pendingBodies: make(map[uint32]interface{}), pendingBodies: make(map[uint32]interface{}),
pendingHeaders: make(map[uint32]interface{}), pendingHeaders: make(map[uint32]interface{}),
@ -184,7 +184,7 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
switch msg := msg.(type) { switch msg := msg.(type) {
case *types.DirectoryInfo: case *types.DirectoryInfo:
store.DirInfo = *msg.Info store.DirInfo = *msg.Info
store.Sort(store.defaultSortCriteria, nil) store.Sort(store.sortCriteria, nil)
update = true update = true
case *types.DirectoryContents: case *types.DirectoryContents:
newMap := make(map[uint32]*models.MessageInfo) newMap := make(map[uint32]*models.MessageInfo)
@ -721,6 +721,7 @@ func (store *MessageStore) ModifyLabels(uids []uint32, add, remove []string,
func (store *MessageStore) Sort(criteria []*types.SortCriterion, cb func()) { func (store *MessageStore) Sort(criteria []*types.SortCriterion, cb func()) {
store.Sorting = true store.Sorting = true
store.sortCriteria = criteria
handle_return := func(msg types.WorkerMessage) { handle_return := func(msg types.WorkerMessage) {
store.Sorting = false store.Sorting = false

View file

@ -282,7 +282,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
store.Update(msg) store.Update(msg)
} else { } else {
store = lib.NewMessageStore(acct.worker, msg.Info, store = lib.NewMessageStore(acct.worker, msg.Info,
acct.getSortCriteria(), acct.GetSortCriteria(),
acct.UiConfig().ThreadingEnabled, acct.UiConfig().ThreadingEnabled,
func(msg *models.MessageInfo) { func(msg *models.MessageInfo) {
acct.conf.Triggers.ExecNewEmail(acct.acct, acct.conf.Triggers.ExecNewEmail(acct.acct,
@ -335,7 +335,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
acct.UpdateStatus() acct.UpdateStatus()
} }
func (acct *AccountView) getSortCriteria() []*types.SortCriterion { func (acct *AccountView) GetSortCriteria() []*types.SortCriterion {
if len(acct.UiConfig().Sort) == 0 { if len(acct.UiConfig().Sort) == 0 {
return nil return nil
} }