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

Change subject: DiffElement: Ensure del/ins tags encapsulate annotation changes
......................................................................


DiffElement: Ensure del/ins tags encapsulate annotation changes

This is more semantically correct, and means that our 'del + ins'
CSS selectors still work.

Change-Id: I13fb38e4e9943be328ba6dc85c124e74de451acd
---
M src/ui/elements/ve.ui.DiffElement.js
M src/ve.utils.js
M tests/ui/ve.ui.DiffElement.test.js
3 files changed, 62 insertions(+), 15 deletions(-)

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



diff --git a/src/ui/elements/ve.ui.DiffElement.js 
b/src/ui/elements/ve.ui.DiffElement.js
index ed363cf..e06287e 100644
--- a/src/ui/elements/ve.ui.DiffElement.js
+++ b/src/ui/elements/ve.ui.DiffElement.js
@@ -699,13 +699,14 @@
  */
 ve.ui.DiffElement.prototype.annotateNode = function ( linearDiff ) {
        var i, ilen, range, type, typeAsString, annType, domElementType, 
changes, item,
+               annIndex, annIndexLists, j, height,
                DIFF_DELETE = ve.DiffMatchPatch.static.DIFF_DELETE,
                DIFF_INSERT = ve.DiffMatchPatch.static.DIFF_INSERT,
                DIFF_CHANGE_DELETE = 
ve.DiffMatchPatch.static.DIFF_CHANGE_DELETE,
                DIFF_CHANGE_INSERT = 
ve.DiffMatchPatch.static.DIFF_CHANGE_INSERT,
                items = [],
                start = 0, // The starting index for a range for building an 
annotation
-               end, transaction, annotatedLinearDiff,
+               end, annotatedLinearDiff,
                domElement, domElements, originalDomElementsIndex,
                diffDoc, diffDocData,
                diffElement = this;
@@ -776,17 +777,45 @@
                                        domElements,
                                        domElements.map( ve.getNodeHtml ).join( 
'' )
                                );
-                               transaction = 
ve.dm.TransactionBuilder.static.newFromAnnotation(
-                                       diffDoc, range, 'set',
-                                       ve.dm.annotationFactory.create(
-                                               annType,
-                                               {
-                                                       type: annType,
-                                                       
originalDomElementsIndex: originalDomElementsIndex
-                                               }
+                               annIndex = diffDoc.getStore().index(
+                                       ve.dm.annotationFactory.create( 
annType, {
+                                               type: annType,
+                                               originalDomElementsIndex: 
originalDomElementsIndex
+                                       } )
+                               );
+
+                               // Insert annotation above annotations that 
span the entire range
+                               // and at least one character more
+                               annIndexLists = [];
+                               for (
+                                       j = Math.max( 0, range.start - 1 );
+                                       j < Math.min( range.end + 1, 
diffDoc.data.getLength() );
+                                       j++
+                               ) {
+                                       annIndexLists[ j ] =
+                                               
diffDoc.data.getAnnotationIndexesFromOffset( j );
+                               }
+                               height = Math.min(
+                                       ve.getCommonStartSequenceLength(
+                                               annIndexLists.slice(
+                                                       Math.max( 0, 
range.start - 1 ),
+                                                       range.end
+                                               )
+                                       ),
+                                       ve.getCommonStartSequenceLength(
+                                               annIndexLists.slice(
+                                                       range.start,
+                                                       Math.min( range.end + 
1, diffDoc.data.getLength() )
+                                               )
                                        )
                                );
-                               diffDoc.commit( transaction );
+                               for ( j = range.start; j < range.end; j++ ) {
+                                       annIndexLists[ j ].splice( height, 0, 
annIndex );
+                                       
diffDoc.data.setAnnotationIndexesAtOffset(
+                                               j,
+                                               annIndexLists[ j ]
+                                       );
+                               }
                        }
                }
                start = end;
