lib/msgstore: Fix Select, Next, Prev with filter
When filter is active we want to use store.results instead of store.uids, since we are dealing with a subset of the uids. Otherwise any methods involving len will have undefined behavior. Signed-off-by: Kevin Kuehler <keur@ocf.berkeley.edu>
This commit is contained in:
parent
b812257ba9
commit
2804f00001
|
@ -310,7 +310,7 @@ func (store *MessageStore) Uids() []uint32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *MessageStore) Selected() *models.MessageInfo {
|
func (store *MessageStore) Selected() *models.MessageInfo {
|
||||||
return store.Messages[store.uids[len(store.uids)-store.selected-1]]
|
return store.Messages[store.Uids()[len(store.Uids())-store.selected-1]]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *MessageStore) SelectedIndex() int {
|
func (store *MessageStore) SelectedIndex() int {
|
||||||
|
@ -318,32 +318,34 @@ func (store *MessageStore) SelectedIndex() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *MessageStore) Select(index int) {
|
func (store *MessageStore) Select(index int) {
|
||||||
|
uids := store.Uids()
|
||||||
store.selected = index
|
store.selected = index
|
||||||
for ; store.selected < 0; store.selected = len(store.uids) + store.selected {
|
for ; store.selected < 0; store.selected = len(uids) + store.selected {
|
||||||
/* This space deliberately left blank */
|
/* This space deliberately left blank */
|
||||||
}
|
}
|
||||||
if store.selected > len(store.uids) {
|
if store.selected > len(uids) {
|
||||||
store.selected = len(store.uids)
|
store.selected = len(uids)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *MessageStore) nextPrev(delta int) {
|
func (store *MessageStore) nextPrev(delta int) {
|
||||||
if len(store.uids) == 0 {
|
uids := store.Uids()
|
||||||
|
if len(uids) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
store.selected += delta
|
store.selected += delta
|
||||||
if store.selected < 0 {
|
if store.selected < 0 {
|
||||||
store.selected = 0
|
store.selected = 0
|
||||||
}
|
}
|
||||||
if store.selected >= len(store.uids) {
|
if store.selected >= len(uids) {
|
||||||
store.selected = len(store.uids) - 1
|
store.selected = len(uids) - 1
|
||||||
}
|
}
|
||||||
nextResultIndex := len(store.results) - store.resultIndex - 2*delta
|
nextResultIndex := len(store.results) - store.resultIndex - 2*delta
|
||||||
if nextResultIndex < 0 || nextResultIndex >= len(store.results) {
|
if nextResultIndex < 0 || nextResultIndex >= len(store.results) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
nextResultUid := store.results[nextResultIndex]
|
nextResultUid := store.results[nextResultIndex]
|
||||||
selectedUid := store.uids[len(store.uids)-store.selected-1]
|
selectedUid := uids[len(uids)-store.selected-1]
|
||||||
if nextResultUid == selectedUid {
|
if nextResultUid == selectedUid {
|
||||||
store.resultIndex += delta
|
store.resultIndex += delta
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue