Page MenuHomePhabricator

Inserting a table breaks CodeMirror highlighting in NWE
Closed, ResolvedPublic

Description

On Firefox, using the tool to insert a table in the 2017 wikitext editor while having CodeMirror syntax highlighting enabled causes the CodeMirror highlighting to break. The highlighting remains broken even if you try to revert the changes via the undo button.

Tested on Firefox 72.0.2 on mediawiki.org (MediaWiki 1.35.0-wmf16). The problem also exists on MediaWiki 1.33.2.

Event Timeline

TK-999 created this task.Jan 24 2020, 4:00 PM
Restricted Application added projects: VisualEditor, Community-Tech. · View Herald TranscriptJan 24 2020, 4:00 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

I've tried to debug this a bit. It seems that the generated table caption is inserted in a separate paragraph after the table opening onto the VE surface, but on the CodeMirror surface, it is displayed on the same line as the table opening. Not yet sure why this happens.

I can reproduce the same issue in Chromium, so this isn't Firefox specific. The highlight can be fixed by disabling CodeMirror and enabling it again, so it must be something weird that only happens during insertion.

Schnark renamed this task from Firefox: Inserting a table breaks CodeMirror highlighting in NWE to Inserting a table breaks CodeMirror highlighting in NWE.Jan 25 2020, 9:08 AM

Looks like the source of this bug is the code changed here: https://gerrit.wikimedia.org/r/c/VisualEditor/VisualEditor/+/458490/8/src/dm/ve.dm.SourceConverter.js#82

The bug happens when we try to convert VisualEditor's data like "{type: 'paragraph'}|+ Caption {type: '/paragraph'}" to plain text expected by CodeMirror, and the result is just "|+ Caption" instead of "|+ Caption \n".

I think we just need to undo that, or in other words, add a newline at the end when converting full paragraphs.

Looks like the source of this bug is the code changed here: https://gerrit.wikimedia.org/r/c/VisualEditor/VisualEditor/+/458490/8/src/dm/ve.dm.SourceConverter.js#82

The bug happens when we try to convert VisualEditor's data like "{type: 'paragraph'}|+ Caption {type: '/paragraph'}" to plain text expected by CodeMirror, and the result is just "|+ Caption" instead of "|+ Caption \n".

I think we just need to undo that, or in other words, add a newline at the end when converting full paragraphs.

Thanks for the quick investigation! 🙂

Does it mean that ve.dm.SourceConverter.getSourceTextFromDataRange should always append a trailing newline to each full paragraph, even if it is followed by an internalList node? From what I see, the table insertion command in NWE ends up calling ve.dm.SourceSurfaceFragment.insertContent via ve.dm.MWWikitextSurfaceFragment.wrapText with the raw "before" parameter from the table insertion command—so the content to insert would contain no internalList nodes. However, if another call was to call insertContent with formatted text, the method would create a document from it to insert, with a trailing internalList node. So I was wondering whether we should append a trailing newline after the last paragraph only if it is truly the last content item, or also if it is followed by an internalList node.

Change 567483 had a related patch set uploaded (by TK-999; owner: TK-999):
[VisualEditor/VisualEditor@master] ve.dm.SourceConverter: Add a trailing newline to each full paragraph

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

Change 567483 merged by jenkins-bot:
[VisualEditor/VisualEditor@master] ve.dm.SourceConverter: Add a trailing newline to each full paragraph

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

matmarex removed a project: Patch-For-Review.

Change 569296 had a related patch set uploaded (by Jforrester; owner: Jforrester):
[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (62458b89d)

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

Change 569296 merged by jenkins-bot:
[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (62458b89d)

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

Restricted Application added a project: VisualEditor. · View Herald TranscriptFeb 4 2020, 11:14 PM
matmarex moved this task from To Triage to Triaged on the VisualEditor board.Feb 12 2020, 5:21 PM
JTannerWMF removed a project: Editing QA.
JTannerWMF added a subscriber: JTannerWMF.

@TK-999 are you still experiencing this?

If we don't hear back in about a week we will assume this is resolved.

JTannerWMF closed this task as Resolved.Oct 28 2020, 5:42 PM
JTannerWMF claimed this task.
Restricted Application added a project: User-Ryasmeen. · View Herald TranscriptOct 28 2020, 5:42 PM