Skip to content

Commit

Permalink
Merge pull request #120 from vdbe/feat/menu/select_next/negative
Browse files Browse the repository at this point in the history
feat(menu): simplify calculations for selection
  • Loading branch information
max397574 authored Nov 1, 2024
2 parents 97ceb1c + 36bcd88 commit dd7fa89
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lua/care/menu/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,15 @@ end

function Menu:select_next(count)
count = count or 1
self.index = self.index + count
if self.index > #self.entries then
self.index = self.index - #self.entries - 1
end
self.index = (self.index + count) % (#self.entries + 1)

self:select(1)
end

function Menu:select_prev(count)
count = count or 1
self.index = self.index - count
if self.index < 0 then
self.index = #self.entries + self.index + 1
end
self.index = (self.index - count) % (#self.entries + 1)

self:select(-1)
end

Expand Down

0 comments on commit dd7fa89

Please sign in to comment.