[MediaWiki-commits] [Gerrit] VisualEditor/VisualEditor[master]: Converter: Remove internal during the main loop

2016-11-07 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Converter: Remove internal during the main loop
..


Converter: Remove internal during the main loop

It was placed in a separate loop so as not to affect whitespace
calculations at the end of the document, so fix that calculation
to include the next node being the internal list.

Also assume the internalList is the last thing in the document.
We were over cautious about this when IL was introduced, but we
make this assumption is so many other places.

Change-Id: Ice6b16722b234b63548be72a8e1017ef24d3cc8f
---
M src/dm/ve.dm.Converter.js
1 file changed, 7 insertions(+), 31 deletions(-)

Approvals:
  Catrope: 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 23acaa7..a94ad72 100644
--- a/src/dm/ve.dm.Converter.js
+++ b/src/dm/ve.dm.Converter.js
@@ -1210,35 +1210,6 @@
return dataSlice;
}
 
-   function removeInternalNodes() {
-   var dataCopy, endOffset;
-   // See if there is an internalList in the data, and if there is 
one, remove it
-   // Removing it here prevents unwanted interactions with 
whitespace preservation
-   for ( i = 0; i < dataLen; i++ ) {
-   if (
-   data[ i ].type && data[ i ].type.charAt( 0 ) 
!== '/' &&
-   ve.dm.nodeFactory.lookup( data[ i ].type ) &&
-   ve.dm.nodeFactory.isNodeInternal( data[ i 
].type )
-   ) {
-   // Copy data if we haven't already done so
-   if ( !dataCopy ) {
-   dataCopy = data.slice();
-   }
-   endOffset = findEndOfNode( i );
-   // Remove this node's data from dataCopy
-   dataCopy.splice( i - ( dataLen - 
dataCopy.length ), endOffset - i );
-   // Move i such that it will be at endOffset in 
the next iteration
-   i = endOffset - 1;
-   }
-   }
-   if ( dataCopy ) {
-   data = dataCopy;
-   dataLen = data.length;
-   }
-   }
-
-   removeInternalNodes();
-
for ( i = 0; i < dataLen; i++ ) {
if ( typeof data[ i ] === 'string' ) {
// Text
@@ -1431,8 +1402,10 @@
if ( 
domElement.childNodes.length === 0 && (
// then 
check that we are the last child
// 
before unwrapping (and therefore destroying)
-   i === 
data.length - 1 ||
-   data[ i 
+ 1 ].type.charAt( 0 ) === '/'
+   data[ i 
+ 1 ] === undefined ||
+   data[ i 
+ 1 ].type.charAt( 0 ) === '/' ||
+   // 
Document ends when we encounter the internal list
+   ( data[ 
i + 1 ].type && this.nodeFactory.isNodeInternal( data[ i + 1 ].type ) )
)
) {
doUnwrap = true;
@@ -1491,6 +1464,9 @@
// Create node from data
if ( this.metaItemFactory.lookup( data[ i 
].type ) ) {
isContentNode = canContainContentStack[ 
canContainContentStack.length - 1 ];
+   } else if ( this.nodeFactory.isNodeInternal( 
data[ i ].type ) ) {
+   // Reached the internal list, finish
+   break;
} else {
canContainContentStack.push(
// if the last item was true 
then this item must inherit it

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ice6b16722b234b63548be72a8e1017ef24d3cc8f
Gerrit-PatchSet: 5
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders 
Gerrit-Reviewer: Catrope 
Gerrit-Revi

[MediaWiki-commits] [Gerrit] VisualEditor/VisualEditor[master]: Converter: Remove internal during the main loop

2016-11-05 Thread Esanders (Code Review)
Esanders has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/320005

Change subject: Converter: Remove internal during the main loop
..

Converter: Remove internal during the main loop

It was placed in a separate loop so as not to affect whitespace
calculations at the end of the document, so fix that calculation
to include the next node being the internal list.

Change-Id: Ice6b16722b234b63548be72a8e1017ef24d3cc8f
---
M src/dm/ve.dm.Converter.js
1 file changed, 8 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/05/320005/1

diff --git a/src/dm/ve.dm.Converter.js b/src/dm/ve.dm.Converter.js
index 23acaa7..4247753 100644
--- a/src/dm/ve.dm.Converter.js
+++ b/src/dm/ve.dm.Converter.js
@@ -1210,35 +1210,6 @@
return dataSlice;
}
 
-   function removeInternalNodes() {
-   var dataCopy, endOffset;
-   // See if there is an internalList in the data, and if there is 
one, remove it
-   // Removing it here prevents unwanted interactions with 
whitespace preservation
-   for ( i = 0; i < dataLen; i++ ) {
-   if (
-   data[ i ].type && data[ i ].type.charAt( 0 ) 
!== '/' &&
-   ve.dm.nodeFactory.lookup( data[ i ].type ) &&
-   ve.dm.nodeFactory.isNodeInternal( data[ i 
].type )
-   ) {
-   // Copy data if we haven't already done so
-   if ( !dataCopy ) {
-   dataCopy = data.slice();
-   }
-   endOffset = findEndOfNode( i );
-   // Remove this node's data from dataCopy
-   dataCopy.splice( i - ( dataLen - 
dataCopy.length ), endOffset - i );
-   // Move i such that it will be at endOffset in 
the next iteration
-   i = endOffset - 1;
-   }
-   }
-   if ( dataCopy ) {
-   data = dataCopy;
-   dataLen = data.length;
-   }
-   }
-
-   removeInternalNodes();
-
for ( i = 0; i < dataLen; i++ ) {
if ( typeof data[ i ] === 'string' ) {
// Text
@@ -1431,8 +1402,10 @@
if ( 
domElement.childNodes.length === 0 && (
// then 
check that we are the last child
// 
before unwrapping (and therefore destroying)
-   i === 
data.length - 1 ||
-   data[ i 
+ 1 ].type.charAt( 0 ) === '/'
+   data[ i 
+ 1 ].type.charAt( 0 ) === '/' ||
+   data[ i 
+ 1 ] === undefined ||
+   // 
Document ends when we encounter the internal list
+   ( data[ 
i + 1 ].type && this.nodeFactory.isNodeInternal( data[ i + 1 ].type ) )
)
) {
doUnwrap = true;
@@ -1491,6 +1464,10 @@
// Create node from data
if ( this.metaItemFactory.lookup( data[ i 
].type ) ) {
isContentNode = canContainContentStack[ 
canContainContentStack.length - 1 ];
+   } else if ( this.nodeFactory.isNodeInternal( 
data[ i ].type ) ) {
+   // Skip over the internal list
+   i = findEndOfNode( i ) - 1;
+   continue;
} else {
canContainContentStack.push(
// if the last item was true 
then this item must inherit it

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ice6b16722b234b63548be72a8e1017ef24d3cc8f
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders 

___
MediaWiki-commits mailing list
MediaWiki-c