Robmoen has uploaded a new change for review.

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


Change subject: If cursor is obscured by toolbar, on keypress scroll to cursor.
......................................................................

If cursor is obscured by toolbar, on keypress scroll to cursor.

Bug: 48735
Change-Id: I45028ed2f13148332518badd5f4647d4d652884e
---
M modules/ve/ui/ve.ui.Toolbar.js
1 file changed, 19 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/18/70918/1

diff --git a/modules/ve/ui/ve.ui.Toolbar.js b/modules/ve/ui/ve.ui.Toolbar.js
index f180066..333a421 100644
--- a/modules/ve/ui/ve.ui.Toolbar.js
+++ b/modules/ve/ui/ve.ui.Toolbar.js
@@ -37,7 +37,8 @@
        this.$window = null;
        this.windowEvents = {
                'resize': ve.bind( this.onWindowResize, this ),
-               'scroll': ve.bind( this.onWindowScroll, this )
+               'scroll': ve.bind( this.onWindowScroll, this ),
+               'keypress': ve.bind( this.onWindowKeypress, this )
        };
 
        // Events
@@ -101,7 +102,7 @@
 };
 
 /**
- * Handle window scroll events while toolbar floating is enabled.
+ * Handle window scroll resize while toolbar floating is enabled.
  *
  * Toolbar will stick to the top of the screen unless it would be over or 
under the last visible
  * branch node in the root of the document being edited, at which point it 
will stop just above it.
@@ -122,6 +123,22 @@
 };
 
 /**
+ * Method to scroll to the cursor position while toolbar is floating on 
keypress only if
+ * the cursor is obscured by the toolbar.
+ *
+ */
+ve.ui.Toolbar.prototype.onWindowKeypress = function () {
+       var cursorPos = this.surface.view.getSelectionRect(),
+               scrollTo = cursorPos.end.y - this.surface.view.$.offset().top,
+               obscured = cursorPos.end.y - this.$window.scrollTop() < 
this.$.height() + this.$.offset().top;
+
+       // If toolbar is floating and cursor
+       if ( obscured && this.floating ) {
+               $( 'html,body' ).animate( { scrollTop: scrollTo }, 0 );
+       }
+};
+
+/**
  * Gets the surface the toolbar controls.
  *
  * @method

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I45028ed2f13148332518badd5f4647d4d652884e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Robmoen <rm...@wikimedia.org>

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

Reply via email to