News for hackers. Stuff that matters.
Re:Can we believe our eyes? Misleading people with Unicode. by xtacy on Thursday August 11, 2011 @12:28PM (#2873558)
Try selecting the text, it behaves funnily in a way that I can't understand!
Re:Can we believe our eyes? Misleading people with Unicode. by bzbarsky on Thursday August 11, 2011 @01:02PM (#2873744)
It behaves funny in a very "simple" way. Selections have this little problem where you move your mouse over the visual representation but the selection is in the logical representation.

So say your logical text is this:

  ltr LTR.
where the capital letters are RTL chars (whether because they're actually RTL or because of an RLO in the char stream). That is, the above represents the reading order. Visually this would look like this:

  ltr RTL.
assuming that this paragraph directionality is left-to-right; a reader reading this text would read the letters in the order 'l', 't', 'r', ' ', n 'L', 'T', 'R' (which if you note matches the logical order, hence the name).

Now say you mouse down between the 't' the 'r' and drag right until your mouse is between the 'R' and the 'T'. Those are your selection endpoints. But the selection happens on the _logical_ text, so what's selected is the 'r', the space, the 'L', and the 'T' (and even in that order). You can see that in the example above; if you mouse down between the two 'o' chars in "elgooG" and drag right to between the two 'o' chars in "Google", then you get exactly this sort of behavior.

Re:Can we believe our eyes? Misleading people with Unicode. by xtacy on Thursday August 11, 2011 @01:49PM (#2873943)
Ah, that makes sense. I didn't think that text selection defines end points and everything between the endpoints (in the physical text) is highlighted. So, if you have:

    Hi RLO elgooG
    ^ select ^
I expected (everything between the logical end points selected):

    Hi Google
    ^^^^^^^ (selected)
In other words, I expected text selection to obey RLO character as well.
Re:Can we believe our eyes? Misleading people with Unicode. by groby_b on Thursday August 11, 2011 @08:05PM (#2875382)
Nope - selection is on logical text, not on visual text. For tons of "fun" reasons. If you want an afternoon of madness, read the Chrome or WebKit sources relating to BiDi text.

If that's not enough pain, read http://unicode.org/reports/tr9/ (the unicode BiDi algorithm)

If you're still liking it, I know a few people who'd love to hire you :)

Re:Can we believe our eyes? Misleading people with Unicode. by bzbarsky on Friday August 12, 2011 @01:08AM (#2876069)
I think you're confusing your logical and physical, or I'm misunderstanding you.

Moving your mouse happens over the physical text and sets the selection endpoints. Then everything that's logically (as opposed to physically) between those endpoints is highlighted. Your "I expected" diagram is showing the text physically between the endpoints, not the text logically between them...