diff options
author | Koni Marti <koni.marti@gmail.com> | 2024-06-14 23:13:59 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-06-23 22:14:21 +0200 |
commit | 910bc95af6e8cee59ab48cb5df2e7bea85b5c94a (patch) | |
tree | 60df37a558f3ecfe2d3427008904b2c828f07b3b /commands | |
parent | 2c06df8720ccf9619fbc293be3c33965672667a9 (diff) | |
download | aerc-910bc95af6e8cee59ab48cb5df2e7bea85b5c94a.tar.gz |
dirlist: store previous folder info
Store the previous folder in the dirlist and retire the global 'history'
map in the commands package. This ensures that the previous folder is
always available when using ':cf -'.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/account/cf.go | 20 | ||||
-rw-r--r-- | commands/account/mkdir.go | 2 | ||||
-rw-r--r-- | commands/account/rmdir.go | 3 |
3 files changed, 12 insertions, 13 deletions
diff --git a/commands/account/cf.go b/commands/account/cf.go index 199664fa..8d7d27ae 100644 --- a/commands/account/cf.go +++ b/commands/account/cf.go @@ -13,15 +13,12 @@ import ( "git.sr.ht/~rjarry/go-opt" ) -var history map[string]string - type ChangeFolder struct { Account bool `opt:"-a"` Folder string `opt:"..." complete:"CompleteFolderAndNotmuch"` } func init() { - history = make(map[string]string) commands.Register(ChangeFolder{}) } @@ -115,16 +112,22 @@ func (c ChangeFolder) Execute([]string) error { handleDirOpenResponse(acct, msg) } + dirlist := acct.Directories() + if dirlist == nil { + return errors.New("No directory list found") + } + if target == "-" { - if dir, ok := history[acct.Name()]; ok { - acct.Directories().Open(dir, "", 0*time.Second, finalize, false) + dir := dirlist.Previous() + if dir != "" { + target = dir } else { return errors.New("No previous folder to return to") } - } else { - acct.Directories().Open(target, "", 0*time.Second, finalize, false) } + dirlist.Open(target, "", 0*time.Second, finalize, false) + return nil } @@ -135,9 +138,6 @@ func handleDirOpenResponse(acct *app.AccountView, msg types.WorkerMessage) { case *types.Error: app.PushError(msg.Error.Error()) case *types.Done: - curAccount := app.SelectedAccount() - previous := curAccount.Directories().Selected() - history[curAccount.Name()] = previous // reset store filtering if we switched folders store := acct.Store() if store != nil { diff --git a/commands/account/mkdir.go b/commands/account/mkdir.go index 5ce7bbf4..13310665 100644 --- a/commands/account/mkdir.go +++ b/commands/account/mkdir.go @@ -45,14 +45,12 @@ func (m MakeDir) Execute(args []string) error { if acct == nil { return errors.New("No account selected") } - previous := acct.SelectedDirectory() acct.Worker().PostAction(&types.CreateDirectory{ Directory: m.Folder, }, func(msg types.WorkerMessage) { switch msg := msg.(type) { case *types.Done: app.PushStatus("Directory created.", 10*time.Second) - history[acct.Name()] = previous acct.Directories().Open(m.Folder, "", 0, nil, false) case *types.Error: app.PushError(msg.Error.Error()) diff --git a/commands/account/rmdir.go b/commands/account/rmdir.go index cd70aa62..ff1463b6 100644 --- a/commands/account/rmdir.go +++ b/commands/account/rmdir.go @@ -72,7 +72,8 @@ func (r RemoveDir) Execute(args []string) error { var newDir string dirFound := false - if oldDir, ok := history[acct.Name()]; ok { + oldDir := acct.Directories().Previous() + if oldDir != "" { present := false for _, dir := range acct.Directories().List() { if dir == oldDir { |