summaryrefslogtreecommitdiff
path: root/widgets/compose.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-02-25 00:21:06 +0100
committerRobin Jarry <robin@jarry.cc>2022-02-25 13:56:53 +0100
commitc26d08103b327bd3f2470e542aa55ab354483347 (patch)
tree4c0567246916d676b71a4675c76a93a198add65f /widgets/compose.go
parent91ead11c47252ca8998fdad7b0770d6b8d07c987 (diff)
downloadaerc-c26d08103b327bd3f2470e542aa55ab354483347.zip
aerc: always check SelectedAccount return value
aerc.SelectedAccount() is used in lots of places. Most of them without checking the return value. In some cases, the currently selected tab is not related to any account (widget.Terminal for example). This can lead to unexpected crashes when accessing account specific configuration. When possible, return an error when no account is currently selected. If no error can be returned, fallback to non-account specific configuration. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com>
Diffstat (limited to 'widgets/compose.go')
-rw-r--r--widgets/compose.go19
1 files changed, 9 insertions, 10 deletions
diff --git a/widgets/compose.go b/widgets/compose.go
index 7229ec8..e47aa3e 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -127,15 +127,15 @@ func (c *Composer) buildComposeHeader(aerc *Aerc, cmpl *completer.Completer) {
c.layout = aerc.conf.Compose.HeaderLayout
c.editors = make(map[string]*headerEditor)
c.focusable = make([]ui.MouseableDrawableInteractive, 0)
+ uiConfig := aerc.SelectedAccountUiConfig()
for i, row := range c.layout {
for j, h := range row {
h = strings.ToLower(h)
c.layout[i][j] = h // normalize to lowercase
- e := newHeaderEditor(h, c.header, aerc.SelectedAccount().UiConfig())
+ e := newHeaderEditor(h, c.header, uiConfig)
if aerc.conf.Ui.CompletionPopovers {
- e.input.TabComplete(cmpl.ForHeader(h),
- aerc.SelectedAccount().UiConfig().CompletionDelay)
+ e.input.TabComplete(cmpl.ForHeader(h), uiConfig.CompletionDelay)
}
c.editors[h] = e
switch h {
@@ -152,9 +152,9 @@ func (c *Composer) buildComposeHeader(aerc *Aerc, cmpl *completer.Completer) {
for _, h := range []string{"cc", "bcc"} {
if c.header.Has(h) {
if _, ok := c.editors[h]; !ok {
- e := newHeaderEditor(h, c.header, aerc.SelectedAccount().UiConfig())
+ e := newHeaderEditor(h, c.header, uiConfig)
if aerc.conf.Ui.CompletionPopovers {
- e.input.TabComplete(cmpl.ForHeader(h), aerc.SelectedAccount().UiConfig().CompletionDelay)
+ e.input.TabComplete(cmpl.ForHeader(h), uiConfig.CompletionDelay)
}
c.editors[h] = e
c.focusable = append(c.focusable, e)
@@ -741,11 +741,10 @@ func (c *Composer) AddEditor(header string, value string, appendHeader bool) {
e.storeValue() // flush modifications from the user to the header
editor = e
} else {
- e := newHeaderEditor(header, c.header,
- c.aerc.SelectedAccount().UiConfig())
- if c.config.Ui.CompletionPopovers {
- e.input.TabComplete(c.completer.ForHeader(header),
- c.config.Ui.CompletionDelay)
+ uiConfig := c.aerc.SelectedAccountUiConfig()
+ e := newHeaderEditor(header, c.header, uiConfig)
+ if uiConfig.CompletionPopovers {
+ e.input.TabComplete(c.completer.ForHeader(header), uiConfig.CompletionDelay)
}
c.editors[header] = e
c.layout = append(c.layout, []string{header})