diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-07-26 11:30:26 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-07-26 11:34:19 +0200 |
commit | 8f7695fde5cd84b7f6b8f3193270eda2fd62448c (patch) | |
tree | 27d2b58969b841f957fdbb8ad703f3d116eb5f9c /widgets | |
parent | 3b90b3b0ddfd8134daa1d417bdd7acd8c39781b7 (diff) | |
download | aerc-8f7695fde5cd84b7f6b8f3193270eda2fd62448c.tar.gz |
msgstore: implement a uid-based architecture
Change the message store architecture from an index-based to a uid-based
one. Key advantage of this design approach is that no reselect mechanism
is required anymore since it comes with the design for free.
Fixes: https://todo.sr.ht/~rjarry/aerc/43
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/msglist.go | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/widgets/msglist.go b/widgets/msglist.go index a190c184..4c7c1c22 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -69,7 +69,9 @@ func (ml *MessageList) Draw(ctx *ui.Context) { ml.UpdateScroller(ml.height, len(store.Uids())) if store := ml.Store(); store != nil && len(store.Uids()) > 0 { - ml.EnsureScroll(store.SelectedIndex()) + if idx := store.FindIndexByUid(store.SelectedUid()); idx >= 0 { + ml.EnsureScroll(len(store.Uids()) - idx - 1) + } } textWidth := ctx.Width() @@ -244,7 +246,7 @@ func (ml *MessageList) drawRow(textWidth int, ctx *ui.Context, uid uint32, row i var style tcell.Style // current row - if row == ml.store.SelectedIndex()-ml.Scroll() { + if msg.Uid == ml.store.SelectedUid() { style = uiConfig.GetComposedStyleSelected(config.STYLE_MSGLIST_DEFAULT, msg_styles) } else { style = uiConfig.GetComposedStyle(config.STYLE_MSGLIST_DEFAULT, msg_styles) @@ -342,7 +344,6 @@ func (ml *MessageList) storeUpdate(store *lib.MessageStore) { if ml.Store() != store { return } - store.Reselect() } func (ml *MessageList) SetStore(store *lib.MessageStore) { @@ -352,7 +353,8 @@ func (ml *MessageList) SetStore(store *lib.MessageStore) { ml.store = store if store != nil { ml.spinner.Stop() - ml.nmsgs = len(store.Uids()) + uids := store.Uids() + ml.nmsgs = len(uids) store.OnUpdate(ml.storeUpdate) store.OnFilterChange(func(store *lib.MessageStore) { if ml.Store() != store { @@ -384,8 +386,21 @@ func (ml *MessageList) Selected() *models.MessageInfo { } func (ml *MessageList) Select(index int) { + // Note that the msgstore.Select function expects a uid as argument + // whereas the msglist.Select expects the message number store := ml.Store() - store.Select(index) + uids := store.Uids() + if len(uids) == 0 { + return + } + uidIdx := len(uids) - index - 1 + if uidIdx >= len(store.Uids()) { + uidIdx = 0 + } else if uidIdx < 0 { + uidIdx = len(store.Uids()) - 1 + } + store.Select(store.Uids()[uidIdx]) + ml.Invalidate() } |