aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/account.go
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-12-11 15:11:25 -0600
committerRobin Jarry <robin@jarry.cc>2022-12-14 11:24:49 +0100
commitd79458f464abccdb43e7d14753577698667ec81c (patch)
treed3dd2ba22c4c441135db86e1ef465c04bca8d323 /widgets/account.go
parent683df439f8df5f53ee00e96eb6b9d525b1c41ea9 (diff)
downloadaerc-d79458f464abccdb43e7d14753577698667ec81c.tar.gz
split: refactor split update logic
Refactor split update logic to more simply update the split. Through the evolution of the split logic, additional variables were stored within the account which allows for cleaner updating of the split. Compare selected UID instead of pointer to message when deciding not to update split. Allow splits to be created and closed when no message is selected. The split will be filled with a ui.Fill (blank). The user will only see a border at the split location when no message is selected. Rename clearSplit to closeSplit, as it is only used in the case when the user doesn't want a split anymore. Ensure that the selected UID is reset to the magic UID when there are no messages left in the message store. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Diffstat (limited to 'widgets/account.go')
-rw-r--r--widgets/account.go69
1 files changed, 40 insertions, 29 deletions
diff --git a/widgets/account.go b/widgets/account.go
index 6bcb5b83..6f1b7cc3 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -39,7 +39,7 @@ type AccountView struct {
split *MessageViewer
splitSize int
splitDebounce *time.Timer
- splitMsg *models.MessageInfo
+ splitUid uint32
splitDir string
// Check-mail ticker
@@ -479,7 +479,7 @@ func (acct *AccountView) CheckMailTimer(d time.Duration) {
}()
}
-func (acct *AccountView) clearSplit() {
+func (acct *AccountView) closeSplit() {
if acct.split != nil {
acct.split.Close()
}
@@ -506,31 +506,25 @@ func (acct *AccountView) UpdateSplitView() {
if acct.Store() == nil {
return
}
- if acct.splitMsg == acct.msglist.Selected() {
+ if acct.Store().SelectedUid() == acct.splitUid {
return
}
if acct.splitDebounce != nil {
acct.splitDebounce.Stop()
}
fn := func() {
- msg, err := acct.SelectedMessage()
- if err != nil {
+ var err error
+ switch acct.SplitDirection() {
+ case "split":
+ err = acct.Split(acct.SplitSize())
+ case "vsplit":
+ err = acct.Vsplit(acct.SplitSize())
+ default:
return
}
- 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())
- return
- }
- orig := acct.split
- acct.split = NewMessageViewer(acct, view)
- acct.grid.ReplaceChild(orig, acct.split)
- if orig != nil {
- orig.Close()
- }
- })
- acct.splitMsg = msg
+ if err != nil {
+ log.Errorf("could not update split: %v", err)
+ }
ui.Invalidate()
}
acct.splitDebounce = time.AfterFunc(100*time.Millisecond, func() {
@@ -550,13 +544,9 @@ func (acct *AccountView) SplitDirection() string {
// rows high. If n is 0, any existing split is removed
func (acct *AccountView) Split(n int) error {
if n == 0 {
- acct.clearSplit()
+ acct.closeSplit()
return nil
}
- msg, err := acct.SelectedMessage()
- if err != nil {
- return fmt.Errorf("could not create split: %w", err)
- }
acct.splitSize = n
acct.splitDir = "split"
if acct.split != nil {
@@ -577,6 +567,18 @@ func (acct *AccountView) Split(n int) error {
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)
+
+ if acct.msglist.Empty() {
+ acct.grid.AddChild(ui.NewFill(' ', tcell.StyleDefault)).At(1, 1)
+ ui.Invalidate()
+ return nil
+ }
+
+ msg, err := acct.SelectedMessage()
+ if err != nil {
+ return fmt.Errorf("could not create split: %w", err)
+ }
+ acct.splitUid = msg.Uid
lib.NewMessageStoreView(msg, false, acct.Store(), acct.aerc.Crypto, acct.aerc.DecryptKeys,
func(view lib.MessageView, err error) {
if err != nil {
@@ -594,13 +596,9 @@ func (acct *AccountView) Split(n int) error {
// rows wide. If n is 0, any existing split is removed
func (acct *AccountView) Vsplit(n int) error {
if n == 0 {
- acct.clearSplit()
+ acct.closeSplit()
return nil
}
- msg, err := acct.SelectedMessage()
- if err != nil {
- return fmt.Errorf("could not create split: %w", err)
- }
acct.splitSize = n
acct.splitDir = "vsplit"
if acct.split != nil {
@@ -620,6 +618,19 @@ func (acct *AccountView) Vsplit(n int) error {
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)
+
+ if acct.msglist.Empty() {
+ acct.grid.AddChild(ui.NewFill(' ', tcell.StyleDefault)).At(0, 2)
+ ui.Invalidate()
+ return nil
+ }
+
+ msg, err := acct.SelectedMessage()
+ if err != nil {
+ return fmt.Errorf("could not create split: %w", err)
+ }
+ acct.splitUid = msg.Uid
+
lib.NewMessageStoreView(msg, false, acct.Store(), acct.aerc.Crypto, acct.aerc.DecryptKeys,
func(view lib.MessageView, err error) {
if err != nil {