aboutsummaryrefslogtreecommitdiffstats
path: root/commands/account
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-04-16 00:22:20 +0200
committerRobin Jarry <robin@jarry.cc>2022-04-17 12:18:33 +0200
commitcb887a2d9d7d7cd5eb57d8849df40cecc3b90090 (patch)
treeb7b23c34a772048484ed6e645226ff64fe103d64 /commands/account
parenta34be9eb36d26afdd723146673694db70662429c (diff)
downloadaerc-cb887a2d9d7d7cd5eb57d8849df40cecc3b90090.tar.gz
store: keep current message selected
Keep current message selected when clearing or changing filters and when toggling threads. Add -s flag to the clear command to also clear the selected message and set cursor to the top of the message list. Implements: https://todo.sr.ht/~rjarry/aerc/36 Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/account')
-rw-r--r--commands/account/clear.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/commands/account/clear.go b/commands/account/clear.go
index 64e70122..69fac2dc 100644
--- a/commands/account/clear.go
+++ b/commands/account/clear.go
@@ -5,6 +5,7 @@ import (
"git.sr.ht/~rjarry/aerc/lib/statusline"
"git.sr.ht/~rjarry/aerc/widgets"
+ "git.sr.ht/~sircmpwn/getopt"
)
type Clear struct{}
@@ -30,6 +31,30 @@ func (Clear) Execute(aerc *widgets.Aerc, args []string) error {
if store == nil {
return errors.New("Cannot perform action. Messages still loading")
}
+
+ clearSelected := false
+ opts, optind, err := getopt.Getopts(args, "s")
+ if err != nil {
+ return err
+ }
+
+ for _, opt := range opts {
+ switch opt.Option {
+ case 's':
+ clearSelected = true
+ }
+ }
+
+ if len(args) != optind {
+ return errors.New("Usage: clear [-s]")
+ }
+
+ if clearSelected {
+ defer store.Select(0)
+ } else {
+ defer store.Reselect(store.Selected())
+ }
+
store.ApplyClear()
acct.SetStatus(statusline.SearchFilterClear())