Page MenuHomePhabricator

Review CodeMirror tickets about cursor position/text selections being misaligned
Closed, ResolvedPublic3 Estimated Story Points

Description

There is a long-known but rather random issue with the CodeMirror integration in VisualEditor. It happens only there because the way the two extensions interact is a little special. Roughly speaking, VisualEditor sits on top of CodeMirror, but is set to opacity: 0. The text cursor and text selections are done in the upper VisualEditor layer.

Sometimes these layers don't align:

  • Sometimes it's a special character in a line that's rendered different in the two layers. In cases like this the cursor is misplaced one or more characters to the left/right.
  • Apparently there are also situations where the cursor is misaligned an entire line up/down. This might be related to extremely long articles, or specific skins.

So what's this task about? Review all existing tickets here on Phabricator and check if any of them is related to what we, the WMDE-TechWish team, did. Especially make sure that the line number gutter we introduced didn't made any of the existing issues worse.

Discussed in story time on 2021-08-25, see https://docs.google.com/document/d/1Fj5ljAEtb_bEUeK-hMb3KzVzGohopp9WCakVnTar5Tc/edit#heading=h.4coyz4cwoadg.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Apparently there are also situations where the cursor is misaligned an entire line up/down. This might be related to extremely long articles, or specific skins.

That's because one line break happens at a slightly different point. These bugs tend to be very difficult, because text measuring is delicate as can be. You'll basically need the exact same rendering of every single glyph and the exact same CSS and dimensions for all surfaces at all times and the measuring that CodeMirror does needs to exactly match what the OS measures. Any potential subpixel of misalignment can throw something off, also think of client side extensions being able to interfere, or things like client side spelling checking perhaps..
Another candidate could be differing font-family fallbacks, as that might influence glyph replacement if a specific glyph is not in the primary font.

Uh, thanks a lot for the hint. That's super helpful.

I still wonder why that layering is even necessary. Why not just let CodeMirror do it's job? Is it because VisualEditor tries to keep track of all wikitext changes in an actual document model in the background? Or something with undo?

Things to search for:

thiemowmde moved this task from Sprint Backlog to Review on the WMDE-TechWish-Sprint-2021-09-01 board.

I did some rather broad searches for "cursor", "selection", and "misplaced". I limited myself to recently updated ticket, as older ones can't be about changes we did. Some notable ones I found:

That's what I could find. Did I miss something?

awight subscribed.

Looking through these bugs, +1 that no additional comments have come in since we deployed line numbering.

That's what I could find. Did I miss something?

I meet this bug and I just commented in T252965 (because I have thought this was this issue, but I’m not that task’s author).

So, shouldn’t this task tagged with VisualEditor-MediaWiki-2017WikitextEditor to make it easier to find?

@Pols12, thanks a lot for the hint. I added the ticket to the list above. Unfortunately it's one of these older bugs our team is currently unable to tackle.

thiemowmde moved this task from Demo to Done on the WMDE-TechWish-Sprint-2021-09-01 board.