mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 06:24:08 +00:00
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:
parent
d69efc426d
commit
aeedd808cd
|
@ -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
|
||||
|
|
|
@ -1227,6 +1227,43 @@ ve.dm.mwExample.domToDataCases = {
|
|||
'"attrs":{"group":"g1","name":"foo"}}\\">' +
|
||||
'</span>"}}">' +
|
||||
'</div>',
|
||||
clipboardBody:
|
||||
'<p>Foo' +
|
||||
'<span typeof="mw:Extension/ref" data-mw="{"name":"ref","attrs":{"name":"bar"}}">' +
|
||||
'<sup>[1]</sup>' +
|
||||
'</span>' +
|
||||
' Baz' +
|
||||
'<span typeof="mw:Extension/ref" data-mw="{"name":"ref","body":{"html":"Quux"},"attrs":{"group":"g1","name":":0"}}">' +
|
||||
'<sup>[g1 1]</sup>' +
|
||||
'</span>' +
|
||||
' Whee' +
|
||||
'<span typeof="mw:Extension/ref" data-mw="{"name":"ref","body":{"html":"' +
|
||||
'<a href=\\"./Bar\\" rel=\\"mw:WikiLink\\">Bar' +
|
||||
'</a>"},"attrs":{"name":"bar"}}">' +
|
||||
'<sup>[1]</sup>' +
|
||||
'</span>' +
|
||||
' Yay' +
|
||||
// This reference has .body.id instead of .body.html
|
||||
'<span typeof="mw:Extension/ref" data-mw="{"name":"ref","body":{"id":"mw-cite-3","html":"No name"},"attrs":{"group":"g1"}}">' +
|
||||
'<sup>[g1 2]</sup>' +
|
||||
'</span>' +
|
||||
' Quux' +
|
||||
'<span typeof="mw:Extension/ref" data-mw="{"name":"ref","body":{"html":"Different content"},"attrs":{"name":"bar"}}">' +
|
||||
'<sup>[1]</sup>' +
|
||||
'</span>' +
|
||||
' Foo' +
|
||||
'<span typeof="mw:Extension/ref" data-mw="{"name":"ref","attrs":{"group":"g1","name":"foo"}}">' +
|
||||
'<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="{"name":"references","attrs":{"group":"g1"},"body":{' +
|
||||
'"html":"<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;},&quot;body&quot;:{&quot;html&quot;:&quot;Ref in refs&quot;}}' +
|
||||
'\\"><sup>[g1 3]</sup></span>"}}">' +
|
||||
'</div>',
|
||||
head: '<base href="http://example.com" />',
|
||||
data: [
|
||||
{ type: 'paragraph' },
|
||||
|
|
Loading…
Reference in a new issue