Esanders has uploaded a new change for review.

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

Change subject: Only show unchanged content adjacent to changed content
......................................................................

Only show unchanged content adjacent to changed content

Bug: T149524
Change-Id: I39b2f35f159fe81a2ea92af7fd0de8ebb59d055f
---
M src/ui/dialogs/ve.ui.DiffDialog.js
M src/ui/elements/ve.ui.DiffElement.js
M src/ui/styles/elements/ve.ui.DiffElement.css
3 files changed, 46 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/06/322706/1

diff --git a/src/ui/dialogs/ve.ui.DiffDialog.js 
b/src/ui/dialogs/ve.ui.DiffDialog.js
index d1da2a4..65daa89 100644
--- a/src/ui/dialogs/ve.ui.DiffDialog.js
+++ b/src/ui/dialogs/ve.ui.DiffDialog.js
@@ -45,7 +45,7 @@
 
        this.content = new OO.ui.PanelLayout( {
                padded: true,
-               expanded: true
+               expanded: false
        } );
 
        this.$body.append( this.content.$element );
diff --git a/src/ui/elements/ve.ui.DiffElement.js 
b/src/ui/elements/ve.ui.DiffElement.js
index d7afc01..66a56de 100644
--- a/src/ui/elements/ve.ui.DiffElement.js
+++ b/src/ui/elements/ve.ui.DiffElement.js
@@ -57,7 +57,10 @@
  */
 ve.ui.DiffElement.prototype.getDiffHtml = function () {
        var i, j, k, ilen, jlen, klen, nodes, move,
-               diffHtml = [];
+               anyChanges = false,
+               spacer = false,
+               diffHtml = [],
+               diffQueue = [];
 
        ilen = Math.max( this.oldDocChildren.length, this.newDocChildren.length 
);
        jlen = ilen;
@@ -68,7 +71,7 @@
                        // Everything else in the new doc is an insert
                        nodes = this.newDocChildren.slice( j );
                        for ( k = 0, klen = nodes.length; k < klen; k++ ) {
-                               diffHtml.push( this.getNodeHtml( nodes[ k ], 
'insert' ) );
+                               diffQueue.push( [ 'getNodeHtml', nodes[ k ], 
'insert' ] );
                        }
 
                } else if ( this.newDocChildren[ j ] === undefined ) {
@@ -76,30 +79,30 @@
                        // Everything else in the old doc is a remove
                        nodes = this.oldDocChildren.slice( i );
                        for ( k = 0, klen = nodes.length; k < klen; k++ ) {
-                               diffHtml.push( this.getNodeHtml( nodes[ k ], 
'remove' ) );
+                               diffQueue.push( [ 'getNodeHtml', nodes[ k ], 
'remove' ] );
                        }
 
                } else if ( this.remove.indexOf( i ) !== -1 ) {
 
                        // The old node is a remove. Decrement the new node 
index
                        // to compare the same new node to the next old node
-                       diffHtml.push( this.getNodeHtml( this.oldDocChildren[ i 
], 'remove' ) );
+                       diffQueue.push( [ 'getNodeHtml', this.oldDocChildren[ i 
], 'remove' ] );
                        j--;
 
                } else if ( this.insert.indexOf( j ) !== -1 ) {
 
                        // The new node is an insert. Decrement the old node 
index
                        // to compare the same old node to the next new node
-                       diffHtml.push( this.getNodeHtml( this.newDocChildren[ j 
], 'insert' ) );
+                       diffQueue.push( [ 'getNodeHtml', this.newDocChildren[ j 
], 'insert' ] );
                        i--;
 
-               } else if ( typeof ( this.newToOld[ j ] ) === 'number' ) {
+               } else if ( typeof this.newToOld[ j ] === 'number' ) {
 
                        // The old and new node are exactly the same, but still
                        // need to check if there has been a move
                        move = this.newToOld[ j ] === i ? undefined :
                                ( this.newToOld[ j ] > i ? 'up' : 'down' );
-                       diffHtml.push( this.getNodeHtml( this.newDocChildren[ j 
], 'none', move ) );
+                       diffQueue.push( [ 'getNodeHtml', this.newDocChildren[ j 
], 'none', move ] );
 
                } else {
 
@@ -107,12 +110,34 @@
                        // diff and also check if there has been a move
                        move = this.newToOld[ j ].node === i ? undefined :
                                ( this.newToOld[ j ].node > i ? 'up' : 'down' );
-                       diffHtml.push( this.getChangedNodeHtml( this.newToOld[ 
j ].node, move ) );
+                       diffQueue.push( [ 'getChangedNodeHtml', this.newToOld[ 
j ].node, move ] );
 
                }
        }
 
-       return diffHtml;
+       function isNoOp( item ) {
+               return !item || ( item[ 2 ] === 'none' && !item[ 3 ] );
+       }
+
+       for ( i = 0, ilen = diffQueue.length; i < ilen; i++ ) {
+               if ( !isNoOp( diffQueue[ i - 1 ] ) || !isNoOp( diffQueue[ i ] ) 
|| !isNoOp( diffQueue[ i + 1 ] ) ) {
+                       spacer = false;
+                       anyChanges = true;
+                       diffHtml.push(
+                               this[ diffQueue[ i ][ 0 ] ].apply( this, 
diffQueue[ i ].slice( 1 ) )
+                       );
+               } else if ( !spacer ) {
+                       spacer = true;
+                       diffHtml.push( $( '<div 
class="ve-ui-diffElement-spacer">' ).text( '⋮' ) );
+               }
+       }
+
+       if ( !anyChanges ) {
+               return [ $( '<div class="ve-ui-diffElement-no-changes">' 
).text( 'No changes' ) ];
+       } else {
+               return diffHtml;
+       }
+
 };
 
 /**
diff --git a/src/ui/styles/elements/ve.ui.DiffElement.css 
b/src/ui/styles/elements/ve.ui.DiffElement.css
index 4a5ecef..0919636 100644
--- a/src/ui/styles/elements/ve.ui.DiffElement.css
+++ b/src/ui/styles/elements/ve.ui.DiffElement.css
@@ -18,7 +18,7 @@
 }
 
 .ve-ui-diffElement-none {
-       opacity: 0.5;
+       opacity: 0.4;
 }
 
 .ve-ui-diffElement-doc-child-change {
@@ -47,3 +47,13 @@
 .ve-ui-diffElement-down *:empty:before {
        content: url( 
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 
);
 }
+
+.ve-ui-diffElement-no-changes {
+       color: #888;
+       font-style: italic;
+}
+
+.ve-ui-diffElement-spacer {
+       color: #888;
+       text-align: center;
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I39b2f35f159fe81a2ea92af7fd0de8ebb59d055f
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>

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

Reply via email to