[FocusManager] correct cursor keys in RTL (#13362)
Some checks failed
macos / macOS 13 x86-64 🔨15.2 🎯10.15 (push) Has been cancelled
macos / macOS 14 ARM64 🔨15.4 🎯11.0 (push) Has been cancelled

This commit is contained in:
David
2025-04-10 22:42:48 +01:00
committed by GitHub
parent d6771ebe61
commit 3def243f97
3 changed files with 35 additions and 15 deletions

View File

@@ -1,9 +1,10 @@
local bit = require("bit")
local BD = require("ui/bidi")
local Device = require("device")
local Event = require("ui/event")
local InputContainer = require("ui/widget/container/inputcontainer")
local logger = require("logger")
local UIManager = require("ui/uimanager")
local bit = require("bit")
local logger = require("logger")
local util = require("util")
--[[
Wrapper Widget that manages focus for a whole dialog
@@ -156,6 +157,7 @@ function FocusManager:onFocusHalfMove(args)
end
elseif direction == "left" then
dx = - math.floor(#row / 2)
if BD.mirroredUILayout() then dx = -dx end
if dx == 0 then
dx = -1
elseif dx + x <= 0 then
@@ -163,12 +165,19 @@ function FocusManager:onFocusHalfMove(args)
end
elseif direction == "right" then
dx = math.floor(#row / 2)
if BD.mirroredUILayout() then dx = -dx end
if dx == 0 then
dx = 1
elseif dx + x > #row then
dx = #row - y -- last column
dx = #row - x -- last column
end
end
if dx ~= 0 and BD.mirroredUILayout() then
-- When in RTL we mirror horizontally the elements/buttons on the screen, however we don't mirror self.layout
-- therefore we must account for this when moving the focus. Since we're already inverting dx in the FocusMove
-- method, we need to "unfix" our value here, before calling onFocusMove, where it will be flipped again.
dx = -dx
end
return self:onFocusMove({dx, dy})
end
@@ -214,6 +223,13 @@ function FocusManager:onFocusMove(args)
end
local dx, dy = unpack(args)
-- Flip horizontal direction in RTL mode
if dx ~= 0 and BD.mirroredUILayout() then
-- When in RTL we mirror horizontally the elements/buttons on the screen, however we don't mirror self.layout
-- therefore we must account for this when moving the focus.
dx = -dx
end
if (dx ~= 0 and not self.movement_allowed.x)
or (dy ~= 0 and not self.movement_allowed.y) then
return true