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

Change subject: ce.BranchNode: Handle splices next to text nodes
......................................................................

ce.BranchNode: Handle splices next to text nodes

Because ce.TextNodes have an empty .$element, the onSplice logic
fails to find the insertion point in the DOM.

We assume that there will never be two adjacent text nodes,
so when the insertion point is after a text node, we go
back one node, get its .$element, then move forward one
node in the DOM.

Change-Id: I22ae8fad8c24b7e8e60abab78142b6f59b736549
---
M src/ce/ve.ce.BranchNode.js
1 file changed, 22 insertions(+), 8 deletions(-)


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

diff --git a/src/ce/ve.ce.BranchNode.js b/src/ce/ve.ce.BranchNode.js
index 6e680e8..1ba33be 100644
--- a/src/ce/ve.ce.BranchNode.js
+++ b/src/ce/ve.ce.BranchNode.js
@@ -179,7 +179,9 @@
        var i, j,
                length,
                args = [],
-               $anchor,
+               anchorCeNode,
+               prevCeNode,
+               anchorDomNode,
                afterAnchor,
                node,
                parentNode,
@@ -203,16 +205,28 @@
                removals[ i ].$element.detach();
        }
        if ( args.length >= 3 ) {
-               if ( index ) {
-                       // Get the element before the insertion point
-                       $anchor = this.children[ index - 1 ].$element.last();
+               if ( index > 0 ) {
+                       // Get the element before the insertion
+                       anchorCeNode = this.children[ index - 1 ];
+                       // If the CE node is a text node, its $element will be 
empty
+                       // Look at its previous sibling, which cannot be a text 
node
+                       if ( anchorCeNode.getType() === 'text' ) {
+                               prevCeNode = this.children[ index - 2 ];
+                               if ( prevCeNode ) {
+                                       anchorDomNode = 
prevCeNode.$element.last()[ 0 ].nextSibling;
+                               } else {
+                                       anchorDomNode = this.$element[ 0 
].firstChild;
+                               }
+                       } else {
+                               anchorDomNode = anchorCeNode.$element.last()[ 0 
];
+                       }
                }
                for ( i = args.length - 1; i >= 2; i-- ) {
                        args[ i ].attach( this );
-                       if ( index ) {
-                               // DOM equivalent of $anchor.after( 
args[i].$element );
-                               afterAnchor = $anchor[ 0 ].nextSibling;
-                               parentNode = $anchor[ 0 ].parentNode;
+                       if ( anchorDomNode ) {
+                               // DOM equivalent of $( anchorDomNode ).after( 
args[i].$element );
+                               afterAnchor = anchorDomNode.nextSibling;
+                               parentNode = anchorDomNode.parentNode;
                                for ( j = 0, length = args[ i 
].$element.length; j < length; j++ ) {
                                        parentNode.insertBefore( args[ i 
].$element[ j ], afterAnchor );
                                }

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

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

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

Reply via email to