diff --git a/lua/care/init.lua b/lua/care/init.lua index 3ba3bb5..7e72c3d 100644 --- a/lua/care/init.lua +++ b/lua/care/init.lua @@ -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) diff --git a/lua/care/menu/init.lua b/lua/care/menu/init.lua index 26624ba..1293035 100644 --- a/lua/care/menu/init.lua +++ b/lua/care/menu/init.lua @@ -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)