Catrope has uploaded a new change for review.

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


Change subject: Restore selection when editor is refocused
......................................................................

Restore selection when editor is refocused

When the editor is focused, the selection goes back to the start of
the document. This was remedied in the .focus() method, but not in
response to native focus events, so when external code blurred then
refocused the editor, the selection would move to the top.

This broke section editing on wikis where ULS is installed: the
selection would be initialized at the start of the section, but then
ULS would load and blur the documentNode (by focusing the pasteTarget)
and then focus it again, so the selection would move to the top.

Instead of restoring the selection only in .focus(), restore it in
response to focus events on the documentNode. When this is done,
saving and restoring the scrollTop is no longer needed.

Bug: 56651
Change-Id: I14700174ee092f9b208215d31a7d1871078a89bf
---
M modules/ve/ce/ve.ce.Surface.js
1 file changed, 8 insertions(+), 10 deletions(-)


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

diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js
index cbf8d64..aa575fa 100644
--- a/modules/ve/ce/ve.ce.Surface.js
+++ b/modules/ve/ce/ve.ce.Surface.js
@@ -302,15 +302,8 @@
  * This is used when switching between surfaces, e.g. when closing a dialog 
window.
  */
 ve.ce.Surface.prototype.focus = function () {
-       var $document = this.documentView.getDocumentNode().$element,
-               $window = this.$( OO.ui.Element.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.onModelSelect( this.surface.getModel().selection );
+       this.documentView.getDocumentNode().$element[0].focus();
+       // documentOnFocus takes care of the rest
 };
 
 /*! Native Browser Events */
@@ -321,7 +314,12 @@
  * @method
  * @param {Event} e Focus event (native event, NOT a jQuery event!)
  */
-ve.ce.Surface.prototype.documentOnFocus = function () {
+ve.ce.Surface.prototype.documentOnFocus = function ( e ) {
+       if ( e.target === this.documentView.getDocumentNode().$element[0] ) {
+               // The document node was focused (as opposed to the paste 
target)
+               // Restore the selection
+               this.onModelSelect( this.surface.getModel().getSelection() );
+       }
        this.eventSequencer.attach( this.$element );
        this.surfaceObserver.startTimerLoop();
 };

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I14700174ee092f9b208215d31a7d1871078a89bf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to