Fix text selection rectangles on BiDi/RTL text#649
Merged
Conversation
9db8ee9 to
b644992
Compare
On single letter text nodes handled by ::first-letter,
getRect() would not find the text node, resulting
in that letter being absent from highlights.
ie. with:
<style>p::first-letter {color: blue}</style>
<p>A<span> single letter before a span</span></p>
<p><span>A</span> single letter in a span</p>
Add optional *ctxFlags parameter, allowing getting more info about the context of the char we return the Rect for: BiDi and paragraph and char RTL status.
Previous implementations had shortcuts that were valid only on plain LTR or RTL text. With BiDi text, it gets a lot more complex: we can't take the shortcuts and need to iterate char by char, handling direction changes, pending or adding or merging rects.
This was referenced Feb 14, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
::first-letter: fix when single letter text nodeOn single letter text nodes handled by
::first-letter,getRect()would not find the text node, resulting in that letter being absent from highlights.ie. with:
ldomXPointer::getRectEx(): return optional contextAdd optional
*ctxFlagsparameter, allowing getting more info about the context of the char we return the Rect for: BiDi and paragraph and char RTL status.ldomXRange::getSegmentRects(): fix when BiDi/RTLPrevious implementations had shortcuts that were valid only on plain LTR or RTL text.
With BiDi text, it gets a lot more complex: we can't take the shortcuts and need to iterate char by change, handling direction changes, pending or adding or merging rects.
I asked about some situations with holes at BiDi boundaries it they should be avoided at koreader/koreader#5359 (comment) - and ended up adding stuff to avoid them.
Started initially with the help of Github copilot in #645, who nearly gave up at #645 (comment).
Then, man beat the machine at #645 (comment), and I continued it manually.
Closes #644 (where I express my initial amazement and followup desperation about working with Github copilot).
This change is