Divec has uploaded a new change for review.

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

Change subject: Calculate unicorn offsets correctly
......................................................................

Calculate unicorn offsets correctly

Use .childNodes instead of .children because we care about text nodes too.
Land next to the unicorn (was erroneously landing at the start of its parent).
Land on the inside of an empty unicorn.

Change-Id: I185f8c97d66e605b7147e71d9850189da6a5d350
---
M src/ce/ve.ce.Document.js
1 file changed, 19 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/72/180072/1

diff --git a/src/ce/ve.ce.Document.js b/src/ce/ve.ce.Document.js
index 1ead7ac..2a58a54 100644
--- a/src/ce/ve.ce.Document.js
+++ b/src/ce/ve.ce.Document.js
@@ -106,9 +106,9 @@
                // At text offset or slug just before the pre unicorn; return 
the point just after it
                return ve.ce.nextCursorOffset( nextNode );
        } else if ( currentNode.nodeType === Node.ELEMENT_NODE &&
-               currentNode.children.length > nao.offset &&
-               currentNode.children[nao.offset].nodeType === Node.ELEMENT_NODE 
&&
-               currentNode.children[nao.offset].classList.contains( 
've-ce-pre-unicorn' )
+               currentNode.childNodes.length > nao.offset &&
+               currentNode.childNodes[nao.offset].nodeType === 
Node.ELEMENT_NODE &&
+               currentNode.childNodes[nao.offset].classList.contains( 
've-ce-pre-unicorn' )
        ) {
                // At element offset just before the pre unicorn; return the 
point just after it
                return { node: nao.node, offset: nao.offset + 1 };
@@ -128,8 +128,8 @@
                return ve.ce.previousCursorOffset( previousNode );
        } else if ( currentNode.nodeType === Node.ELEMENT_NODE &&
                nao.offset > 0 &&
-               currentNode.children[nao.offset - 1].nodeType === 
Node.ELEMENT_NODE &&
-               currentNode.children[nao.offset - 1].classList.contains( 
've-ce-post-unicorn' )
+               currentNode.childNodes[nao.offset - 1].nodeType === 
Node.ELEMENT_NODE &&
+               currentNode.childNodes[nao.offset - 1].classList.contains( 
've-ce-post-unicorn' )
        ) {
                // At element offset just after the post unicorn; return the 
point just before it
                return { node: nao.node, offset: nao.offset - 1 };
@@ -174,11 +174,21 @@
                        $item = current[0].eq( current[1] );
                        if ( $item.hasClass( 've-ce-unicorn' ) ) {
                                if ( offset === startOffset ) {
-                                       return {
-                                               node: $item[0].parentNode,
-                                               offset: offset - startOffset
-                                       };
+                                       // Return if empty unicorn pair at the 
correct offset
+                                       if ( $( $item[0].previousSibling 
).hasClass( 've-ce-unicorn' ) ) {
+                                               return {
+                                                       node: 
$item[0].parentNode,
+                                                       offset: current[1] - 1
+                                               };
+                                       } else if ( $( $item[0].nextSibling 
).hasClass( 've-ce-unicorn' ) ) {
+                                               return {
+                                                       node: 
$item[0].parentNode,
+                                                       offset: current[1] + 1
+                                               };
+                                       }
+                                       // Else algorithm will/did descend into 
unicorned range
                                }
+                               // Else algorithm will skip this unicorn
                        } else if ( $item.is( '.ve-ce-branchNode, 
.ve-ce-leafNode' ) ) {
                                model = $item.data( 'view' ).model;
                                // DM nodes can render as multiple elements in 
the view, so check

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

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

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

Reply via email to