aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-11-27 17:49:02 +0100
committerRobin Jarry <robin@jarry.cc>2023-12-01 17:17:22 +0100
commitfeafc433f08761290831e44fccf023badb5588aa (patch)
tree2cfb16dd64f4ee4d3b5f3d2cc6cadc2094d74cf3
parent0be135a38186725e6414cb7c6945f93ae6e71ef9 (diff)
downloadaerc-feafc433f08761290831e44fccf023badb5588aa.tar.gz
dirtree: prevent folder selection when archiving
Prevent an unwanted folder selection in the directory tree when archiving. A previous fix (commit 0be135a3) introduced a regression which caused the directory tree to select the folder for which a CreateDirectory message returned successfully. Since the :archive command will issue a CreateDirectory message in every operation, the directory tree will thus erroneously select the target archive directory. However, the functionality to select a newly created folder by the :mkdir command is actually correct and should be kept since this corresponds to the regular directory list behavior. Another quirk that is addressed is caused by the rebuilding of the directory tree when the underyling directories change. In that case, the ui.DirListCollapse setting would overwrite the user changes. Therefore, only apply the ui.DirListCollapse setting at the first time of building the directory tree. Fixes: 0be135a38186 ("dirtree: fix jumping folders") Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
-rw-r--r--app/dirtree.go39
1 files changed, 26 insertions, 13 deletions
diff --git a/app/dirtree.go b/app/dirtree.go
index 1cfd1513..559a717e 100644
--- a/app/dirtree.go
+++ b/app/dirtree.go
@@ -72,18 +72,16 @@ func (dt *DirectoryTree) ClearList() {
}
func (dt *DirectoryTree) Update(msg types.WorkerMessage) {
+ selected := dt.Selected()
switch msg := msg.(type) {
-
case *types.Done:
- switch resp := msg.InResponseTo().(type) {
- case *types.RemoveDirectory, *types.ListDirectories:
- dt.DirectoryList.Update(msg)
- dt.buildTree()
- dt.Invalidate()
- case *types.CreateDirectory:
+ switch msg.InResponseTo().(type) {
+ case *types.RemoveDirectory, *types.ListDirectories, *types.CreateDirectory:
dt.DirectoryList.Update(msg)
dt.buildTree()
- dt.reindex(resp.Directory)
+ if selected != "" {
+ dt.reindex(selected)
+ }
dt.Invalidate()
default:
dt.DirectoryList.Update(msg)
@@ -241,16 +239,31 @@ func (dt *DirectoryTree) Select(name string) {
if name == "" {
return
}
- dt.reindex(name)
- dt.DirectoryList.Select(name)
+ dt.Open(name, dt.UiConfig(name).DirListDelay, nil)
}
func (dt *DirectoryTree) Open(name string, delay time.Duration, cb func(types.WorkerMessage)) {
if name == "" {
return
}
- dt.reindex(name)
- dt.DirectoryList.Open(name, delay, cb)
+ again := false
+ if findString(dt.dirs, name) < 0 {
+ again = true
+ } else {
+ dt.reindex(name)
+ }
+ dt.DirectoryList.Open(name, delay, func(msg types.WorkerMessage) {
+ if cb != nil {
+ cb(msg)
+ }
+ if _, ok := msg.(*types.Done); ok && again {
+ if findString(dt.dirs, name) < 0 {
+ dt.dirs = append(dt.dirs, name)
+ }
+ dt.buildTree()
+ dt.reindex(name)
+ }
+ })
}
func (dt *DirectoryTree) NextPrev(delta int) {
@@ -483,7 +496,7 @@ func (dt *DirectoryTree) buildTreeNode(node *types.Thread, stree [][]string, def
}
nextNode := &types.Thread{Uid: uid}
node.AddChild(nextNode)
- if dt.UiConfig(path).DirListCollapse != 0 {
+ if dt.UiConfig(path).DirListCollapse != 0 && dt.listIdx < 0 {
if depth > dt.UiConfig(path).DirListCollapse {
node.Hidden = 1
} else {