mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Linter
synced 2024-11-14 19:27:53 +00:00
9c65d786e2
Register a hook for when VE is finished initializing to select the error section, just like the textbox-based editor. Use the BeforePageDisplay hook so it runs on VE page loads too. Bug: T160102 Change-Id: I59a7e0a3e8be32e4689cbf41c4904970902c4dff
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
( function ( mw, $ ) {
|
|
$( function () {
|
|
var location = mw.config.get( 'wgLinterErrorLocation' ),
|
|
$textbox = $( '#wpTextbox1' );
|
|
|
|
/**
|
|
* Convert the normal offset for one that is usable
|
|
* by VE's DOM that changes newlines into <p>
|
|
*
|
|
* @param {ve.ui.Surface} surface
|
|
* @param {int} offset
|
|
* @return {int}
|
|
*/
|
|
function fixOffset( surface, offset ) {
|
|
return ( surface.getDom().slice( 0, offset ).match( /\n/g ) || [] ).length + 1 + offset;
|
|
}
|
|
|
|
if ( location ) {
|
|
if ( $textbox.length ) {
|
|
$textbox.focus().textSelection( 'setSelection', { start: location[ 0 ], end: location[ 1 ] } );
|
|
}
|
|
// Register NWE code should it be loaded
|
|
// TODO: We should somehow force source mode if VE is opened
|
|
mw.hook( 've.activationComplete' ).add( function () {
|
|
var range,
|
|
surface = ve.init.target.getSurface();
|
|
|
|
if ( surface.getMode() === 'source' ) {
|
|
range = new ve.Range( fixOffset( surface, location[ 0 ] ), fixOffset( surface, location[ 1 ] ) );
|
|
surface.getModel().setLinearSelection( range );
|
|
}
|
|
} );
|
|
}
|
|
} );
|
|
}( mediaWiki, jQuery ) );
|