mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 06:46:26 +00:00
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
This commit is contained in:
parent
b496f7d3f1
commit
3970288c8c
|
@ -1637,15 +1637,22 @@ ve.init.mw.ArticleTarget.prototype.goToHeading = function ( headingNode ) {
|
|||
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 );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue