1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
diff --git a/commands/msg/fold.go b/commands/msg/fold.go
index 06e933d7bde26d76236f5be1c746807f22b14cf9..f3f55871f73247e49014aeb5394a46d8bca19f1b 100644
--- a/commands/msg/fold.go
+++ b/commands/msg/fold.go
@@ -7,7 +7,9 @@
"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 @@ }
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 c0e28af94925b543922db6d7237f5ac91bea4c01..a38795d516c73ac003459cf402637b695c58339d 100644
--- a/config/binds.conf
+++ b/config/binds.conf
@@ -44,6 +44,7 @@
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 2d53dca33ad8d043b5c26217b38f8fbb8845427f..c34b3e7ff241539df44f393d77ded37bf3c6e9d8 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -529,10 +529,11 @@
*: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 ca5f16d9c8dbd1063d3ca201f862c2624e09869b..e54c256572eee2c5b661ba6057c87bbab9043dc9 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 b4f5ac5fcfa54fe5db33df93dc98cc198013271e..fdd2a8e604eaea01e1865affaa6bac8b88a4e717 100644
--- a/worker/types/thread.go
+++ b/worker/types/thread.go
@@ -15,7 +15,7 @@ PrevSibling *Thread
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
|