Page MenuHomePhabricator

Text misaligned when switching directionality using CodeMirror in 2017 Source Editor
Open, Needs TriagePublicBUG REPORT

Description

What is the problem?

Bug found by @Bhsd in T357482#10112821.

While using the 2017 Source Editor with syntax highlighting (CodeMirror) enabled, if I click "View as right-to-left" (or "View as left-to-right" in an RTL wiki) the text can get misaligned.

It is particularly noticeable when you start typing. What seems to happen is when you first switch from LTR to RTL the div.ve-ce-documentNode style attribute is margin-left: 0px; margin-right: 22px. But, when you start typing (at least in an LTR language) it changes to margin-left: 22px; margin-right: 0px.

Steps to reproduce problem
  1. https://en.wikipedia.beta.wmflabs.org/w/index.php?title=Conflict-title-0.745086650833999-Iñtërnâtiônàlizætiøn&veaction=editsource
  2. Open the Page options menu (burger) and click "View as right-to-left" (or press ctrl shift x)
  3. Type something

Expected behaviour: The text you type is aligned with the current cursor position.
Observed behaviour: The text appears in a different place.

Another way:

  1. https://ar.wikipedia.beta.wmflabs.org/w/index.php?title=النيجر&veaction=editsource
  2. Switch to LTR
  3. Open the devtools, go to the JS Console and run $(".ve-ce-documentNode-codeEditor-webkit-hide").css('-webkit-text-fill-color', 'black')

Expected behaviour: No notable change.
Observed behaviour: Text becomes blurred (see the last screenshot below).

Environment

Browser: Firefox 115, Chromium 120, Chrome 128.
Wiki(s): https://en.wikipedia.beta.wmflabs.org MediaWiki 1.43.0-alpha (910d89a) 06:57, 6 September 2024.
Editor: VisualEditor – (cefa56e) 10:21, 5 September 2024. CodeMirror 6.0.0 (b8cf07f) 07:23, 5 September 2024.

Screenshots

rtl_switch_misalignment.png (295×1 px, 35 KB)

Example of this article before switching to LTR:

bs_win11_Chrome_128.0.jpg (764×1 px, 96 KB)

After switching to LTR:

bs_win11_Chrome_128.0 (1).jpg (764×1 px, 100 KB)

Event Timeline

Change #1084938 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] ve.ui.CodeMirror.v6: use view's direction when updating gutter width

https://gerrit.wikimedia.org/r/1084938

Change #1084938 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] ve.ui.CodeMirror.v6: use view's direction when updating gutter width

https://gerrit.wikimedia.org/r/1084938

MusikAnimal subscribed.

Passing this back to Dom for QA. I am hoping the change made to fix this may help with some of the other issues identified at T357482.

Nope! The "Another way" repro steps is still a problem. I'm not done here yet.

Change #1085479 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] ve.ui.CodeMirror.v6: don't auto-flip CSS rules affecting gutter

https://gerrit.wikimedia.org/r/1085479

Change #1085479 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] ve.ui.CodeMirror.v6: don't auto-flip CSS rules affecting gutter

https://gerrit.wikimedia.org/r/1085479

I cannot reproduce the misalignment issues from the description.

However, when I switch to and from syntax highlighting the cursor isn't always in the correct place. This persists when I press the movements keys, but goes away when I start typing.

Change #1092418 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/CodeMirror@master] ve.ui.CodeMirrorAction.v6: Use direction of surface view, not model view

https://gerrit.wikimedia.org/r/1092418

Change #1092418 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] ve.ui.CodeMirrorAction.v6: Use direction of surface view, not model view

https://gerrit.wikimedia.org/r/1092418

I cannot reproduce the misalignment issues from the description.

However, when I switch to and from syntax highlighting the cursor isn't always in the correct place. This persists when I press the movements keys, but goes away when I start typing.

Fixed! Technically this was an unrelated bug as this happens anytime you load CodeMirror with the directionality set to RTL but the page itself is LTR. Anyway I'm very grateful you discovered this. Thank you!!