eclipse-theia / theia

Eclipse Theia is a cloud & desktop IDE framework implemented in TypeScript.
http://theia-ide.org
Eclipse Public License 2.0
19.96k stars 2.5k forks source link

Right-to-left language issue in Editor with parentheses use #14256

Open dannaf opened 2 days ago

dannaf commented 2 days ago

Bug Description:

When typing in a right-to-left language in the Editor, word sequence order is not maintained properly when parentheses are used. (I observed this bug with Hebrew, specifically, but presumably it may affect right-to-left languages generally.)

Steps to Reproduce:

  1. Create a Markdown file testing.md and open it in the Theia Editor.
  2. Type or paste a Hebrew sentence that has a part in parentheses in the middle, and observe that the order of the parts (before, during/between, and after the parentheses) is not retained properly as right-to-left. Can paste the following sentence for example:
זה משפט כדי לבדוק את הבעיה (את הבעיה שעליה מדובר) ורואים שהיא קיימת

To make sure the visual sequence is clear, here is a screenshot of how the sentence is supposed to look (a screenshot of the codeblock text above, which is correct):

image

which in my current/default font in the Theia Editor should look like:

image

But here is how it appears in the Theia Editor for me:

image

Notice how the three parts are reversed. Each part is internally in the correct word order (and each word is in the correct character order), but the sequence of these parts is reversed.


Note also that the problem arises as soon as the first parenthesis is typed, which already appears in the wrong place (as though it is at the current cursor position in a left-to-right sentence, i.e. at the right, instead of appearing at the proper cursor position for a right-to-left sentence, i.e. at the left). This makes the Theia Editor almost unusable for typing prose in Hebrew, as any use of parentheses completely throws off the entire line (which should be able to accommodate even a whole paragraph).

Moreover, it is then difficult to correct the problem after typing the text with the parentheses (even if the user may want to add linebreaks before and after the parentheses to alleviate this) as the Editor graphics are then desynchronized with the actual cursor position, i.e. clicking or using the arrow keys becomes very confusing; adding line breaks becomes a guessing game of trial and error. To best see this, which may even be a separate bug, click on the left-most Hebrew character that's to the right of the left parenthesis, in the sentence as it appears in the incorrect order when pasted with the current bug, as shown non-selected in the following screenshot (it is not selected precisely due to the issue that is being described here, that there is a cursor issue when trying to target that character)

image

and observe the Editor cursor appear at a different location than where the user clicked, namely to the right of the right-most character that's to the left of the right parenthesis, just-left of the right parenthesis, as shown in the next screenshot:

image

Additional Information

msujew commented 2 days ago

Hey @dannaf,

As far as I'm aware, monaco editor doesn't support RTL languages. Can you try whether this works in VS Code? If it doesn't, please file an issue with them.

dannaf commented 3 hours ago

Aw, that's an upsetting surprise; you are correct, as noted here: https://github.com/microsoft/monaco-editor/issues/2371#issuecomment-1459973407. I'll try to reopen that discussion there sometime hopefully.

But, as for Theia, I tried it now with VS Code and it actually did work better than in Theia. When I pasted the testing sentence that I suggested above it appeared fine:

image

However, when I typed it the behavior was a bit strange; a bit strange but usable, and it ended up fine at the end of the sentence. What seems to occur is that when typing RTL the cursor position is fine intra-word (i.e. on the left) but upon every spacebar it teleports to the full-right (instead of moving one spacebar-worth further to the left) but it thereafter teleports back to the full-left when starting to type the next word. The same thing happens during the parentheses, except that with the automatic placement of the closing parentheses in the editor upon opening the first parentheses it looks a bit more strange as there is a closing parenthesis hanging out to the right of the sentence. But this goes away when typing the close of the parenthesis, at which point the right-dangling parenthesis teleports to the left where it should be and that ordeal gets wrapped up.

This inconvenience in VS Code is not ideal, but I would say that it is essentially usable for a flexible user who can ignore the junk happening at the right like the cursor and the parenthesis hanging out there, and focus on writing beautifully into the sunset—I mean, writing onwards to the left -:) Whereas the current situation in Theia I characterize as unusable, because any use of parentheses demolishes the entire line by chopping it into parts and then scrambling them up.