diff options
-rw-r--r-- | app/dirlist.go | 15 | ||||
-rw-r--r-- | app/dirtree.go | 12 |
2 files changed, 16 insertions, 11 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() diff --git a/app/dirtree.go b/app/dirtree.go index 6a3b34c0..8f8730b4 100644 --- a/app/dirtree.go +++ b/app/dirtree.go @@ -256,12 +256,17 @@ func (dt *DirectoryTree) NextPrev(delta int) { } } - dt.listIdx = newIdx + dt.selectIndex(newIdx) +} + +func (dt *DirectoryTree) selectIndex(i int) { + dt.listIdx = i if path := dt.getDirectory(dt.list[dt.listIdx]); path != "" { dt.virtual = false dt.Select(path) } else { dt.virtual = true + dt.NewContext() dt.virtualCb() } } @@ -274,10 +279,7 @@ func (dt *DirectoryTree) CollapseFolder() { // highlight parent node and select it for i, t := range dt.list { if t == node.Parent { - dt.listIdx = i - if path := dt.getDirectory(dt.list[dt.listIdx]); path != "" { - dt.Select(path) - } + dt.selectIndex(i) } } } else { |