mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 06:46:26 +00:00
Merge "ve.ce.Surface.getSelectionRect() can return null"
This commit is contained in:
commit
66615efc1f
|
@ -184,6 +184,7 @@ ve.ce.Surface.static.getClipboardHash = function ( $elements ) {
|
|||
* Get the coordinates of the selection anchor.
|
||||
*
|
||||
* @method
|
||||
* @returns {Object|null} { 'start': { 'x': ..., 'y': ... }, 'end': { 'x': ..., 'y': ... } }
|
||||
*/
|
||||
ve.ce.Surface.prototype.getSelectionRect = function () {
|
||||
var sel, rect, $span, lineHeight, startRange, startOffset, endRange, endOffset, focusedOffset;
|
||||
|
|
|
@ -294,6 +294,14 @@ ve.ui.Context.prototype.updateDimensions = function ( transition ) {
|
|||
// We're on top of a selected text
|
||||
// Get the position of the cursor
|
||||
cursorPosition = surface.getSelectionRect();
|
||||
if ( !cursorPosition ) {
|
||||
// The surface apparently isn't selected, so getSelectionRect() returned null.
|
||||
// This shouldn't happen because the context is only supposed to be displayed in
|
||||
// response to a selection, but for some reason this does happen in phantomjs.
|
||||
// We can't update the context position if we don't know where the selection is,
|
||||
// so just bail.
|
||||
return this;
|
||||
}
|
||||
|
||||
// Correct for surface offset:
|
||||
position = {
|
||||
|
|
|
@ -130,9 +130,13 @@ ve.ui.SurfaceToolbar.prototype.onWindowResize = function () {
|
|||
* the cursor is obscured by the toolbar.
|
||||
*/
|
||||
ve.ui.SurfaceToolbar.prototype.onSurfaceViewKeyUp = function () {
|
||||
var cursorPos = this.surface.view.getSelectionRect(),
|
||||
barHeight = this.$bar.height(),
|
||||
scrollTo = this.$bar.offset().top - barHeight + ( cursorPos.end.y - cursorPos.start.y ),
|
||||
var barHeight, scrollTo, obscured, cursorPos = this.surface.view.getSelectionRect();
|
||||
if ( !cursorPos ) {
|
||||
return;
|
||||
}
|
||||
|
||||
barHeight = this.$bar.height();
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue