mediawiki-extensions-Linter/modules/ext.linter.edit.js
Ed Sanders f5df08a745 Use VE's new offset conversion method
Change-Id: I64767fccae26522fdce5287c5486c322108c168a
Depends-On: Idc960a37433c5b8d952a677d1529a25b94fac7f7
Depends-On: I1071faeec586fa2b44be810a35f8044800c8f800
2017-11-04 21:44:11 +00:00

27 lines
874 B
JavaScript

( function ( mw, $ ) {
$( function () {
var location = mw.config.get( 'wgLinterErrorLocation' ),
$textbox = $( '#wpTextbox1' );
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 () {
// Selection is reset on a setTimeout after activation, so wait for that.
setTimeout( function () {
var range,
surface = ve.init.target.getSurface();
if ( surface.getMode() === 'source' ) {
range = surface.getModel().getRangeFromSourceOffsets( location[ 0 ], location[ 1 ] );
surface.getModel().setLinearSelection( range );
}
} );
} );
}
} );
}( mediaWiki, jQuery ) );