summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-10-19 14:28:50 -0500
committerRobin Jarry <robin@jarry.cc>2022-10-19 21:50:26 +0200
commitbd8a4feecc539a50bec005bd2b58af045d9a51bc (patch)
tree347fce8fe7eef986180121e4b9f9444b89e87d17
parentee964ad6b0bd8ee42e903e25b75d9985dc2ff40e (diff)
downloadaerc-bd8a4feecc539a50bec005bd2b58af045d9a51bc.tar.gz
aerc-bd8a4feecc539a50bec005bd2b58af045d9a51bc.zip
split: prevent opening split when no messages are selected
The [v]split command panics when it is run with no message selected, or when messages aren't loaded. Check for a valid selected message before creating a split, and report an error if one isn't selected. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--commands/account/split.go6
-rw-r--r--widgets/account.go22
2 files changed, 18 insertions, 10 deletions
diff --git a/commands/account/split.go b/commands/account/split.go
index 2b802256..284182dc 100644
--- a/commands/account/split.go
+++ b/commands/account/split.go
@@ -55,9 +55,7 @@ func (Split) Execute(aerc *widgets.Aerc, args []string) error {
n = 0
}
if args[0] == "split" {
- acct.Split(n)
- return nil
+ return acct.Split(n)
}
- acct.Vsplit(n)
- return nil
+ return acct.Vsplit(n)
}
diff --git a/widgets/account.go b/widgets/account.go
index b6000f7c..c82646a9 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -545,10 +545,14 @@ func (acct *AccountView) SplitDirection() string {
// Split splits the message list view horizontally. The message list will be n
// rows high. If n is 0, any existing split is removed
-func (acct *AccountView) Split(n int) {
+func (acct *AccountView) Split(n int) error {
if n == 0 {
acct.clearSplit()
- return
+ return nil
+ }
+ msg, err := acct.SelectedMessage()
+ if err != nil {
+ return fmt.Errorf("could not create split: %w", err)
}
acct.splitSize = n
acct.splitDir = "split"
@@ -570,7 +574,7 @@ func (acct *AccountView) Split(n int) {
acct.grid.AddChild(ui.NewBordered(acct.dirlist, ui.BORDER_RIGHT, acct.uiConf)).Span(2, 1)
}
acct.grid.AddChild(ui.NewBordered(acct.msglist, ui.BORDER_BOTTOM, acct.uiConf)).At(0, 1)
- lib.NewMessageStoreView(acct.msglist.Selected(), false, acct.Store(), acct.aerc.Crypto, acct.aerc.DecryptKeys,
+ lib.NewMessageStoreView(msg, false, acct.Store(), acct.aerc.Crypto, acct.aerc.DecryptKeys,
func(view lib.MessageView, err error) {
if err != nil {
acct.aerc.PushError(err.Error())
@@ -580,14 +584,19 @@ func (acct *AccountView) Split(n int) {
acct.grid.AddChild(acct.split).At(1, 1)
})
ui.Invalidate()
+ return nil
}
// Vsplit splits the message list view vertically. The message list will be n
// rows wide. If n is 0, any existing split is removed
-func (acct *AccountView) Vsplit(n int) {
+func (acct *AccountView) Vsplit(n int) error {
if n == 0 {
acct.clearSplit()
- return
+ return nil
+ }
+ msg, err := acct.SelectedMessage()
+ if err != nil {
+ return fmt.Errorf("could not create split: %w", err)
}
acct.splitSize = n
acct.splitDir = "vsplit"
@@ -608,7 +617,7 @@ func (acct *AccountView) Vsplit(n int) {
acct.grid.AddChild(ui.NewBordered(acct.dirlist, ui.BORDER_RIGHT, acct.uiConf)).At(0, 0)
}
acct.grid.AddChild(ui.NewBordered(acct.msglist, ui.BORDER_RIGHT, acct.uiConf)).At(0, 1)
- lib.NewMessageStoreView(acct.msglist.Selected(), false, acct.Store(), acct.aerc.Crypto, acct.aerc.DecryptKeys,
+ lib.NewMessageStoreView(msg, false, acct.Store(), acct.aerc.Crypto, acct.aerc.DecryptKeys,
func(view lib.MessageView, err error) {
if err != nil {
acct.aerc.PushError(err.Error())
@@ -618,4 +627,5 @@ func (acct *AccountView) Vsplit(n int) {
acct.grid.AddChild(acct.split).At(0, 2)
})
ui.Invalidate()
+ return nil
}