jenkins-bot has submitted this change and it was merged.

Change subject: Make ArticleTarget#goToHeading work at all times
......................................................................


Make ArticleTarget#goToHeading work at all times

Was previously written to work on initialise when the surface
isn't focused. If the surface is focused, run immediately.

Change-Id: Ie7accd63a4ca3e18448914d34609fe0418f15b4e
---
M modules/ve-mw/init/ve.init.mw.ArticleTarget.js
1 file changed, 11 insertions(+), 4 deletions(-)

Approvals:
  Jforrester: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js 
b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js
index 92cbca3..88fdd32 100644
--- a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js
+++ b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js
@@ -1637,15 +1637,22 @@
        offset = surfaceModel.getDocument().data.getNearestContentOffset(
                offsetNode.getModel().getOffset(), 1
        );
-       // onDocumentFocus is debounced, so wait for that to happen before 
setting
-       // the model selection, otherwise it will get reset
-       surfaceView.once( 'focus', function () {
+
+       function scrollAndSetSelection() {
                surfaceModel.setLinearSelection( new ve.Range( offset ) );
                // Focussing the document triggers showSelection which calls 
scrollIntoView
                // which uses a jQuery animation, so make sure this is aborted.
                $( OO.ui.Element.static.getClosestScrollableContainer( 
surfaceView.$element[ 0 ] ) ).stop( true );
                target.scrollToHeading( headingNode );
-       } );
+       }
+
+       if ( surfaceView.isFocused() ) {
+               scrollAndSetSelection();
+       } else {
+               // onDocumentFocus is debounced, so wait for that to happen 
before setting
+               // the model selection, otherwise it will get reset
+               surfaceView.once( 'focus', scrollAndSetSelection );
+       }
 };
 
 /**

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie7accd63a4ca3e18448914d34609fe0418f15b4e
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Alex Monk <a...@wikimedia.org>
Gerrit-Reviewer: DLynch <dly...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to