mediawiki-extensions-Linter/modules/ext.linter.edit.js
Bartosz Dziewoński d18262cfa1 Scroll the textbox to selection (error location) on page load
Only doing 'setSelection' doesn't guarantee that the textbox will be
scrolled (it works on Firefox and Edge, but not on Chrome and IE).

Bug: T152760
Change-Id: I3fab6363cd432d137430884eaca3555a7bf5aafa
2019-06-09 19:37:15 +00:00

19 lines
599 B
JavaScript

$( function () {
var location = mw.config.get( 'wgLinterErrorLocation' ),
// eslint-disable-next-line no-jquery/no-global-selector
$textbox = $( '#wpTextbox1' );
if ( location ) {
if ( $textbox.length ) {
$textbox.trigger( 'focus' ).textSelection( 'setSelection', { start: location[ 0 ], end: location[ 1 ] } );
$textbox.textSelection( 'scrollToCaretPosition' );
}
mw.hook( 've.tempWikitextReady' ).add( function () {
mw.libs.ve.tempWikitextEditor.$element[ 0 ].setSelectionRange(
location[ 0 ], location[ 1 ]
);
mw.libs.ve.tempWikitextEditor.focus();
} );
}
} );