From 10948ba91f4d9c4521c7f4e1f47d325d956b469d Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Wed, 26 Jun 2013 13:03:59 +0100 Subject: [PATCH] Preserve scroll position after dialog close Bug: 49977 Change-Id: I8cc12ba7845eebc6199fbcd2d355bf0d5f38264b --- modules/ve/ce/ve.ce.Surface.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js index ec6300420f..681b5ea5d3 100644 --- a/modules/ve/ce/ve.ce.Surface.js +++ b/modules/ve/ce/ve.ce.Surface.js @@ -253,7 +253,13 @@ ve.ce.Surface.prototype.destroy = function () { * This is used when switching between surfaces, e.g. when closing a dialog window. */ ve.ce.Surface.prototype.focus = function () { - this.documentView.getDocumentNode().$[0].focus(); + var $document = this.documentView.getDocumentNode().$, + $window = $( ve.Element.static.getWindow( $document ) ), + scrollTop = $window.scrollTop(); + + $document[0].focus(); + // Calling focus sets the cursor to zero offset, so we need to restore scrollTop + $window.scrollTop( scrollTop ); this.focusedNode = null; this.onChange( null, this.surface.getModel().selection ); };