diff --git a/app/dirlist.go b/app/dirlist.go index 23842e3f..9969a996 100644 --- a/app/dirlist.go +++ b/app/dirlist.go @@ -36,8 +36,8 @@ type DirectoryLister interface { NextPrev(int) - CollapseFolder() - ExpandFolder() + CollapseFolder(string) + ExpandFolder(string) SelectedMsgStore() (*lib.MessageStore, bool) MsgStore(string) (*lib.MessageStore, bool) @@ -170,11 +170,11 @@ func (dirlist *DirectoryList) Update(msg types.WorkerMessage) { } } -func (dirlist *DirectoryList) CollapseFolder() { +func (dirlist *DirectoryList) CollapseFolder(string) { // no effect for the DirectoryList } -func (dirlist *DirectoryList) ExpandFolder() { +func (dirlist *DirectoryList) ExpandFolder(string) { // no effect for the DirectoryList } diff --git a/app/dirtree.go b/app/dirtree.go index 22f0c8a9..30ced9a6 100644 --- a/app/dirtree.go +++ b/app/dirtree.go @@ -304,30 +304,35 @@ func (dt *DirectoryTree) selectIndex(i int) { } } -func (dt *DirectoryTree) CollapseFolder() { - if dt.listIdx >= 0 && dt.listIdx < len(dt.list) { - if node := dt.list[dt.listIdx]; node != nil { - if node.Parent != nil && (node.Hidden != 0 || node.FirstChild == nil) { - node.Parent.Hidden = 1 - // highlight parent node and select it - for i, t := range dt.list { - if t == node.Parent { - dt.selectIndex(i) - } - } - } else { - node.Hidden = 1 +func (dt *DirectoryTree) CollapseFolder(name string) { + name = strings.TrimRight(name, dt.worker.PathSeparator()) + index, node := dt.getTreeNode(models.UID(name)) + if node == nil { + return + } + if node.Parent != nil && (node.Hidden != 0 || node.FirstChild == nil) { + node.Parent.Hidden = 1 + // highlight parent node and select it + for i, t := range dt.list { + if t == node.Parent && index == dt.listIdx { + dt.selectIndex(i) + break } - dt.Invalidate() } + } else { + node.Hidden = 1 } + dt.Invalidate() } -func (dt *DirectoryTree) ExpandFolder() { - if dt.listIdx >= 0 && dt.listIdx < len(dt.list) { - dt.list[dt.listIdx].Hidden = 0 - dt.Invalidate() +func (dt *DirectoryTree) ExpandFolder(name string) { + name = strings.TrimRight(name, dt.worker.PathSeparator()) + _, node := dt.getTreeNode(models.UID(name)) + if node == nil { + return } + node.Hidden = 0 + dt.Invalidate() } func (dt *DirectoryTree) countVisible(list []*types.Thread) (n int) { diff --git a/commands/account/expand-folder.go b/commands/account/expand-folder.go index 8b1a8c66..0422c55e 100644 --- a/commands/account/expand-folder.go +++ b/commands/account/expand-folder.go @@ -7,7 +7,9 @@ import ( "git.sr.ht/~rjarry/aerc/commands" ) -type ExpandCollapseFolder struct{} +type ExpandCollapseFolder struct { + Folder string `opt:"folder" required:"false" complete:"CompleteFolder" desc:"Folder name."` +} func init() { commands.Register(ExpandCollapseFolder{}) @@ -25,15 +27,26 @@ func (ExpandCollapseFolder) Aliases() []string { return []string{"expand-folder", "collapse-folder"} } -func (ExpandCollapseFolder) Execute(args []string) error { +func (*ExpandCollapseFolder) CompleteFolder(arg string) []string { + acct := app.SelectedAccount() + if acct == nil { + return nil + } + return commands.FilterList(acct.Directories().List(), arg, nil) +} + +func (e ExpandCollapseFolder) Execute(args []string) error { acct := app.SelectedAccount() if acct == nil { return errors.New("No account selected") } + if e.Folder == "" { + e.Folder = acct.Directories().Selected() + } if args[0] == "expand-folder" { - acct.Directories().ExpandFolder() + acct.Directories().ExpandFolder(e.Folder) } else { - acct.Directories().CollapseFolder() + acct.Directories().CollapseFolder(e.Folder) } return nil } diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd index 6de06175..1647a67e 100644 --- a/doc/aerc.1.scd +++ b/doc/aerc.1.scd @@ -646,10 +646,11 @@ message list, the message in the message viewer, etc). Cycles to the next (or previous) folder shown in the sidebar, repeated __ times (default: _1_). -*:expand-folder*++ -*:collapse-folder* - Expands or collapses the current folder when the directory tree is - enabled. +*:expand-folder* [__]++ +*:collapse-folder* [__] + Expands or collapses a folder when the directory tree is enabled. If no + __ argument is specified, the currently selected folder is acted + upon. *:export-mbox* __ Exports messages in the current folder to an mbox file. If there are marked