4753cfd3e3
In order to better align to vim functionality: deselect visual mode selections after performing a command on the selection. This patch also introduces a new command to allow for re-selecting (remarking) the previous selection set so that commands can be chained together. The deselection only applies to msg commands that *do not* move the message from the store (those types of commands already deselect): - read/unread - flag/unflag - modify-labels - copy - pipe Previous usage to mark several messages as read and deselect all: Vjjj:read<Enter>:unmark -a<Enter> New usage, similar to vim: Vjjj:read<Enter> To chain a command together: Vjjj:read<Enter>:remark<Enter>{next command}<Enter> Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
104 lines
1.7 KiB
Go
104 lines
1.7 KiB
Go
package msg
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.sr.ht/~rjarry/aerc/widgets"
|
|
"git.sr.ht/~sircmpwn/getopt"
|
|
)
|
|
|
|
type Mark struct{}
|
|
|
|
func init() {
|
|
register(Mark{})
|
|
}
|
|
|
|
func (Mark) Aliases() []string {
|
|
return []string{"mark", "unmark", "remark"}
|
|
}
|
|
|
|
func (Mark) Complete(aerc *widgets.Aerc, args []string) []string {
|
|
return nil
|
|
}
|
|
|
|
func (Mark) Execute(aerc *widgets.Aerc, args []string) error {
|
|
h := newHelper(aerc)
|
|
selected, err := h.msgProvider.SelectedMessage()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
store, err := h.store()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
opts, _, err := getopt.Getopts(args, "atv")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var all bool
|
|
var toggle bool
|
|
var visual bool
|
|
for _, opt := range opts {
|
|
switch opt.Option {
|
|
case 'a':
|
|
all = true
|
|
case 'v':
|
|
visual = true
|
|
case 't':
|
|
toggle = true
|
|
}
|
|
}
|
|
|
|
switch args[0] {
|
|
case "mark":
|
|
if all && visual {
|
|
return fmt.Errorf("-a and -v are mutually exclusive")
|
|
}
|
|
|
|
var modFunc func(uint32)
|
|
if toggle {
|
|
modFunc = store.ToggleMark
|
|
} else {
|
|
modFunc = store.Mark
|
|
}
|
|
if all {
|
|
uids := store.Uids()
|
|
for _, uid := range uids {
|
|
modFunc(uid)
|
|
}
|
|
return nil
|
|
} else if visual {
|
|
store.ToggleVisualMark()
|
|
return nil
|
|
} else {
|
|
modFunc(selected.Uid)
|
|
return nil
|
|
}
|
|
|
|
case "unmark":
|
|
if visual {
|
|
return fmt.Errorf("visual mode not supported for this command")
|
|
}
|
|
|
|
if all && toggle {
|
|
uids := store.Uids()
|
|
for _, uid := range uids {
|
|
store.ToggleMark(uid)
|
|
}
|
|
return nil
|
|
} else if all && !toggle {
|
|
store.ClearVisualMark()
|
|
return nil
|
|
} else {
|
|
store.Unmark(selected.Uid)
|
|
return nil
|
|
}
|
|
case "remark":
|
|
if all || visual || toggle {
|
|
return fmt.Errorf("Usage: :remark")
|
|
}
|
|
store.Remark()
|
|
return nil
|
|
}
|
|
return nil // never reached
|
|
}
|