Problem in combining RTL & LTR texts
-
I found recently that if you have both RTL & LTR text in the same line, highlighting words doesn’t work properly.
For example, the line below has an Arabic word “Phone” and a phone number, when I try to double click on the number, it highlights the word and part of the number, but copying it will actually copy the number only. However, if I manually highlight the number and copy it, it will copy the word with part of the number.
NOTE: This problem will occur only when text direction is set to LTR.
///////Example///////
الهاتف:0505050550 -
It seems that Scintilla support visual rendering of lines with RTL symbols by reversing specific sequences but “forgets” to extend this support to anything beyond the rendering itself. Highlighting adds background color at absolute index ranges.
Not even sure if Scintilla implements this support directly or get it for free from the Win32 APIs it uses.If you typed the following Logical order:
<RTL sequence A…B> <LTR sequence C…D> < RTL sequence E…F>
Scintilla will display the following Visual order:
<Reversed RTL sequence F…E> <LTR sequence C…D> <Reversed RTL sequence F…E>Logical: A..B C..D E..F Visual: F..E C..D B..A
Now when you move with with the cursor from index 0 to the right the cursor will traverse the visual order.
But if you select a range of indexes [n:m] the range will refer to the logical order while the highlight will show the visual order.
Double click calculates the index location within the window, selects text at that index from the logical order and highlight the incorrect range within the visual order.To fix that Scintilla will need to maintain for each line the mapping of logical to visual indexes and consult this mapping for cursor movement and highlighting. This can also lead to broken multiple highlighting if you select, in the example, [B:C].
It took Microsoft many years to make this work correctly. Not sure if all products support it or only Word.
I will not expect a free project that mainly target developers to make such a change anytime soon.
If you need RTL support stick with Word and its likes.