Divec has uploaded a new change for review.

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

Change subject: Use unicorn client rect for adjacent collapsed selection
......................................................................

Use unicorn client rect for adjacent collapsed selection

For a collapsed selection between two unicorn images, the nearest containing 
client rect is
actually that of the surrounding element, which can be arbitrarily wide. The 
unicorn's own
client rect is a better match for the cursor position.

Change-Id: I77894f24c1fee39343ce6652f999aaa9133cc511
---
M src/ce/ve.ce.Surface.js
1 file changed, 32 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/24/176824/1

diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 110fe4c..d6d5c82 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -347,34 +347,46 @@
  * @return {Object} ClientRect-like object
  */
 ve.ce.Surface.prototype.getClientRectFromNode = function () {
-       var rect, rtl, x,
+       var rect, side, x, range, adjacentNode,
                node = this.nativeSelection.focusNode;
 
        while ( node && node.nodeType !== Node.ELEMENT_NODE ) {
                node = node.parentNode;
        }
+
+       if ( !node ) {
+               return null;
+       }
+
        // When possible, pretend the cursor is the left/right border of the 
node
        // (depending on directionality) as a fallback.
-       if ( node ) {
-               // We would use getBoundingClientRect(), but in iOS7 that's 
relative to the
-               // document rather than to the viewport
-               rect = node.getClientRects()[0];
-               if ( !rect ) {
-                       // FF can return null when focusNode is invisible
-                       return null;
-               }
-               rtl = this.getModel().getDocument().getDir() === 'rtl';
-               x = rtl ? rect.right : rect.left;
-               return {
-                       top: rect.top,
-                       bottom: rect.bottom,
-                       left: x,
-                       right: x,
-                       width: 0,
-                       height: rect.height
-               };
+
+       // We would use getBoundingClientRect(), but in iOS7 that's relative to 
the
+       // document rather than to the viewport
+       rect = node.getClientRects()[0];
+       if ( !rect ) {
+               // FF can return null when focusNode is invisible
+               return null;
        }
-       return null;
+
+       side = this.getModel().getDocument().getDir() === 'rtl' ? 'right' : 
'left';
+       range = this.nativeSelection.getRangeAt( 0 );
+       adjacentNode = range.endContainer.childNodes[ range.endOffset ];
+       if ( range.collapsed && $( adjacentNode ).hasClass( 've-ce-unicorn' ) ) 
{
+               // We're next to a unicorn; use its left/right position
+               x = adjacentNode.getClientRects()[0][ side ];
+       } else {
+               x = rect[ side ];
+       }
+
+       return {
+               top: rect.top,
+               bottom: rect.bottom,
+               left: x,
+               right: x,
+               width: 0,
+               height: rect.height
+       };
 };
 
 /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I77894f24c1fee39343ce6652f999aaa9133cc511
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