Catrope has uploaded a new change for review.
https://gerrit.wikimedia.org/r/70230
Change subject: Preserve the <a> inside of a reference <span>
......................................................................
Preserve the <a> inside of a reference <span>
This was a big gaping DOM diff that's been in there since the beginning,
but which we only found today.
Change-Id: Ie4e791b212ddd3210bc1d5c11308452bb57ae3ce
---
M modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
M modules/ve/test/dm/ve.dm.example.js
2 files changed, 17 insertions(+), 31 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/30/70230/1
diff --git a/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
b/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
index 37c6589..53f9fa8 100644
--- a/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
+++ b/modules/ve/dm/nodes/ve.dm.MWReferenceNode.js
@@ -57,6 +57,7 @@
'attributes': {
'mw': mwData,
'originalMw': mwDataJSON,
+ 'childDomElements': ve.copyArray(
Array.prototype.slice.apply( domElements[0].childNodes ) ),
'about': about,
'listIndex': listIndex,
'listGroup': listGroup,
@@ -69,7 +70,7 @@
};
ve.dm.MWReferenceNode.static.toDomElements = function ( dataElement, doc,
converter ) {
- var itemNodeHtml, mwData, i, iLen, keyedNodes, setContents, originalMw,
+ var itemNodeHtml, mwData, i, iLen, keyedNodes, setContents, originalMw,
childDomElements,
el = doc.createElement( 'span' ),
itemNodeWrapper = doc.createElement( 'div' ),
itemNode = converter.internalList.getItemNode(
dataElement.attributes.listIndex ),
@@ -134,6 +135,12 @@
el.setAttribute( 'data-mw', JSON.stringify( mwData ) );
}
+ // Restore the span's childNodes to prevent unnecessary DOM diffs
+ childDomElements = ve.copyDomElements(
dataElement.attributes.childDomElements, doc );
+ for ( i = 0, iLen = childDomElements.length; i < iLen; i++ ) {
+ el.appendChild( childDomElements[i] );
+ }
+
return [ el ];
};
diff --git a/modules/ve/test/dm/ve.dm.example.js
b/modules/ve/test/dm/ve.dm.example.js
index bcb1336..4988364 100644
--- a/modules/ve/test/dm/ve.dm.example.js
+++ b/modules/ve/test/dm/ve.dm.example.js
@@ -1279,6 +1279,7 @@
'refGroup': '',
'mw': { 'body': { 'html': '' },
'attrs': { 'name': 'bar' } },
'originalMw':
'{"body":{"html":""},"attrs":{"name":"bar"}}',
+ 'childDomElements': $( '<a
href="#cite_note-bar-1" data-parsoid="{}">[1]</a>' ).toArray(),
'contentsUsed': false
},
'htmlAttributes': [
@@ -1314,6 +1315,7 @@
'refGroup': '',
'mw': { 'body': { 'html': 'Quux' },
'attrs': { 'name': 'quux' } },
'originalMw':
'{"body":{"html":"Quux"},"attrs":{"name":"quux"}}',
+ 'childDomElements': $( '<a
href="#cite_note-quux-2" data-parsoid="{}">[2]</a>' ).toArray(),
'contentsUsed': true
},
'htmlAttributes': [
@@ -1349,6 +1351,7 @@
'refGroup': '',
'mw': { 'body': { 'html': 'Bar' },
'attrs': { 'name': 'bar' } },
'originalMw':
'{"body":{"html":"Bar"},"attrs":{"name":"bar"}}',
+ 'childDomElements': $( '<a
href="#cite_note-bar-1" data-parsoid="{}">[1]</a>' ).toArray(),
'contentsUsed': true
},
'htmlAttributes': [
@@ -1384,6 +1387,7 @@
'refGroup': 'g1',
'mw': { 'body': { 'html': 'No name' },
'attrs': { 'group': 'g1' } },
'originalMw': '{"body":{"html":"No
name"},"attrs":{"group":"g1"}}',
+ 'childDomElements': $( '<a
href="#cite_note-3" data-parsoid="{}">[3]</a>' ).toArray(),
'contentsUsed': true
},
'htmlAttributes': [
@@ -1446,41 +1450,14 @@
{ 'type': '/paragraph' },
{ 'type': '/internalItem' },
{ 'type': '/internalList' }
- ],
- 'normalizedHtml':
- '<p>Foo' +
- '<span id="cite_ref-bar-1-0" class="reference"
about="#mwt5" typeof="mw:Extension/ref" ' +
- 'data-parsoid="{}" ' +
-
'data-mw="{"body":{"html":""},"attrs":{"name":"bar"}}">'
+
- '</span>' +
- ' Baz' +
- '<span id="cite_ref-quux-2-0" class="reference"
about="#mwt6" typeof="mw:Extension/ref" ' +
- 'data-parsoid="{}" ' +
-
'data-mw="{"body":{"html":"Quux"},"attrs":{"name":"quux"}}">'
+
- '</span>' +
- ' Whee' +
- '<span id="cite_ref-bar-1-1" class="reference"
about="#mwt7" typeof="mw:Extension/ref" ' +
- 'data-parsoid="{}" ' +
-
'data-mw="{"body":{"html":"Bar"},"attrs":{"name":"bar"}}">'
+
- '</span>' +
- ' Yay' +
- '<span id="cite_ref-3-0" class="reference"
about="#mwt8" typeof="mw:Extension/ref" ' +
- 'data-parsoid="{}" ' +
-
'data-mw="{"body":{"html":"No
name"},"attrs":{"group":"g1"}}">' +
- '</span>' +
- '</p>' +
- '<ol class="references" about="#mwt12"
typeof="mw:Extension/references" ' +
-
'data-mw="{"name":"references","attrs":{}}" ' +
- 'data-parsoid="{}">' +
- '<li id="cite_note-quux-2"><a
href="#cite_ref-quux-2-0">u2191</a>Quux</li>' +
- '</ol>'
+ ]
},
'mw:Reference with metadata': {
'html': '<p><span about="#mwt2" class="reference" ' +
'data-mw="{"name":"ref","body":' +
'{"html":"Foo<!-- bar
-->"},"attrs":{}}" ' +
'id="cite_ref-1-0" rel="dc:references"
typeof="mw:Extension/ref" data-parsoid="{}">' +
- '</span></p>',
+ '<a href="#cite_note-bar-1"
data-parsoid="{}">[1]</a></span></p>',
'data': [
{ 'type': 'paragraph' },
{
@@ -1499,6 +1476,7 @@
'name': 'ref'
},
'originalMw':
'{"name":"ref","body":{"html":"Foo<!-- bar -->"},"attrs":{}}',
+ 'childDomElements': $( '<a
href="#cite_note-bar-1" data-parsoid="{}">[1]</a>' ).toArray(),
'refGroup': ''
},
'htmlAttributes': [
@@ -1511,7 +1489,8 @@
'id': 'cite_ref-1-0',
'rel': 'dc:references',
'typeof':
'mw:Extension/ref'
- }
+ },
+ 'children': [ { 'values': {
'data-parsoid': '{}', 'href': '#cite_note-bar-1' } } ]
}
]
},
--
To view, visit https://gerrit.wikimedia.org/r/70230
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie4e791b212ddd3210bc1d5c11308452bb57ae3ce
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits