aboutsummaryrefslogtreecommitdiffstats
path: root/app/dirlist.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-11-18 02:07:06 +0100
committerRobin Jarry <robin@jarry.cc>2023-11-23 00:14:54 +0100
commit85d0936df6861c41a1dddd91a2f3b97afd8e127a (patch)
tree72def6d94ba56f508bdc6cbf051865c000d968dc /app/dirlist.go
parent48b9589d8bbe4ec8982c08a9fe6e59b77734eb80 (diff)
downloadaerc-85d0936df6861c41a1dddd91a2f3b97afd8e127a.tar.gz
dirlist/dirtree: context handling
Add a NewContext() function that extracts and handles the canceling and re-creation of a new context for the directory list. This enables a better control of the context cancellation especially for a directory tree when a virtual node is selected. Before, the previous folder would have been opened if a virtual node was selected. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'app/dirlist.go')
-rw-r--r--app/dirlist.go15
1 files changed, 9 insertions, 6 deletions
diff --git a/app/dirlist.go b/app/dirlist.go
index 708eb824..d260d7c1 100644
--- a/app/dirlist.go
+++ b/app/dirlist.go
@@ -67,15 +67,12 @@ type DirectoryList struct {
func NewDirectoryList(acctConf *config.AccountConfig,
worker *types.Worker,
) DirectoryLister {
- ctx, cancel := context.WithCancel(context.Background())
-
dirlist := &DirectoryList{
acctConf: acctConf,
store: lib.NewDirStore(),
worker: worker,
- ctx: ctx,
- cancel: cancel,
}
+ dirlist.NewContext()
uiConf := dirlist.UiConfig("")
dirlist.spinner = NewSpinner(uiConf)
dirlist.spinner.Start()
@@ -87,6 +84,13 @@ func NewDirectoryList(acctConf *config.AccountConfig,
return dirlist
}
+func (dirlist *DirectoryList) NewContext() {
+ if dirlist.cancel != nil {
+ dirlist.cancel()
+ }
+ dirlist.ctx, dirlist.cancel = context.WithCancel(context.Background())
+}
+
func (dirlist *DirectoryList) UiConfig(dir string) *config.UIConfig {
if dir == "" {
dir = dirlist.Selected()
@@ -181,8 +185,7 @@ func (dirlist *DirectoryList) Open(name string, delay time.Duration,
) {
dirlist.selecting = name
- dirlist.cancel()
- dirlist.ctx, dirlist.cancel = context.WithCancel(context.Background())
+ dirlist.NewContext()
go func(ctx context.Context) {
defer log.PanicHandler()