Menu: Fix fallout from #12583 on hasDPad devices (#12657)

Tweak `mergeTitleBarIntoLayout` to keep the current selection (adjusted for the added rows) instead of resetting the focus.

It only actually called `moveFocusTo` on `hasDPad` devices, which explains why this was missed during testing.

Fix https://github.com/koreader/koreader/pull/12583#issuecomment-2423554770
This commit is contained in:
NiLuJe
2024-10-21 13:35:44 +02:00
committed by GitHub
parent 238f0c0896
commit fdd342de40
2 changed files with 7 additions and 12 deletions

View File

@@ -1136,21 +1136,16 @@ function Menu:mergeTitleBarIntoLayout()
-- Title bar items can be accessed through key mappings on kindle
return
end
local menu_item_layout_start_row = 1
-- On hasFewKeys devices, Menu uses the "Right" key to trigger the context menu: we can't use it to move focus in horizontal directions.
-- So, add title bar buttons to FocusManager's layout in a vertical-only layout
local title_bar_layout = self.title_bar:generateVerticalLayout()
for _, row in ipairs(title_bar_layout) do
table.insert(self.layout, menu_item_layout_start_row, row)
menu_item_layout_start_row = menu_item_layout_start_row + 1
end
if menu_item_layout_start_row > #self.layout then -- no menu items
menu_item_layout_start_row = #self.layout -- avoid index overflow
end
if Device:hasDPad() then
-- Move focus to the first menu item, if any, in keeping with the pre-FocusManager behavior
self:moveFocusTo(1, menu_item_layout_start_row, FocusManager.NOT_FOCUS)
for i, row in ipairs(title_bar_layout) do
-- Insert the title bar in the top rows of our layout
table.insert(self.layout, i, row)
end
-- Adjust for the added rows to keep our current selection
self.selected.y = self.selected.y + #title_bar_layout
logger.dbg("Menu:mergeTitleBarIntoLayout: Adjusted focus position to account for added titlebar rows:", self.selected.x, ",", self.selected.y)
end
--[[

View File

@@ -139,6 +139,7 @@ function CoverMenu:updateItems(select_number, no_recalculate_dimen)
-- As done in Menu:updateItems()
self:updatePageInfo(select_number)
Menu.mergeTitleBarIntoLayout(self)
self.show_parent.dithered = self._has_cover_images
UIManager:setDirty(self.show_parent, function()
@@ -316,7 +317,6 @@ function CoverMenu:updateItems(select_number, no_recalculate_dimen)
self.showFileDialog_ours = self.showFileDialog
end)
end
Menu.mergeTitleBarIntoLayout(self)
end
-- Similar to showFileDialog setup just above, but for History,