visual-mode: deselect messages after performing command

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>
This commit is contained in:
Tim Culverhouse 2022-06-10 17:24:12 -05:00 committed by Robin Jarry
parent af0e587976
commit 4753cfd3e3
7 changed files with 21 additions and 2 deletions

View File

@ -59,6 +59,7 @@ func (Copy) Execute(aerc *widgets.Aerc, args []string) error {
switch msg := msg.(type) { switch msg := msg.(type) {
case *types.Done: case *types.Done:
aerc.PushStatus("Messages copied.", 10*time.Second) aerc.PushStatus("Messages copied.", 10*time.Second)
store.ClearVisualMark()
case *types.Error: case *types.Error:
aerc.PushError(msg.Error.Error()) aerc.PushError(msg.Error.Error())
} }

View File

@ -14,7 +14,7 @@ func init() {
} }
func (Mark) Aliases() []string { func (Mark) Aliases() []string {
return []string{"mark", "unmark"} return []string{"mark", "unmark", "remark"}
} }
func (Mark) Complete(aerc *widgets.Aerc, args []string) []string { func (Mark) Complete(aerc *widgets.Aerc, args []string) []string {
@ -93,6 +93,12 @@ func (Mark) Execute(aerc *widgets.Aerc, args []string) error {
store.Unmark(selected.Uid) store.Unmark(selected.Uid)
return nil return nil
} }
case "remark":
if all || visual || toggle {
return fmt.Errorf("Usage: :remark")
}
store.Remark()
return nil
} }
return nil // never reached return nil // never reached
} }

View File

@ -57,6 +57,7 @@ func (ModifyLabels) Execute(aerc *widgets.Aerc, args []string) error {
switch msg := msg.(type) { switch msg := msg.(type) {
case *types.Done: case *types.Done:
aerc.PushStatus("labels updated", 10*time.Second) aerc.PushStatus("labels updated", 10*time.Second)
store.ClearVisualMark()
case *types.Error: case *types.Error:
aerc.PushError(msg.Error.Error()) aerc.PushError(msg.Error.Error())
} }

View File

@ -197,7 +197,7 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
} }
}) })
} }
provider.Store().ClearVisualMark()
return nil return nil
} }

View File

@ -175,6 +175,7 @@ func (FlagMsg) Execute(aerc *widgets.Aerc, args []string) error {
wg.Wait() wg.Wait()
if success { if success {
aerc.PushStatus(actionName+" flag '"+flagName+"' successful", 10*time.Second) aerc.PushStatus(actionName+" flag '"+flagName+"' successful", 10*time.Second)
store.ClearVisualMark()
} }
}() }()

View File

@ -384,6 +384,10 @@ message list, the message in the message viewer, etc).
*-t*: toggle the mark state instead of unmarking a message *-t*: toggle the mark state instead of unmarking a message
*remark*
Re-select the last set of marked messages. Can be used to chain commands
after a selection has been acted upon
## MESSAGE COMPOSE COMMANDS ## MESSAGE COMPOSE COMMANDS
*abort* *abort*

View File

@ -26,6 +26,7 @@ type MessageStore struct {
//marking //marking
marked map[uint32]struct{} marked map[uint32]struct{}
lastMarked map[uint32]struct{}
visualStartUid uint32 visualStartUid uint32
visualMarkMode bool visualMarkMode bool
@ -558,6 +559,10 @@ func (store *MessageStore) Unmark(uid uint32) {
delete(store.marked, uid) delete(store.marked, uid)
} }
func (store *MessageStore) Remark() {
store.marked = store.lastMarked
}
// ToggleMark toggles the marked state on a MessageInfo // ToggleMark toggles the marked state on a MessageInfo
func (store *MessageStore) ToggleMark(uid uint32) { func (store *MessageStore) ToggleMark(uid uint32) {
if store.visualMarkMode { if store.visualMarkMode {
@ -573,6 +578,7 @@ func (store *MessageStore) ToggleMark(uid uint32) {
// resetMark removes the marking from all messages // resetMark removes the marking from all messages
func (store *MessageStore) resetMark() { func (store *MessageStore) resetMark() {
store.lastMarked = store.marked
store.marked = make(map[uint32]struct{}) store.marked = make(map[uint32]struct{})
} }