jenkins-bot has submitted this change and it was merged.

Change subject: Fixing inspector popup position
......................................................................


Fixing inspector popup position

The inspector popup should appear relative to the position of the related
calling method - either relative to the cursor (like in links and language)
or relative to the focusableNode (like in templates/transclusion).

Bug: 50905
Change-Id: I07f58d0c6561adecbec560fc24bcb6e590f2cd9f
---
M modules/ve/ui/ve.ui.Context.js
1 file changed, 38 insertions(+), 22 deletions(-)

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



diff --git a/modules/ve/ui/ve.ui.Context.js b/modules/ve/ui/ve.ui.Context.js
index 9eb1d42..077a52f 100644
--- a/modules/ve/ui/ve.ui.Context.js
+++ b/modules/ve/ui/ve.ui.Context.js
@@ -249,46 +249,62 @@
                surface = this.surface.getView(),
                inspector = this.inspectors.getCurrent(),
                focusedNode = surface.getFocusedNode(),
-               // Get cursor position
-               position = surface.getSelectionRect(),
-               surfaceOffset = surface.$.offset();
+               surfaceOffset = surface.$.offset(),
+               $node, nodePosition, cursorPosition, position;
 
-       // translate from ce surface
-       position = {
-               y: position.end.y - surfaceOffset.top,
-               x: position.end.x - surfaceOffset.left
-       };
-
-       if ( position ) {
-               $container = inspector ? this.inspectors.$ : this.$menu;
+       $container = inspector ? this.inspectors.$ : this.$menu;
+       if ( focusedNode ) {
+               // We're on top of a node
+               $node = focusedNode.$;
+               nodePosition = $node.position();
                if ( this.embedded ) {
+                       // Get the position relative to the surface it is 
embedded in
                        focusableOffset = ve.Element.getRelativePosition(
-                               focusedNode.$focusable, this.surface.$
+                               $node, this.surface.$
                        );
-                       focusableWidth = focusedNode.$focusable.outerWidth();
                        position = { 'y': focusableOffset.top };
-                       // RTL check for Page-level (CE)
+
+                       // When inspector is embedded in RTL, it requires
+                       // adjustments to the relative positioning (pop up on 
the other side):
                        if ( this.surface.view.getDir() === 'rtl' ) {
                                position.x = focusableOffset.left;
                                this.popup.align = 'left';
                        } else {
+                               focusableWidth = $node.outerWidth();
                                position.x = focusableOffset.left + 
focusableWidth;
                                this.popup.align = 'right';
                        }
                } else {
+                       // Get the position of the focusedNode:
+                       position = {
+                               x: nodePosition.left,
+                               y: nodePosition.top
+                       };
                        this.popup.align = 'center';
                }
-               this.$.css( { 'left': position.x, 'top': position.y } );
+       } else {
+               // We're on top of a selected text
+               // Get the position of the cursor
+               cursorPosition = surface.getSelectionRect();
 
-               this.popup.display(
-                       position.x,
-                       position.y,
-                       $container.outerWidth( true ),
-                       $container.outerHeight( true ),
-                       transition
-               );
+               // Correct for surface offset:
+               position = {
+                       x: cursorPosition.end.x - surfaceOffset.left,
+                       y: cursorPosition.end.y - surfaceOffset.top
+               };
+               this.popup.align = 'center';
        }
 
+       this.$.css( { 'left': position.x, 'top': position.y } );
+
+       this.popup.display(
+               position.x,
+               position.y,
+               $container.outerWidth( true ),
+               $container.outerHeight( true ),
+               transition
+       );
+
        return this;
 };
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I07f58d0c6561adecbec560fc24bcb6e590f2cd9f
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <mor...@gmail.com>
Gerrit-Reviewer: Amire80 <amir.ahar...@mail.huji.ac.il>
Gerrit-Reviewer: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Inez <i...@wikia-inc.com>
Gerrit-Reviewer: Trevor Parscal <tpars...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to