Skip to content

Commit

Permalink
feat(window): Menu:select_next negative count
Browse files Browse the repository at this point in the history
When using a negative count for `Menu:select_next` don't go into
negative indices instead rollover to the last entry.
  • Loading branch information
vdbe committed Nov 1, 2024
1 parent 117c0c5 commit 6466e49
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lua/care/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ care.api = {
care.core.menu:close()
end,
select_prev = function(count)
care.core.menu:select_prev(count)
care.core.menu:select_next(-(count or 1))
end,
select_next = function(count)
care.core.menu:select_next(count)
Expand Down
13 changes: 4 additions & 9 deletions lua/care/menu/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +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

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:select(-1)

self:select_next(-count)
end

function Menu:open(entries, offset)
Expand Down

0 comments on commit 6466e49

Please sign in to comment.