mirror of
https://git.sr.ht/~rjarry/aerc
synced 2026-03-02 18:23:33 +01:00
compose: only show default annotations if absent from config
Currently, it is impossible to "hide" bindings presented on the review
screen even if removing the annotations from binds.conf.
If the configuration contains any annotated bindings, completely ignore
all of the default annotations.
Only display bindings from the config that are both present and
annotated.
Fixes: 64502d9e8b ("compose: show annotations on the review screen")
Changelog-changed: Key bindings available on the compose review screen
are now only displayed if they are annotated with a comment. If
no binding is annotated in `[compose::review]`, then the default
annotations will be used as a fallback to avoid displaying a blank
screen.
Reported-by: Skejg <grolleman@zoho.com>
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Inwit <inwit@sindominio.net>
This commit is contained in:
@@ -1674,6 +1674,17 @@ type reviewMessage struct {
|
||||
grid *ui.Grid
|
||||
}
|
||||
|
||||
var fallbackAnnotations = map[string]string{
|
||||
":send<enter>": "Send",
|
||||
":edit<enter>": "Edit (body and headers)",
|
||||
":attach<space>": "Add attachment",
|
||||
":detach<space>": "Remove attachment",
|
||||
":postpone<enter>": "Postpone",
|
||||
":preview<enter>": "Preview message",
|
||||
":abort<enter>": "Abort (discard message, no confirmation)",
|
||||
":choose -o d discard abort -o p postpone postpone<enter>": "Abort or postpone",
|
||||
}
|
||||
|
||||
func newReviewMessage(composer *Composer, err error) *reviewMessage {
|
||||
bindings := config.Binds.ComposeReview.ForAccount(
|
||||
composer.acctConfig.Name,
|
||||
@@ -1681,50 +1692,39 @@ func newReviewMessage(composer *Composer, err error) *reviewMessage {
|
||||
bindings = bindings.ForFolder(composer.SelectedDirectory())
|
||||
|
||||
const maxInputWidth = 6
|
||||
type reviewCmd struct {
|
||||
output string
|
||||
annotation string
|
||||
input string
|
||||
|
||||
annotated := false
|
||||
for _, binding := range bindings.Bindings {
|
||||
if binding.Annotation != "" {
|
||||
annotated = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
reviewCmds := []reviewCmd{
|
||||
{":send<enter>", "Send", ""},
|
||||
{":edit<enter>", "Edit (body and headers)", ""},
|
||||
{":attach<space>", "Add attachment", ""},
|
||||
{":detach<space>", "Remove attachment", ""},
|
||||
{":postpone<enter>", "Postpone", ""},
|
||||
{":preview<enter>", "Preview message", ""},
|
||||
{":abort<enter>", "Abort (discard message, no confirmation)", ""},
|
||||
{":choose -o d discard abort -o p postpone postpone<enter>", "Abort or postpone", ""},
|
||||
type reviewCmd struct {
|
||||
input string
|
||||
output string
|
||||
annotation string
|
||||
}
|
||||
var actions []string
|
||||
|
||||
var reviewCmds []reviewCmd
|
||||
|
||||
for _, binding := range bindings.Bindings {
|
||||
inputs := config.FormatKeyStrokes(binding.Input)
|
||||
outputs := config.FormatKeyStrokes(binding.Output)
|
||||
found := false
|
||||
for i, rcmd := range reviewCmds {
|
||||
if outputs == rcmd.output {
|
||||
found = true
|
||||
if reviewCmds[i].input == "" {
|
||||
reviewCmds[i].input = inputs
|
||||
} else {
|
||||
reviewCmds[i].input += ", " + inputs
|
||||
}
|
||||
if binding.Annotation != "" {
|
||||
// overwrite default description with
|
||||
// user annotations if present
|
||||
reviewCmds[i].annotation = binding.Annotation
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
rcmd := reviewCmd{
|
||||
|
||||
if annotated && binding.Annotation != "" {
|
||||
reviewCmds = append(reviewCmds, reviewCmd{
|
||||
input: inputs,
|
||||
output: outputs,
|
||||
annotation: binding.Annotation,
|
||||
})
|
||||
} else if annotation, ok := fallbackAnnotations[outputs]; ok {
|
||||
reviewCmds = append(reviewCmds, reviewCmd{
|
||||
input: inputs,
|
||||
}
|
||||
reviewCmds = append(reviewCmds, rcmd)
|
||||
output: outputs,
|
||||
annotation: annotation,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1741,6 +1741,7 @@ func newReviewMessage(composer *Composer, err error) *reviewMessage {
|
||||
}
|
||||
widthstr := strconv.Itoa(width)
|
||||
|
||||
var actions []string
|
||||
for _, rcmd := range reviewCmds {
|
||||
if rcmd.input != "" {
|
||||
actions = append(actions, fmt.Sprintf(" %-"+widthstr+"s %-40s %s",
|
||||
|
||||
@@ -60,7 +60,8 @@ The available contexts are:
|
||||
|
||||
p = :postpone<Enter> # I'll work on it later
|
||||
|
||||
The order in which the bindings are defined is preserved.
|
||||
Only bindings that are annotated with a comment will be displayed on the
|
||||
review screen. The order in which they are defined is preserved.
|
||||
|
||||
*[terminal]*
|
||||
keybindings for terminal tabs
|
||||
|
||||
Reference in New Issue
Block a user