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.

Screenshot 2020-01-24 at 16.56.13.png (1×1 px, 471 KB)

Event Timeline

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

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

JTannerWMF removed a project: Editing QA.
JTannerWMF subscribed.

@TK-999 are you still experiencing this?

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

JTannerWMF claimed this task.