fix: menu prev/next navigation shouldn't smooth scroll

closes #352
This commit is contained in:
tomasklaen
2022-10-29 19:30:34 +02:00
parent 64feeb04b7
commit 972dd41b94

View File

@@ -329,10 +329,13 @@ end
---@param index? integer
---@param menu? MenuStack
function Menu:scroll_to_index(index, menu)
---@param immediate? boolean
function Menu:scroll_to_index(index, menu, immediate)
menu = menu or self.current
if (index and index >= 1 and index <= #menu.items) then
self:scroll_to(round((self.scroll_step * (index - 1)) - ((menu.height - self.scroll_step) / 2)), menu)
local position = round((self.scroll_step * (index - 1)) - ((menu.height - self.scroll_step) / 2))
if immediate then self:set_scroll_to(position, menu)
else self:scroll_to(position, menu) end
end
end
@@ -425,14 +428,14 @@ end
function Menu:prev(menu)
menu = menu or self.current
menu.selected_index = math.max(menu.selected_index and menu.selected_index - 1 or #menu.items, 1)
self:scroll_to_index(menu.selected_index, menu)
self:scroll_to_index(menu.selected_index, menu, true)
end
---@param menu? MenuStack
function Menu:next(menu)
menu = menu or self.current
menu.selected_index = math.min(menu.selected_index and menu.selected_index + 1 or 1, #menu.items)
self:scroll_to_index(menu.selected_index, menu)
self:scroll_to_index(menu.selected_index, menu, true)
end
function Menu:back()
@@ -579,8 +582,8 @@ function Menu:enable_key_bindings()
self:add_key_binding('shift+enter', 'menu-select-alt5', self:create_key_action('open_selected_item_soft'))
self:add_key_binding('shift+kp_enter', 'menu-select-alt6', self:create_key_action('open_selected_item_soft'))
self:add_key_binding('esc', 'menu-close', self:create_key_action('close'))
self:add_key_binding('pgup', 'menu-page-up', self:create_key_action('on_pgup'))
self:add_key_binding('pgdwn', 'menu-page-down', self:create_key_action('on_pgdwn'))
self:add_key_binding('pgup', 'menu-page-up', self:create_key_action('on_pgup'), 'repeatable')
self:add_key_binding('pgdwn', 'menu-page-down', self:create_key_action('on_pgdwn'), 'repeatable')
self:add_key_binding('home', 'menu-home', self:create_key_action('on_home'))
self:add_key_binding('end', 'menu-end', self:create_key_action('on_end'))
end