jenkins-bot has submitted this change and it was merged.

Change subject: Fix whitespace consistency checking when child has no 
whitespace property
......................................................................


Fix whitespace consistency checking when child has no whitespace property

Our whitespace consistency checks never check innerPre, because
we assume it was already checked when the first child's outerPre
was processed, and then code then clears innerPre. So if innerPre survives,
we assume that must be because there was no children. This is almost
true, but if the first child didn't have any whitespace data at all,
the code path that cleared it was never taken. In this case, make
sure to clear it as well.

EXCEPT if we're doing this from a content node, those never have
whitespace recorded on them. Of course. Sigh.

Change-Id: I8ad147f174040b7f9223c57ac8583c22e172a3d7
---
M src/dm/ve.dm.Converter.js
M tests/dm/ve.dm.example.js
2 files changed, 21 insertions(+), 3 deletions(-)

Approvals:
  Jforrester: Looks good to me, approved
  Esanders: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/dm/ve.dm.Converter.js b/src/dm/ve.dm.Converter.js
index 189447b..ea3ece6 100644
--- a/src/dm/ve.dm.Converter.js
+++ b/src/dm/ve.dm.Converter.js
@@ -1467,12 +1467,15 @@
                                }
                        } else {
                                // Create node from data
-                               if ( !this.metaItemFactory.lookup( data[i].type 
) ) {
+                               if ( this.metaItemFactory.lookup( data[i].type 
) ) {
+                                       isContentNode = 
canContainContentStack[canContainContentStack.length - 1];
+                               } else {
                                        canContainContentStack.push(
                                                // if the last item was true 
then this item must inherit it
                                                
canContainContentStack[canContainContentStack.length - 1] ||
                                                
this.nodeFactory.canNodeContainContent( data[i].type )
                                        );
+                                       isContentNode = 
this.nodeFactory.isNodeContent( data[i].type );
                                }
 
                                dataElementOrSlice = getDataElementOrSlice();
@@ -1522,7 +1525,7 @@
                                                                
parentDomElement.veInternal.whitespace
                                                        ) {
                                                                theirs = 
parentDomElement.veInternal.whitespace[1];
-                                                               // Clear after 
use so it's not used twice
+                                                               // Clear 
parent's innerPre so it's not used again
                                                                
parentDomElement.veInternal.whitespace[1] = undefined;
                                                        }
                                                        // else theirs=undefined
@@ -1536,6 +1539,17 @@
                                                                domElement
                                                        );
                                                }
+                                       } else if (
+                                               !isContentNode &&
+                                               !domElement.previousSibling &&
+                                               parentDomElement.veInternal &&
+                                               
parentDomElement.veInternal.whitespace
+                                       ) {
+                                               // The parent's innerPre should 
not be used, because it doesn't match
+                                               // outerPre (since we didn't 
have any whitespace set at all).
+                                               // Except if this is a content 
node, because content nodes
+                                               // don't have whitespace 
annotated on them *sigh*
+                                               
parentDomElement.veInternal.whitespace[1] = undefined;
                                        }
                                }
 
diff --git a/tests/dm/ve.dm.example.js b/tests/dm/ve.dm.example.js
index fa02c5e..94eed1f 100644
--- a/tests/dm/ve.dm.example.js
+++ b/tests/dm/ve.dm.example.js
@@ -2512,12 +2512,16 @@
                        'B',
                        { type: '/paragraph' },
                        { type: '/listItem' },
+                       { type: 'listItem', internal: { whitespace: [ 
undefined, ' ', '\n' ] } },
+                       { type: 'paragraph', internal: { generated: 'empty' } },
+                       { type: '/paragraph' },
+                       { type: '/listItem' },
                        { type: '/list' },
                        { type: 'internalList' },
                        { type: '/internalList' }
                ],
                innerWhitespace: [ '\t', '\n' ],
-               normalizedBody: '<ul><li><p>\tA\n</p>  <p>B</p></li></ul>'
+               normalizedBody: '<ul><li><p>\tA\n</p>  
<p>B</p></li><li></li></ul>'
        },
        'order of nested annotations is preserved': {
                body: '<p><b><u><i>Foo</i></u></b></p>',

-- 
To view, visit https://gerrit.wikimedia.org/r/179880
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I8ad147f174040b7f9223c57ac8583c22e172a3d7
Gerrit-PatchSet: 2
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to