Page MenuHomePhabricator

2017 wikitext editor adds an extra newline when using textSelection( 'setContents', ... )
Open, Needs TriagePublic

Description

The 2017 wikitext editor implements the jquery.textSelection API so it can be transparently substituted in for WikiEditor.

  1. Launch the 2017 editor
  2. Run this in the console: $( '#wpTextbox1' ).textSelection( 'setContents', 'a')

The output should be a single line of text saying a

Instead, it outputs two lines, an a followed by a newline.

Ideally, textSelection('setContents') should result in textSelection('getContents') returning the exact original input.

Event Timeline

Issue appears to be that this is what setContents does:

surface.getModel().getLinearFragment( new ve.Range( 0 ), true ).expandLinearSelection( 'root' ).insertContent( content );

When insertContent runs, it first removes the entire root range of the document. The transaction this generates replaces the entire contents with [{paragraph}, {/paragraph}] (and doesn't touch the empty internallist), I presume because it doesn't want an empty document to exist. It then proceeds on to insert the new content at the start of the document... leaving that empty-paragraph there to get bumped to the end.

Fun extra discovery: trying to setContents something that starts with a newline completely breaks. ($( '#wpTextbox1' ).textSelection( 'setContents', '\nFoo').) It tries to close the root node, apparently.

Change #1317768 had a related patch set uploaded (by DLynch; author: DLynch):

[VisualEditor/VisualEditor@master] dm.SurfaceFragment: don't leave an empty paragraph after replacing all content

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

Change #1317768 merged by jenkins-bot:

[VisualEditor/VisualEditor@master] dm.SurfaceFragment: don't leave an empty paragraph after replacing all content

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

Change #1318299 had a related patch set uploaded (by DLynch; author: DLynch):

[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (59c920b33)

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

Change #1318299 merged by jenkins-bot:

[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (59c920b33)

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

Change #1318310 had a related patch set uploaded (by DLynch; author: DLynch):

[mediawiki/extensions/CodeMirror@master] selenium: drop trailing newline from VE setContents expectations

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

Change #1318310 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] selenium: drop trailing newline from VE setContents expectations

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