(bug 41947) Propagate change markers when unwrapping generated nodes

Editing the text of a list item results in a change marker on the
paragraph within that list item. However, that paragraph usually isn't
present in the HTML, so the converter unwraps it when converting back to
HTML, and the change markers are lost. Instead, transfer the change
markers to the <li>.

Change-Id: Id675075d19c08d69bc8e990174841dc393b749fc
This commit is contained in:
Trevor Parscal 2012-11-16 15:39:35 -08:00
parent 29a0c38e05
commit 2c8411eb62
2 changed files with 41 additions and 4 deletions

View file

@ -669,9 +669,9 @@ ve.dm.Converter.prototype.getDataFromDom = function ( domElement, annotations, d
* @returns {HTMLElement} Wrapper div containing the resulting HTML
*/
ve.dm.Converter.prototype.getDomFromData = function ( data ) {
var text, i, j, annotations, annotation, annotationElement, dataElement, arr,
var text, i, j, k, annotations, annotation, annotationElement, dataElement, arr,
wrapper, childDomElement, pre, ours, theirs, parentDomElement, startClosingAt,
isContentNode,
isContentNode, changed, parentChanged,
container = document.createElement( 'div' ),
domElement = container,
annotationStack = new ve.AnnotationSet();
@ -859,6 +859,27 @@ ve.dm.Converter.prototype.getDomFromData = function ( data ) {
domElement
);
}
// Transfer change markers
changed = domElement.getAttribute( 'data-ve-changed' );
if ( changed ) {
parentChanged = parentDomElement.getAttribute( 'data-ve-changed' );
if ( parentChanged ) {
changed = $.parseJSON( changed );
parentChanged = $.parseJSON( parentChanged );
for ( k in changed ) {
if ( k in parentChanged ) {
parentChanged[k] += changed[k];
} else {
parentChanged[k] = changed[k];
}
}
parentDomElement.setAttribute( 'data-ve-changed',
$.toJSON( parentChanged ) );
} else {
parentDomElement.setAttribute( 'data-ve-changed',
changed );
}
}
parentDomElement.removeChild( domElement );
}

View file

@ -1502,11 +1502,27 @@ ve.dm.example.domToDataCases = {
'B',
'a',
'r',
{ 'type': '/paragraph' }
{ 'type': '/paragraph' },
{ 'type': 'list', 'attributes': { 'style': 'bullet' } },
{ 'type': 'listItem' },
{
'type': 'paragraph',
'internal': {
'generated': 'wrapper',
'changed': { 'content': 1 }
}
},
'B',
'a',
'z',
{ 'type': '/paragraph' },
{ 'type': '/listItem' },
{ 'type': '/list' }
],
'normalizedHtml': '<p data-ve-changed="{&quot;content&quot;:1}">' +
'Foo<img data-ve-changed="{&quot;attributes&quot;:2}" />' +
'</p><p data-ve-changed="{&quot;created&quot;:1}">Bar</p>'
'</p><p data-ve-changed="{&quot;created&quot;:1}">Bar</p>' +
'<ul><li data-ve-changed="{&quot;content&quot;:1}">Baz</li></ul>'
},
'about grouping': {
'html': '<div typeof="mw:Placeholder" about="#mwt1">Foo</div>' +