aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorinwit <inwit@sindominio.net>2023-10-29 23:45:56 +0100
committerRobin Jarry <robin@jarry.cc>2023-11-02 11:59:39 +0100
commit4bd93fccbf18a855016bd26a3ec8cd9ca7cf5600 (patch)
treeab1041819a2e50d454111ca7859cfa7ec0700361
parent9ce4af011c93e2816ce04012f6205b54e0ed1d51 (diff)
downloadaerc-4bd93fccbf18a855016bd26a3ec8cd9ca7cf5600.tar.gz
fold: add an option to toggle folding
Add a toggle option (-t) to :fold/:unfold commands to allow for switching the folding status of a thread. Changelog-Added: Toggle folding with `:fold -t`. Signed-Off-By: inwit <inwit@sindominio.net> Acked-by: Robin Jarry <robin@jarry.cc> Tested-by: Jason Cox <me@jasoncarloscox.com>
-rw-r--r--commands/msg/fold.go10
-rw-r--r--config/binds.conf1
-rw-r--r--doc/aerc.1.scd7
-rw-r--r--lib/msgstore.go35
-rw-r--r--worker/types/thread.go2
5 files changed, 37 insertions, 18 deletions
diff --git a/commands/msg/fold.go b/commands/msg/fold.go
index 06e933d7..f3f55871 100644
--- a/commands/msg/fold.go
+++ b/commands/msg/fold.go
@@ -7,7 +7,9 @@ import (
"git.sr.ht/~rjarry/aerc/lib/ui"
)
-type Fold struct{}
+type Fold struct {
+ Toggle bool `opt:"-t" aliases:"fold,unfold"`
+}
func init() {
register(Fold{})
@@ -17,7 +19,7 @@ func (Fold) Aliases() []string {
return []string{"fold", "unfold"}
}
-func (Fold) Execute(args []string) error {
+func (f Fold) Execute(args []string) error {
h := newHelper()
store, err := h.store()
if err != nil {
@@ -31,9 +33,9 @@ func (Fold) Execute(args []string) error {
switch strings.ToLower(args[0]) {
case "fold":
- err = store.Fold(msg.Uid)
+ err = store.Fold(msg.Uid, f.Toggle)
case "unfold":
- err = store.Unfold(msg.Uid)
+ err = store.Unfold(msg.Uid, f.Toggle)
}
ui.Invalidate()
return err
diff --git a/config/binds.conf b/config/binds.conf
index c0e28af9..a38795d5 100644
--- a/config/binds.conf
+++ b/config/binds.conf
@@ -44,6 +44,7 @@ V = :mark -v<Enter>
T = :toggle-threads<Enter>
zc = :fold<Enter>
zo = :unfold<Enter>
+<tab> = :fold -t<Enter>
<Enter> = :view<Enter>
d = :prompt 'Really delete this message?' 'delete-message'<Enter>
diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index 2d53dca3..c34b3e7f 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -529,10 +529,11 @@ message list, the message in the message viewer, etc).
*:toggle-threads*
Toggles between message threading and the normal message list.
-*:fold*++
-*:unfold*
+*:fold* [*-t*]++
+*:unfold* [*-t*]
Collapse or un-collapse the thread children of the selected message.
- Folded threads can be identified by _{{.Thread\*}}_ template attributes
+ If the toggle flag *-t* is set, the folded status is changed. Folded
+ threads can be identified by _{{.Thread\*}}_ template attributes
in *[ui].index-columns*. See *aerc-config*(5) and *aerc-templates*(7)
for more details.
diff --git a/lib/msgstore.go b/lib/msgstore.go
index ca5f16d9..e54c2565 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -509,29 +509,44 @@ func (store *MessageStore) SelectedThread() (*types.Thread, error) {
return store.Thread(store.SelectedUid())
}
-func (store *MessageStore) Fold(uid uint32) error {
- return store.doThreadFolding(uid, true)
+func (store *MessageStore) Fold(uid uint32, toggle bool) error {
+ return store.doThreadFolding(uid, true, toggle)
}
-func (store *MessageStore) Unfold(uid uint32) error {
- return store.doThreadFolding(uid, false)
+func (store *MessageStore) Unfold(uid uint32, toggle bool) error {
+ return store.doThreadFolding(uid, false, toggle)
}
-func (store *MessageStore) doThreadFolding(uid uint32, hide bool) error {
+func (store *MessageStore) doThreadFolding(uid uint32, hide bool, toggle bool) error {
thread, err := store.Thread(uid)
if err != nil {
return err
}
- if hide && thread.FirstChild.Hidden > 0 {
+ if len(thread.Uids()) == 1 {
+ return nil
+ }
+ folded := thread.FirstChild.Hidden > 0
+ if !toggle && hide && folded {
return nil
}
err = thread.Walk(func(t *types.Thread, _ int, __ error) error {
if t.Uid != uid {
- if hide {
- t.Hidden++ //increase fold level
- } else if t.Hidden > 1 {
+ switch {
+ case toggle:
+ if folded {
+ if t.Hidden > 1 {
+ t.Hidden--
+ } else {
+ t.Hidden = 0
+ }
+ } else {
+ t.Hidden++
+ }
+ case hide:
+ t.Hidden++
+ case t.Hidden > 1:
t.Hidden--
- } else {
+ default:
t.Hidden = 0
}
}
diff --git a/worker/types/thread.go b/worker/types/thread.go
index b4f5ac5f..fdd2a8e6 100644
--- a/worker/types/thread.go
+++ b/worker/types/thread.go
@@ -15,7 +15,7 @@ type Thread struct {
NextSibling *Thread
FirstChild *Thread
- Hidden int // if this flag is not zero the message isn't rendered in the UI
+ Hidden int // if this flag is not zero the message isn't rendered in the UI
Deleted bool // if this flag is set the message was deleted
// Context indicates the message doesn't match the mailbox / query but