diff options
author | Reto Brunner <reto@labrat.space> | 2019-07-04 11:17:23 +0200 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-07-04 12:24:16 -0400 |
commit | b12eba55c3cac7e754d1a17c4da4ffa230846af9 (patch) | |
tree | fcca1e58282267b313b4ddc13fbe7a47bd64ad0d /widgets/dirlist.go | |
parent | 0abca31c1519cac19914fa7b1849126c2c512529 (diff) |
dirlist: simplify nextPrev() considerably
Assuming we always have a sorted dirlist
(other code depends on that already), we don't need to loop over the
dirStore.
Any filtering done should be performed elsewhere
Diffstat (limited to 'widgets/dirlist.go')
-rw-r--r-- | widgets/dirlist.go | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/widgets/dirlist.go b/widgets/dirlist.go index c7469d1..01adfe7 100644 --- a/widgets/dirlist.go +++ b/widgets/dirlist.go @@ -133,32 +133,18 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) { } func (dirlist *DirectoryList) nextPrev(delta int) { - for i, dir := range dirlist.dirs { - if dir == dirlist.selected { - var j int - ndirs := len(dirlist.dirs) - for j = i + delta; j != i; j += delta { - if j < 0 { - j = ndirs - 1 - } - if j >= ndirs { - j = 0 - } - name := dirlist.dirs[j] - if len(dirlist.acctConf.Folders) > 1 && name != dirlist.selected { - idx := sort.SearchStrings(dirlist.acctConf.Folders, name) - if idx == len(dirlist.acctConf.Folders) || - dirlist.acctConf.Folders[idx] != name { - - continue - } - } - break - } - dirlist.Select(dirlist.dirs[j]) - break - } + curIdx := sort.SearchStrings(dirlist.dirs, dirlist.selected) + if curIdx == len(dirlist.dirs) { + return + } + newIdx := curIdx + delta + ndirs := len(dirlist.dirs) + if newIdx < 0 { + newIdx = ndirs - 1 + } else if newIdx >= ndirs { + newIdx = 0 } + dirlist.Select(dirlist.dirs[newIdx]) } func (dirlist *DirectoryList) Next() { |