KeySelection: add per-doc support for RTL traversal
This commit is contained in:
1 parent
82a5f20b25
commit
2c0f541516
1 file changed
+19
-3
@@ -247,6 +247,7 @@ function ReaderKeySelection:startHighlightIndicator()
|
||||
end
|
||||
local center_x = rect.x + rect.w * 0.5
|
||||
local center_y = rect.y + rect.h * 0.5
|
||||
self.invert_ui_layout = self.view:shouldInvertBiDiLayoutMirroring()
|
||||
local nearest_word = self:_getNearestWordFromScreenPoint(center_x, center_y)
|
||||
if nearest_word then
|
||||
self:_setIndicatorToWord(nearest_word)
|
||||
@@ -453,6 +454,9 @@ function ReaderKeySelection:_resolveSplitWordFromX(word, x_pos)
|
||||
else
|
||||
is_head = right_half
|
||||
end
|
||||
if self.invert_ui_layout then
|
||||
is_head = not is_head
|
||||
end
|
||||
if is_head then
|
||||
word.is_split_fragment = "head"
|
||||
return word, head_box.y
|
||||
@@ -568,18 +572,22 @@ function ReaderKeySelection:_getWordAnchorCoordinates(word)
|
||||
end
|
||||
end
|
||||
if word.is_split_fragment then
|
||||
local head_is_left = self.mirroredUI
|
||||
if self.invert_ui_layout then
|
||||
head_is_left = not head_is_left
|
||||
end
|
||||
-- Grab the width of the crosshairs so we can tuck it inside the bounding box
|
||||
local ind_w = self._current_indicator_pos and self._current_indicator_pos.w or 0
|
||||
if word.is_split_fragment == "head" and word.segments then
|
||||
-- Target the physical box of the head fragment
|
||||
local head_box = word.segments[1]
|
||||
local x = self.mirroredUI and head_box.x or (head_box.x + head_box.w - ind_w)
|
||||
local x = head_is_left and head_box.x or (head_box.x + head_box.w - ind_w)
|
||||
local y = head_box.y + head_box.h * 0.5
|
||||
return x, y, true
|
||||
elseif word.is_split_fragment == "tail" and word.segments then
|
||||
-- Target the physical box of the tail fragment
|
||||
local tail_box = word.segments[#word.segments]
|
||||
local x = self.mirroredUI and (tail_box.x + tail_box.w - ind_w) or tail_box.x
|
||||
local x = head_is_left and (tail_box.x + tail_box.w - ind_w) or tail_box.x
|
||||
local y = tail_box.y + tail_box.h * 0.5
|
||||
return x, y, true
|
||||
end
|
||||
@@ -700,6 +708,10 @@ end
|
||||
function ReaderKeySelection:_getAdjacentWordRolling(word, direction, lock_line_center_y, lock_line_tolerance)
|
||||
if not word or not word.pos0 then return nil end
|
||||
local is_forward_physical = (not self.mirroredUI and direction > 0) or (self.mirroredUI and direction < 0)
|
||||
if self.invert_ui_layout then
|
||||
is_forward_physical = not is_forward_physical
|
||||
direction = -direction
|
||||
end
|
||||
-- If we're on one half of a split word, the next 'line' is just the other half.
|
||||
if self:_isSplitHyphenatedWord(word) then
|
||||
if is_forward_physical and word.is_split_fragment == "head" then
|
||||
@@ -726,8 +738,12 @@ function ReaderKeySelection:_getAdjacentWordRolling(word, direction, lock_line_c
|
||||
-- probe for them, otherwise indicator will hit a boundary before the fragment.
|
||||
if not doc:isXPointerInCurrentPage(next_xp) then
|
||||
logger.dbg("ReaderKeySelection: Logical boundary hit. Attempting physical horizontal probe.")
|
||||
local head_is_left = self.mirroredUI
|
||||
if self.invert_ui_layout then
|
||||
head_is_left = not head_is_left
|
||||
end
|
||||
local probe = {}
|
||||
if self.mirroredUI then
|
||||
if head_is_left then
|
||||
probe.x = is_forward_physical and (word.sbox.x - 10) or (word.sbox.x + word.sbox.w + 10)
|
||||
else
|
||||
probe.x = is_forward_physical and (word.sbox.x + word.sbox.w + 10) or (word.sbox.x - 10)
|
||||
|
||||
Reference in new issue
Block a user