Merge "Bind listener to keyup to capture arrows & better math for scrolling."

This commit is contained in:
jenkins-bot 2013-07-10 21:22:58 +00:00 committed by Gerrit Code Review
commit ac6c10dad7

View file

@ -40,7 +40,7 @@ ve.ui.Toolbar = function VeUiToolbar( surface, options ) {
'scroll': ve.bind( this.onWindowScroll, this ) 'scroll': ve.bind( this.onWindowScroll, this )
}; };
this.surfaceViewEvents = { this.surfaceViewEvents = {
'keypress': ve.bind( this.onSurfaceViewKeyPress, this ) 'keyup': ve.bind( this.onSurfaceViewKeyUp, this )
}; };
// Events // Events
@ -125,14 +125,15 @@ ve.ui.Toolbar.prototype.onWindowResize = function () {
}; };
/** /**
* Method to scroll to the cursor position while toolbar is floating on keypress only if * Method to scroll to the cursor position while toolbar is floating on keyup only if
* the cursor is obscured by the toolbar. * the cursor is obscured by the toolbar.
* *
*/ */
ve.ui.Toolbar.prototype.onSurfaceViewKeyPress = function () { ve.ui.Toolbar.prototype.onSurfaceViewKeyUp = function () {
var cursorPos = this.surface.view.getSelectionRect(), var cursorPos = this.surface.view.getSelectionRect(),
scrollTo = cursorPos.end.y - this.surface.view.$.offset().top, barHeight = this.$bar.height(),
obscured = cursorPos.end.y - this.$window.scrollTop() < this.$.height() + this.$.offset().top; scrollTo = this.$bar.offset().top - barHeight + ( cursorPos.end.y - cursorPos.start.y ),
obscured = cursorPos.start.y - this.$window.scrollTop() < barHeight;
// If toolbar is floating and cursor is obscured, scroll cursor into view // If toolbar is floating and cursor is obscured, scroll cursor into view
if ( obscured && this.floating ) { if ( obscured && this.floating ) {