diff options
author | Kevin Kuehler <kkuehler@brave.com> | 2019-06-10 22:05:55 -0700 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-06-11 09:34:36 -0400 |
commit | 32f970e0531a0811392d2836773870acf649cf26 (patch) | |
tree | 2e65f2a122b6235c9e858ba4af36481475292747 /lib | |
parent | d1df7103280ef488434b103e5e9e3129c407e5b6 (diff) | |
download | aerc-32f970e0531a0811392d2836773870acf649cf26.tar.gz |
Move select functionality from msglist to msgstore
Remove msglist Next and Prev commands
Signed-off-by: Kevin Kuehler <kkuehler@brave.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/msgstore.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go index 5b4d5406..a81f9ad3 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -17,6 +17,7 @@ type MessageStore struct { // Ordered list of known UIDs Uids []uint32 + selected int bodyCallbacks map[uint32][]func(io.Reader) headerCallbacks map[uint32][]func(*types.MessageInfo) @@ -34,6 +35,7 @@ func NewMessageStore(worker *types.Worker, Deleted: make(map[uint32]interface{}), DirInfo: *dirInfo, + selected: 0, bodyCallbacks: make(map[uint32][]func(io.Reader)), headerCallbacks: make(map[uint32][]func(*types.MessageInfo)), @@ -279,3 +281,42 @@ func (store *MessageStore) Read(uids []uint32, read bool, Uids: set, }, cb) } + +func (store *MessageStore) Selected() *types.MessageInfo { + return store.Messages[store.Uids[len(store.Uids)-store.selected-1]] +} + +func (store *MessageStore) SelectedIndex() int { + return store.selected +} + +func (store *MessageStore) Select(index int) { + store.selected = index + for ; store.selected < 0; store.selected = len(store.Uids) + store.selected { + /* This space deliberately left blank */ + } + if store.selected > len(store.Uids) { + store.selected = len(store.Uids) + } +} + +func (store *MessageStore) nextPrev(delta int) { + if len(store.Uids) == 0 { + return + } + store.selected += delta + if store.selected < 0 { + store.selected = 0 + } + if store.selected >= len(store.Uids) { + store.selected = len(store.Uids) - 1 + } +} + +func (store *MessageStore) Next() { + store.nextPrev(1) +} + +func (store *MessageStore) Prev() { + store.nextPrev(-1) +} |