aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/dirlist.go8
-rw-r--r--commands/account/cf.go20
-rw-r--r--commands/account/mkdir.go2
-rw-r--r--commands/account/rmdir.go3
4 files changed, 20 insertions, 13 deletions
diff --git a/app/dirlist.go b/app/dirlist.go
index 7dff934c..6c89aff9 100644
--- a/app/dirlist.go
+++ b/app/dirlist.go
@@ -23,6 +23,8 @@ type DirectoryLister interface {
ui.Drawable
Selected() string
+ Previous() string
+
Select(string)
Open(string, string, time.Duration, func(types.WorkerMessage), bool)
@@ -56,6 +58,7 @@ type DirectoryList struct {
dirs []string
selecting string
selected string
+ previous string
spinner *Spinner
worker *types.Worker
ctx context.Context
@@ -112,6 +115,7 @@ func (dirlist *DirectoryList) Update(msg types.WorkerMessage) {
case *types.Done:
switch msg := msg.InResponseTo().(type) {
case *types.OpenDirectory:
+ dirlist.previous = dirlist.selected
dirlist.selected = msg.Directory
dirlist.filterDirsByFoldersConfig()
hasSelected := false
@@ -222,6 +226,10 @@ func (dirlist *DirectoryList) Selected() string {
return dirlist.selected
}
+func (dirlist *DirectoryList) Previous() string {
+ return dirlist.previous
+}
+
func (dirlist *DirectoryList) Invalidate() {
ui.Invalidate()
}
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 {