Page MenuHomePhabricator

SyntaxHighlight in VisualEditor behaves wrongly with a sort of align right when typing
Closed, ResolvedPublicBUG REPORT

Description

List of steps to reproduce (step by step, including full links if applicable):

  • Edit a page with VisualEditor, e.g. Wikipedia Sandbox
  • Select in the menu Insert > Code block
  • Start typing some code

What happens?:

When typing the textarea is always moved on the right of the cursor, and consequently we don’t see what we are typing on the left of the cursor. See video below.

This issue seems to occur when the page is newly opened (after a hard refresh Ctrl+F5/Ctrl+R), but it occurs no more the second time we open the dialog box in the same page, or possibly when we edit another page without hard refresh (but this could depend on the browser, I’m not sure about the exact conditions).

Task 303964.gif (1,236×620 px, 3 MB)

What should have happened instead?:

The textarea should not move on the right.

Software version (if not a Wikimedia wiki), browser information, screenshots, other information, etc.:

  • MediaWiki 1.38.0-alpha (git 2b818a6) (current version on English Wikipedia)
  • SyntaxHighlight - git 1ae9ab5
  • VisualEditor - git afde13a
  • Occurs on all skins currently deployed (Vector, Vector 2022, Monobook, MinervaNeue, Timeless)
  • Occurs on Firefox 97-98, Brave 1.35.103, Chromium 90.0.4430.212, Opera 84.0.4316.14 on Debian 10, as well as Firefox 97 on Windows 10

Occurs also on an independant MediaWiki 1.36 with SyntaxHighlight and VisualEditor in REL1_36.

Event Timeline

I’m investigating. I’m pretty sure the issue is related to the RL module ext.codeEditor.ace which is dynamically loaded by VE in ve.ui.MWAceEditorWidget, and it seems there is some incomplete initialisation when the promise is returned.

Note: there is no issue when the extension CodeEditor is not activated (tested on a MW 1.36 where I reproduce the issue).

Below is a fix inside the extension VisualEditor (for my installation with MW 1.36), but given I don’t know well Ace it should be double-checked:

diff --git modules/ve-mw/ui/widgets/ve.ui.MWAceEditorWidget.js modules/ve-mw/ui/widgets/ve.ui.MWAceEditorWidget.js
index 14ed4abae..1cadd3c19 100644
--- modules/ve-mw/ui/widgets/ve.ui.MWAceEditorWidget.js
+++ modules/ve-mw/ui/widgets/ve.ui.MWAceEditorWidget.js
@@ -142,3 +142,3 @@ ve.ui.MWAceEditorWidget.prototype.setupEditor = function () {
 	this.setEditorValue( this.getValue() );
-	this.editor.resize();
+	this.editor.resize( true );
 };

According to the API Reference of Ace, the method resize has a parameter force, and it seems setting it to true solves the issue.

Change 771967 had a related patch set uploaded (by Esanders; author: Esanders):

[mediawiki/extensions/VisualEditor@master] Fix resize of MWAceEditorWidget when setting up

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

Change 771967 merged by jenkins-bot:

[mediawiki/extensions/VisualEditor@master] Fix resize of MWAceEditorWidget when setting up

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