r57376 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57375‎ | r57376 | r57377 >
Date:11:58, 5 October 2009
Author:catrope
Status:ok
Tags:
Comment:
* EditToolbar: (bug 20992) Regular expression search doesn't work when the first match is unique
* (bug 20993) Find Next button isn't triggered when user presses Enter while a match is selected in the textarea
Modified paths:
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js
@@ -1237,16 +1237,25 @@
12381238 var regex = new RegExp( searchStr, flags );
12391239 var $textarea = $j(this).data( 'context' ).$textarea;
12401240 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 )
12431249 $j( '#edittoolbar-replace-nomatch' ).show();
1244 - } else if ( mode == 'replaceAll' ) {
 1250+ else if ( mode == 'replaceAll' ) {
12451251 // Prepare to select the last match
12461252 var start = text.lastIndexOf( matches[matches.length - 1] );
12471253 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;
12491258 $textarea
1250 - .val( $textarea.val().replace( regex, replaceStr ) )
 1259+ .val( replaced )
12511260 .change()
12521261 .setSelection( start + corr, end + corr )
12531262 .scrollToCaretPosition();
@@ -1287,7 +1296,9 @@
12881297 },
12891298 'edittoolbar-tool-replace-close': function() {
12901299 $j(this).dialog( 'close' );
1291 - $j(this).data( 'context' ).$textarea.focus();
 1300+ $j(this).data( 'context' ).$textarea
 1301+ .unbind( 'keypress.srdialog' )
 1302+ .focus();
12921303 }
12931304 },
12941305 open: function() {
@@ -1299,13 +1310,15 @@
13001311 // Execute the action associated with the first button
13011312 // when the user presses Enter
13021313 $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();
13081316 });
13091317 }
 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+ });
13101323 }
13111324 }
13121325 }
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php
@@ -19,7 +19,7 @@
2020 /* Configuration */
2121
2222 // Bump the version number every time you change any of the .css/.js files
23 -$wgEditToolbarStyleVersion = 48;
 23+$wgEditToolbarStyleVersion = 49;
2424
2525 // Set this to true to simply override the stock toolbar for everyone
2626 $wgEditToolbarGlobalEnable = false;

Follow-up revisions

RevisionCommit summaryAuthorDate
r57719wmf-deployment: Merge babaco fixes from trunk...catrope20:20, 14 October 2009

Status & tagging log