Never use original data optimisation when in clipboard mode

In clipboard mode we need the full body regardless of if the reference
has changed since load or not.

Bug: T104230
Change-Id: Ie59e04d381f2fd2680e8af0cf05a80df71052822
This commit is contained in:
Ed Sanders 2015-07-09 13:39:08 +01:00 committed by Catrope
parent d69efc426d
commit aeedd808cd
2 changed files with 44 additions and 4 deletions

View file

@ -102,6 +102,7 @@ ve.dm.MWReferenceNode.static.toDataElement = function ( domElements, converter )
ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc, converter ) {
var itemNodeHtml, originalHtml, mwData, i, iLen, keyedNodes, setContents, contentsAlreadySet,
originalMw, listKeyParts, name,
isForClipboard = converter.isForClipboard(),
el = doc.createElement( 'span' ),
itemNodeWrapper = doc.createElement( 'div' ),
originalHtmlWrapper = doc.createElement( 'div' ),
@ -162,8 +163,9 @@ ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc, conver
( ve.getProp( mwData, 'body', 'id' ) !== undefined && itemNode.getAttribute( 'originalHtml' ) ) ||
'';
originalHtmlWrapper.innerHTML = originalHtml;
// Only set body.html if itemNodeHtml and originalHtml are actually different
if ( !originalHtmlWrapper.isEqualNode( itemNodeWrapper ) ) {
// Only set body.html if itemNodeHtml and originalHtml are actually different,
// or we are writing the clipboard for use in another VE instance
if ( isForClipboard || !originalHtmlWrapper.isEqualNode( itemNodeWrapper ) ) {
ve.setProp( mwData, 'body', 'html', itemNodeHtml );
}
}
@ -199,10 +201,11 @@ ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc, conver
delete mwData.attrs.refGroup;
}
// If mwAttr and originalMw are the same, use originalMw to prevent reserialization.
// If mwAttr and originalMw are the same, use originalMw to prevent reserialization,
// unless we are writing the clipboard for use in another VE instance
// Reserialization has the potential to reorder keys and so change the DOM unnecessarily
originalMw = dataElement.attributes.originalMw;
if ( originalMw && ve.compare( mwData, JSON.parse( originalMw ) ) ) {
if ( !isForClipboard && originalMw && ve.compare( mwData, JSON.parse( originalMw ) ) ) {
el.setAttribute( 'data-mw', originalMw );
// Return the original DOM elements if possible

View file

@ -1227,6 +1227,43 @@ ve.dm.mwExample.domToDataCases = {
'"attrs":{"group":"g1","name":"foo"}}\\">' +
'</span>&quot;}}">' +
'</div>',
clipboardBody:
'<p>Foo' +
'<span typeof="mw:Extension/ref" data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;attrs&quot;:{&quot;name&quot;:&quot;bar&quot;}}">' +
'<sup>[1]</sup>' +
'</span>' +
' Baz' +
'<span typeof="mw:Extension/ref" data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;body&quot;:{&quot;html&quot;:&quot;Quux&quot;},&quot;attrs&quot;:{&quot;group&quot;:&quot;g1&quot;,&quot;name&quot;:&quot;:0&quot;}}">' +
'<sup>[g1 1]</sup>' +
'</span>' +
' Whee' +
'<span typeof="mw:Extension/ref" data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;body&quot;:{&quot;html&quot;:&quot;' +
'<a href=\\&quot;./Bar\\&quot; rel=\\&quot;mw:WikiLink\\&quot;>Bar' +
'</a>&quot;},&quot;attrs&quot;:{&quot;name&quot;:&quot;bar&quot;}}">' +
'<sup>[1]</sup>' +
'</span>' +
' Yay' +
// This reference has .body.id instead of .body.html
'<span typeof="mw:Extension/ref" data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;body&quot;:{&quot;id&quot;:&quot;mw-cite-3&quot;,&quot;html&quot;:&quot;No name&quot;},&quot;attrs&quot;:{&quot;group&quot;:&quot;g1&quot;}}">' +
'<sup>[g1 2]</sup>' +
'</span>' +
' Quux' +
'<span typeof="mw:Extension/ref" data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;body&quot;:{&quot;html&quot;:&quot;Different content&quot;},&quot;attrs&quot;:{&quot;name&quot;:&quot;bar&quot;}}">' +
'<sup>[1]</sup>' +
'</span>' +
' Foo' +
'<span typeof="mw:Extension/ref" data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;attrs&quot;:{&quot;group&quot;:&quot;g1&quot;,&quot;name&quot;:&quot;foo&quot;}}">' +
'<sup>[g1 3]</sup>' +
'</span>' +
'</p>' +
// The HTML below is enriched to wrap reference contents in <span id="mw-cite-[...]">
// which Parsoid doesn't do yet, but T88290 asks for
'<div typeof="mw:Extension/references"' +
'data-mw="{&quot;name&quot;:&quot;references&quot;,&quot;attrs&quot;:{&quot;group&quot;:&quot;g1&quot;},&quot;body&quot;:{' +
'&quot;html&quot;:&quot;<span typeof=\\&quot;mw:Extension/ref\\&quot; ' +
'data-mw=\\&quot;{&amp;quot;name&amp;quot;:&amp;quot;ref&amp;quot;,&amp;quot;attrs&amp;quot;:{&amp;quot;group&amp;quot;:&amp;quot;g1&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;foo&amp;quot;},&amp;quot;body&amp;quot;:{&amp;quot;html&amp;quot;:&amp;quot;Ref in refs&amp;quot;}}' +
'\\&quot;><sup>[g1 3]</sup></span>&quot;}}">' +
'</div>',
head: '<base href="http://example.com" />',
data: [
{ type: 'paragraph' },