Merge "Never use original data optimisation when in clipboard mode"

This commit is contained in:
jenkins-bot 2015-07-10 19:49:41 +00:00 committed by Gerrit Code Review
commit b4cef1cf01
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' },