jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/344801 )

Change subject: Replace instanceof ContentBranchNode with #canContainContent
......................................................................


Replace instanceof ContentBranchNode with #canContainContent

Change-Id: I3d3968c9017245247673e317b7ff48c064c97313
---
M src/ce/ve.ce.Surface.js
M src/dm/ve.dm.VisualDiff.js
M src/ui/elements/ve.ui.DiffElement.js
M src/ve.DiffTreeNode.js
4 files changed, 10 insertions(+), 11 deletions(-)

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



diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index e3fabf0..fabb2d0 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -2239,7 +2239,7 @@
                // (which wouldn't put the open and close tags in the clipboard 
to begin with).
                if (
                        pastedNodes.length === 1 &&
-                       pastedNodes[ 0 ].node instanceof ve.dm.ContentBranchNode
+                       pastedNodes[ 0 ].node.canContainContent()
                ) {
                        if ( contextRange.containsRange( pastedNodes[ 0 
].nodeRange ) ) {
                                contextRange = pastedNodes[ 0 ].nodeRange;
diff --git a/src/dm/ve.dm.VisualDiff.js b/src/dm/ve.dm.VisualDiff.js
index 353fa52..534faca 100644
--- a/src/dm/ve.dm.VisualDiff.js
+++ b/src/dm/ve.dm.VisualDiff.js
@@ -266,8 +266,7 @@
                        oldNode = oldDocChildTree.orderedNodes[ treeDiff[ i ][ 
0 ] ].node;
                        newNode = newDocChildTree.orderedNodes[ treeDiff[ i ][ 
1 ] ].node;
 
-                       if ( !( oldNode instanceof ve.dm.ContentBranchNode ) &&
-                               !( newNode instanceof ve.dm.ContentBranchNode ) 
) {
+                       if ( !oldNode.canContainContent() && 
!newNode.canContainContent() ) {
 
                                // There is no content change
                                diffInfo[ i ] = {
@@ -281,13 +280,13 @@
                                };
                                continue;
 
-                       } else if ( !( newNode instanceof 
ve.dm.ContentBranchNode ) ) {
+                       } else if ( !newNode.canContainContent() ) {
 
                                // Content was removed
                                diffInfo[ i ] = { replacement: true };
                                removeLength = oldNode.length;
 
-                       } else if ( !( oldNode instanceof 
ve.dm.ContentBranchNode ) ) {
+                       } else if ( !oldNode.canContainContent() ) {
 
                                // Content was inserted
                                diffInfo[ i ] = { replacement: true };
@@ -334,7 +333,7 @@
 
                        // Node was removed
                        oldNode = oldDocChildTree.orderedNodes[ treeDiff[ i ][ 
0 ] ];
-                       if ( oldNode.node instanceof ve.dm.ContentBranchNode ) {
+                       if ( oldNode.node.canContainContent() ) {
                                removeLength = oldNode.node.length;
                        }
 
@@ -342,7 +341,7 @@
 
                        // Node was inserted
                        newNode = newDocChildTree.orderedNodes[ treeDiff[ i ][ 
1 ] ];
-                       if ( newNode.node instanceof ve.dm.ContentBranchNode ) {
+                       if ( newNode.node.canContainContent() ) {
                                insertLength = newNode.node.length;
                        }
 
diff --git a/src/ui/elements/ve.ui.DiffElement.js 
b/src/ui/elements/ve.ui.DiffElement.js
index 379735a..cbd07d6 100644
--- a/src/ui/elements/ve.ui.DiffElement.js
+++ b/src/ui/elements/ve.ui.DiffElement.js
@@ -409,7 +409,7 @@
 
                node = oldNodes[ nodeIndex ];
 
-               if ( !( node.node instanceof ve.dm.ContentBranchNode ) ) {
+               if ( !node.node.canContainContent() ) {
 
                        // Record that the node has been removed, but don't 
display it, for now
                        // TODO: describe the change for the attribute diff
@@ -494,7 +494,7 @@
                // Add insert class
                nodeData[ nodeRangeStart ] = this.addAttributesToNode(
                        nodeData[ nodeRangeStart ], this.newDoc, {
-                               'data-diff-action': node.node instanceof 
ve.dm.ContentBranchNode ? 'insert' : 'structural-insert'
+                               'data-diff-action': 
node.node.canContainContent() ? 'insert' : 'structural-insert'
                        }
                );
        }
diff --git a/src/ve.DiffTreeNode.js b/src/ve.DiffTreeNode.js
index 1131159..964cef4 100644
--- a/src/ve.DiffTreeNode.js
+++ b/src/ve.DiffTreeNode.js
@@ -38,7 +38,7 @@
  * @return {boolean} The nodes are equal
  */
 ve.DiffTreeNode.prototype.isEqual = function ( otherNode ) {
-       if ( this.node instanceof ve.dm.ContentBranchNode && otherNode.node 
instanceof ve.dm.ContentBranchNode ) {
+       if ( this.node.canContainContent() && 
otherNode.node.canContainContent() ) {
                return JSON.stringify( this.doc.getData( 
this.node.getOuterRange() ) ) ===
                        JSON.stringify( otherNode.doc.getData( 
otherNode.node.getOuterRange() ) );
        } else {
@@ -53,7 +53,7 @@
  * @return {Array} Array of nodes the same type as the original node
  */
 ve.DiffTreeNode.prototype.getOriginalNodeChildren = function () {
-       if ( this.node.children && !( this.node instanceof 
ve.dm.ContentBranchNode ) ) {
+       if ( this.node.children && !this.node.canContainContent() ) {
                return this.node.children;
        }
        return [];

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3d3968c9017245247673e317b7ff48c064c97313
Gerrit-PatchSet: 2
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to