Hit Test Adjustment logic

0 views
Skip to first unread message

Stephen Chenney

unread,
Jun 25, 2024, 9:18:44 PM6/25/24
to editing-dev
Could someone please explain to me the problem that is being solved by Hit Test Adjustment, specifically BidiAdjustment::AdjustForHitTest (https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/editing/bidi_adjustment.cc;drc=cc5be7150eef183a1b9a6716d42a396ab7c59733;l=758)?

It messes up selection of mixed bidi content in horrible ways and has multiple bugs filed against it, including one I just filed. All I can think of is that it is trying to do something about the fundamentally difficult situation with mixed bidi where some runs have text indices increasing left to right while others have them increasing right to left. When you try to select such content the start and end indices of the selection run may not visually encase the content you have just dragged over. But if that's the intention the algorithm seems to have numerous bugs.

Before I go hacking to try to fix it, I would like to understand what the desired behavior is.

Stephen.

Xiaocheng Hu

unread,
Jul 2, 2024, 2:56:04 AM7/2/24
to Stephen Chenney, editing-dev
Ah, my old friend :)

Long story short, BidiAdjustment tries to create a 1:1 mapping between visual and logical positions at bidi run boundaries. And Blink does it in a horrible way with tons of bugs.

See also:
https://goo.gl/NDz7CS for more background about what BidiAdjustment is and how it (doesn't) work
http://bit.ly/2xVMjdc for how I tried to fixed it

--
You received this message because you are subscribed to the Google Groups "editing-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to editing-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/editing-dev/CAGsbWzRFR2kS8Sc4LtcDQ30NfERqUaupy%2BG8ACYMYSUbJpb-HQ%40mail.gmail.com.

Stephen Chenney

unread,
Jul 2, 2024, 9:57:26 PM7/2/24
to Xiaocheng Hu, editing-dev
Thanks. I don't think I want to make changes in this hairy code, but unfortunately the canvas Text Metrics implementation of caretPositionFromPoint will differ from the DOM version because it will be finding the text run (after bidi algorithm) then taking CaretPositionForHitTest. So no bidi adjustment.

If I was going to change anything, for hit testing (also mouse/touch selection) I would only do bidi adjustment if the hit point was very close to the boundary between two characters, not always when the offset returned is at a bidi boundary. I think that info is available.

Cheers,
Stephen.
Reply all
Reply to author
Forward
0 new messages