diff --git a/src/ve.utils.js b/src/ve.utils.js
index 00dc8a0..5967eb9 100644
--- a/src/ve.utils.js
+++ b/src/ve.utils.js
@@ -1400,7 +1400,7 @@
                val = sequences[ 0 ][ commonLength ];
                for ( i = 1, len = sequences.length; i < len; i++ ) {
                        if (
-                               sequences[ i ].length < commonLength ||
+                               sequences[ i ].length <= commonLength ||
                                sequences[ i ][ commonLength ] !== val
                        ) {
                                break commonLengthLoop;
diff --git a/tests/ui/ve.ui.DiffElement.test.js 
b/tests/ui/ve.ui.DiffElement.test.js
index 5bf89ac..287800f 100644
--- a/tests/ui/ve.ui.DiffElement.test.js
+++ b/tests/ui/ve.ui.DiffElement.test.js
@@ -268,7 +268,7 @@
                                newDoc: '<p>foo <b>bar</b> baz</p>',
                                expected:
                                        '<div 
class="ve-ui-diffElement-doc-child-change">' +
-                                               '<p>foo <del 
data-diff-action="remove">bar</del><b><ins 
data-diff-action="insert">bar</ins></b> baz</p>' +
+                                               '<p>foo <del 
data-diff-action="remove">bar</del><ins 
data-diff-action="insert"><b>bar</b></ins> baz</p>' +
                                        '</div>'
                        },
                        {
@@ -277,7 +277,25 @@
                                newDoc: '<p>foo bar baz</p>',
                                expected:
                                        '<div 
class="ve-ui-diffElement-doc-child-change">' +
-                                               '<p>foo <b><del 
data-diff-action="remove">bar</del></b><ins data-diff-action="insert">bar</ins> 
baz</p>' +
+                                               '<p>foo <del 
data-diff-action="remove"><b>bar</b></del><ins 
data-diff-action="insert">bar</ins> baz</p>' +
+                                       '</div>'
+                       },
+                       {
+                               msg: 'Annotation attribute change',
+                               oldDoc: '<p>foo <a href="quuz">bar</a> baz</p>',
+                               newDoc: '<p>foo <a href="whee">bar</a> baz</p>',
+                               expected:
+                                       '<div 
class="ve-ui-diffElement-doc-child-change">' +
+                                               '<p>foo <span 
data-diff-action="change-remove"><a href="quuz">bar</a></span><span 
data-diff-action="change-insert" data-diff-id="0"><a href="whee">bar</a></span> 
baz</p>' +
+                                       '</div>'
+                       },
+                       {
+                               msg: 'Nested annotation change',
+                               oldDoc: '<p><a href="#">foo bar baz</a></p>',
+                               newDoc: '<p><a href="#">foo <b>bar</b> 
baz</a></p>',
+                               expected:
+                                       '<div 
class="ve-ui-diffElement-doc-child-change">' +
+                                               '<p><a href="#">foo <del 
data-diff-action="remove">bar</del><ins 
data-diff-action="insert"><b>bar</b></ins> baz</a></p>' +
                                        '</div>'
                        },
                        {
@@ -286,7 +304,7 @@
                                newDoc: '<p>foo <b>bar</b> baz</p>',
                                expected:
                                        '<div 
class="ve-ui-diffElement-doc-child-change">' +
-                                               '<p>foo <del 
data-diff-action="remove">car</del><b><ins 
data-diff-action="insert">bar</ins></b> baz</p>' +
+                                               '<p>foo <del 
data-diff-action="remove">car</del><ins 
data-diff-action="insert"><b>bar</b></ins> baz</p>' +
                                        '</div>'
                        },
                        {
@@ -295,7 +313,7 @@
                                newDoc: '<p>foo car baz</p>',
                                expected:
                                        '<div 
class="ve-ui-diffElement-doc-child-change">' +
-                                               '<p>foo <b><del 
data-diff-action="remove">bar</del></b><ins data-diff-action="insert">car</ins> 
baz</p>' +
+                                               '<p>foo <del 
data-diff-action="remove"><b>bar</b></del><ins 
data-diff-action="insert">car</ins> baz</p>' +
                                        '</div>'
                        },
                        {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I13fb38e4e9943be328ba6dc85c124e74de451acd
Gerrit-PatchSet: 15
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Divec <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Tchanders <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to