summaryrefslogtreecommitdiff
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
parent683df439f8df5f53ee00e96eb6b9d525b1c41ea9 (diff)
downloadaerc-d79458f464abccdb43e7d14753577698667ec81c.tar.gz
aerc-d79458f464abccdb43e7d14753577698667ec81c.zip
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>
-rw-r--r--commands/account/split.go3
-rw-r--r--lib/msgstore.go3
-rw-r--r--widgets/account.go69
-rw-r--r--widgets/msglist.go1
4 files changed, 44 insertions, 32 deletions
diff --git a/commands/account/split.go b/commands/account/split.go
index 72292c43..080d0b1b 100644
--- a/commands/account/split.go
+++ b/commands/account/split.go
@@ -30,9 +30,6 @@ func (Split) Execute(aerc *widgets.Aerc, args []string) error {
if acct == nil {
return errors.New("No account selected")
}
- if acct.Messages().Empty() {
- return nil
- }
n := 0
var err error
if len(args) > 1 {
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 45513145..6710fa56 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -315,6 +315,9 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
}
}
store.uids = uids
+ if len(uids) == 0 {
+ store.Select(MagicUid)
+ }
var newResults []uint32
for _, res := range store.results {
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 {
diff --git a/widgets/msglist.go b/widgets/msglist.go
index a12a4687..fc5b46b5 100644
--- a/widgets/msglist.go
+++ b/widgets/msglist.go
@@ -391,6 +391,7 @@ func (ml *MessageList) Select(index int) {
store := ml.Store()
uids := store.Uids()
if len(uids) == 0 {
+ store.Select(lib.MagicUid)
return
}