Tchanders has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/364326 )

Change subject: VisualDiff: Use <del> and <ins> on whole paragraphs
......................................................................

VisualDiff: Use <del> and <ins> on whole paragraphs

When a whole child node of the document node is deleted
or inserted, wrap the content in <del> or <ins> tags.

Bug: T170136
Change-Id: I106ba0ea3122d4b28e7008e5108c046df05c184e
---
M src/ui/elements/ve.ui.DiffElement.js
M src/ui/styles/elements/ve.ui.DiffElement.css
M tests/ui/ve.ui.DiffElement.test.js
3 files changed, 28 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/26/364326/1

diff --git a/src/ui/elements/ve.ui.DiffElement.js 
b/src/ui/elements/ve.ui.DiffElement.js
index b13f6fc..2550f15 100644
--- a/src/ui/elements/ve.ui.DiffElement.js
+++ b/src/ui/elements/ve.ui.DiffElement.js
@@ -375,7 +375,7 @@
  * @return {HTMLElement[]} Elements (not owned by window.document)
  */
 ve.ui.DiffElement.prototype.getNodeElements = function ( node, action, move ) {
-       var nodeData, doc, body, element,
+       var nodeData, doc, body, element, annIndex, annType,
                nodeDoc = action === 'remove' ? this.oldDoc : this.newDoc,
                documentSlice = nodeDoc.cloneFromRange( node.getOuterRange() );
 
@@ -385,9 +385,23 @@
        // Add the classes to the outer element (in case there was a move)
        nodeData[ 0 ] = this.addAttributesToNode( nodeData[ 0 ], nodeDoc, { 
'data-diff-action': action, 'data-diff-move': move } );
 
+       if ( action !== 'none' ) {
+               annType = action === 'remove' ? 'textStyle/delete' : 
'textStyle/insert';
+               annIndex = documentSlice.getStore().index(
+                       ve.dm.annotationFactory.create( annType, {
+                               type: annType
+                       } )
+               );
+               ve.dm.Document.static.addAnnotationsToData(
+                       nodeData,
+                       new ve.dm.AnnotationSet( documentSlice.getStore(), [ 
annIndex ] )
+               );
+       }
+
        // Get the html for the linear model with classes
        // Doc is always the new doc when inserting into the store
        documentSlice.getStore().merge( this.newDoc.getStore() );
+
        // forClipboard is true, so that we can render otherwise invisible nodes
        doc = ve.dm.converter.getDomFromModel( documentSlice, true );
        body = doc.body;
diff --git a/src/ui/styles/elements/ve.ui.DiffElement.css 
b/src/ui/styles/elements/ve.ui.DiffElement.css
index 274d6eb..55bbfbc 100644
--- a/src/ui/styles/elements/ve.ui.DiffElement.css
+++ b/src/ui/styles/elements/ve.ui.DiffElement.css
@@ -64,6 +64,7 @@
 }
 
 [data-diff-action='insert'],
+[data-diff-action='insert'] > ins,
 [data-diff-action='remove'],
 [data-diff-action='change-insert'],
 [data-diff-action='change-remove'] {
@@ -96,13 +97,19 @@
        display: none;
 }
 
-del[data-diff-action='remove'] {
+del[data-diff-action='remove'],
+[data-diff-action='remove'] > del {
        text-decoration: line-through;
 }
 del[data-diff-action='remove']:hover {
        text-decoration: none;
 }
 
+del[data-diff-action='remove']:hover,
+[data-diff-action='remove']:hover > del {
+       text-decoration: none;
+}
+
 [data-diff-action='insert'] [rel='ve:Comment'],
 [data-diff-action='remove'] [rel='ve:Comment'],
 [data-diff-action='change-insert'] [rel='ve:Comment'],
diff --git a/tests/ui/ve.ui.DiffElement.test.js 
b/tests/ui/ve.ui.DiffElement.test.js
index 676e869..e88e64f 100644
--- a/tests/ui/ve.ui.DiffElement.test.js
+++ b/tests/ui/ve.ui.DiffElement.test.js
@@ -120,10 +120,10 @@
                                newDoc: '<p>boo</p><p>bar</p><p>baz</p>',
                                expected:
                                        '<div 
class="ve-ui-diffElement-doc-child-change">' +
-                                               '<p 
data-diff-action="remove">foo</p>' +
+                                               '<p 
data-diff-action="remove"><del>foo</del></p>' +
                                        '</div>' +
                                        '<div 
class="ve-ui-diffElement-doc-child-change">' +
-                                               '<p 
data-diff-action="insert">boo</p>' +
+                                               '<p 
data-diff-action="insert"><ins>boo</ins></p>' +
                                        '</div>' +
                                        '<p data-diff-action="none">bar</p>' +
                                        spacer
@@ -134,10 +134,10 @@
                                newDoc: 'boo',
                                expected:
                                        '<div 
class="ve-ui-diffElement-doc-child-change">' +
-                                               '<p 
data-diff-action="remove">foo</p>' +
+                                               '<p 
data-diff-action="remove"><del>foo</del></p>' +
                                        '</div>' +
                                        '<div 
class="ve-ui-diffElement-doc-child-change">' +
-                                               '<p 
data-diff-action="insert">boo</p>' +
+                                               '<p 
data-diff-action="insert"><ins>boo</ins></p>' +
                                        '</div>'
                        },
                        {
@@ -187,7 +187,7 @@
                                                '<div rel="ve:Alien" 
data-diff-action="remove">Alien</div>' +
                                        '</div>' +
                                        '<div 
class="ve-ui-diffElement-doc-child-change">' +
-                                               '<p 
data-diff-action="insert">Foo</p>' +
+                                               '<p 
data-diff-action="insert"><ins>Foo</ins></p>' +
                                        '</div>'
                        },
                        {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I106ba0ea3122d4b28e7008e5108c046df05c184e
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Tchanders <[email protected]>

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

Reply via email to