Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js |
— | — | @@ -1237,16 +1237,25 @@ |
1238 | 1238 | var regex = new RegExp( searchStr, flags ); |
1239 | 1239 | var $textarea = $j(this).data( 'context' ).$textarea; |
1240 | 1240 | var text = $j.wikiEditor.fixOperaBrokenness( $textarea.val() ); |
1241 | | - var matches = text.match( regex ); |
1242 | | - if ( !matches ) { |
| 1241 | + var matches = false; |
| 1242 | + if ( mode != 'replaceAll' ) |
| 1243 | + matches = text.substr( $j(this).data( 'offset' ) ).match( regex ); |
| 1244 | + if ( !matches ) |
| 1245 | + // Search hit BOTTOM, continuing at TOP |
| 1246 | + matches = text.match( regex ); |
| 1247 | + |
| 1248 | + if ( !matches ) |
1243 | 1249 | $j( '#edittoolbar-replace-nomatch' ).show(); |
1244 | | - } else if ( mode == 'replaceAll' ) { |
| 1250 | + else if ( mode == 'replaceAll' ) { |
1245 | 1251 | // Prepare to select the last match |
1246 | 1252 | var start = text.lastIndexOf( matches[matches.length - 1] ); |
1247 | 1253 | var end = start + replaceStr.length; |
1248 | | - var corr = ( matches.length - 1 ) * ( replaceStr.length - searchStr.length ); |
| 1254 | + |
| 1255 | + // Calculate how much the last match will move |
| 1256 | + var replaced = text.replace( regex, replaceStr ); |
| 1257 | + var corr = replaced.length - text.length - replaceStr.length + matches[matches.length - 1].length; |
1249 | 1258 | $textarea |
1250 | | - .val( $textarea.val().replace( regex, replaceStr ) ) |
| 1259 | + .val( replaced ) |
1251 | 1260 | .change() |
1252 | 1261 | .setSelection( start + corr, end + corr ) |
1253 | 1262 | .scrollToCaretPosition(); |
— | — | @@ -1287,7 +1296,9 @@ |
1288 | 1297 | }, |
1289 | 1298 | 'edittoolbar-tool-replace-close': function() { |
1290 | 1299 | $j(this).dialog( 'close' ); |
1291 | | - $j(this).data( 'context' ).$textarea.focus(); |
| 1300 | + $j(this).data( 'context' ).$textarea |
| 1301 | + .unbind( 'keypress.srdialog' ) |
| 1302 | + .focus(); |
1292 | 1303 | } |
1293 | 1304 | }, |
1294 | 1305 | open: function() { |
— | — | @@ -1299,13 +1310,15 @@ |
1300 | 1311 | // Execute the action associated with the first button |
1301 | 1312 | // when the user presses Enter |
1302 | 1313 | $j(this).closest( '.ui-dialog' ).keypress( function( e ) { |
1303 | | - if ( ( e.keyCode || e.which ) == 13 ) { |
1304 | | - $j(this) |
1305 | | - .find( 'button:first' ) |
1306 | | - .click(); |
1307 | | - } |
| 1314 | + if ( ( e.keyCode || e.which ) == 13 ) |
| 1315 | + $j(this).find( 'button:first' ).click(); |
1308 | 1316 | }); |
1309 | 1317 | } |
| 1318 | + var dialog = $j(this).closest( '.ui-dialog' ); |
| 1319 | + $j(this).data( 'context' ).$textarea.bind( 'keypress.srdialog', function( e ) { |
| 1320 | + if ( ( e.keyCode || e.which ) == 13 ) |
| 1321 | + dialog.find( 'button:first' ).click(); |
| 1322 | + }); |
1310 | 1323 | } |
1311 | 1324 | } |
1312 | 1325 | } |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | /* Configuration */ |
21 | 21 | |
22 | 22 | // Bump the version number every time you change any of the .css/.js files |
23 | | -$wgEditToolbarStyleVersion = 48; |
| 23 | +$wgEditToolbarStyleVersion = 49; |
24 | 24 | |
25 | 25 | // Set this to true to simply override the stock toolbar for everyone |
26 | 26 | $wgEditToolbarGlobalEnable = false; |