Page MenuHomePhabricator

Visual Editor Ace text component: cursor positioning incorrect when editing math, code blocks
Closed, ResolvedPublicBUG REPORT

Description

Start the visual editor on an arbitrary page in the English Wikipedia, for example
https://en.wikipedia.org/wiki/User:AxelBoldt/sandbox?veaction=edit . Choose Insert/Math formula, Code Block, or similar. Then type "ABCDEF".

You will notice that the blinking cursor is not placed after the F, but incorrectly somewhere in the middle of the string.

The zoom level appears to influence the precise positioning of the cursor, but the bug occurs at all zoom levels. I see it on Chrome and Firefox, whether logged in or not.

Event Timeline

This seems to specifically be related to the Ace editor component used in a MWAceEditorWidget, and seems to be tied to how the Ace editor is deciding how wide characters are. The line height seems to be off as well:

image.png (928×1 px, 85 KB)

It's a lot more obvious in Vector 2022, but still happens in old Vector (just taking most of a line for noticeable drift to occur).

Anything which triggers a re-render of the editor component after it's opened seems to fix it for the lifetime of that editor instance -- e.g. click into the "options" tab and then back to "formula".

DLynch renamed this task from Visual Editor Math Formula insertion: cursor positioning incorrect to Visual Editor Ace text component: cursor positioning incorrect.Feb 3 2023, 4:40 PM
DLynch updated the task description. (Show Details)
matmarex renamed this task from Visual Editor Ace text component: cursor positioning incorrect to Visual Editor Ace text component: cursor positioning incorrect when editing math, code blocks.Feb 3 2023, 5:13 PM

It seems that the issue occurs because the editor is set up while the dialog opening animation is still playing. During setup Ace computes font metrics, which it uses later to display the cursor etc., and the update changed how it does this (see this.$measureSizes = function in https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/CodeEditor/+/941cc7c109d34947e727df49ab059bc07ea31426%5E%21/), and while the previous method seems to have worked fine despite the animation, the new one thinks the font size is about half of what it really is.

Ace has committed a fix for it, so we could presumably either backport that into our bundled version or await a new release.

It looks like they release around once a month, and the last release was 3 weeks ago, so I say let's wait.

I've got an Ace update patch up on the subtask

EAkinloose subscribed.

I think we are good.

Screenshot 2023-03-06 at 18.09.01.png (1×2 px, 131 KB)

Yes, it seems fixed now. I tested on Windows/Firefox and Windows/Chrome.