http://www.mediawiki.org/wiki/Special:Code/MediaWiki/57376

Revision: 57376
Author:   catrope
Date:     2009-10-05 11:58:45 +0000 (Mon, 05 Oct 2009)

Log Message:
-----------
* 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
    trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php

Modified: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js
===================================================================
--- trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js     
2009-10-05 11:30:52 UTC (rev 57375)
+++ trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js     
2009-10-05 11:58:45 UTC (rev 57376)
@@ -1237,16 +1237,25 @@
                                var regex = new RegExp( searchStr, flags );
                                var $textarea = $j(this).data( 'context' 
).$textarea;
                                var text = $j.wikiEditor.fixOperaBrokenness( 
$textarea.val() );
-                               var matches = text.match( regex );
-                               if ( !matches ) {
+                               var matches = false;
+                               if ( mode != 'replaceAll' )
+                                       matches = text.substr( $j(this).data( 
'offset' ) ).match( regex );
+                               if ( !matches )
+                                       // Search hit BOTTOM, continuing at TOP
+                                       matches = text.match( regex );
+                               
+                               if ( !matches )
                                        $j( '#edittoolbar-replace-nomatch' 
).show();
-                               } else if ( mode == 'replaceAll' ) {
+                               else if ( mode == 'replaceAll' ) {
                                        // Prepare to select the last match
                                        var start = text.lastIndexOf( 
matches[matches.length - 1] );
                                        var end = start + replaceStr.length;
-                                       var corr = ( matches.length - 1 ) * ( 
replaceStr.length - searchStr.length ); 
+                                       
+                                       // Calculate how much the last match 
will move
+                                       var replaced = text.replace( regex, 
replaceStr );
+                                       var corr = replaced.length - 
text.length - replaceStr.length + matches[matches.length - 1].length;
                                        $textarea
-                                               .val( $textarea.val().replace( 
regex, replaceStr ) )
+                                               .val( replaced )
                                                .change()
                                                .setSelection( start + corr, 
end + corr )
                                                .scrollToCaretPosition();
@@ -1287,7 +1296,9 @@
                                },
                                'edittoolbar-tool-replace-close': function() {
                                        $j(this).dialog( 'close' );
-                                       $j(this).data( 'context' 
).$textarea.focus();
+                                       $j(this).data( 'context' ).$textarea
+                                               .unbind( 'keypress.srdialog' )
+                                               .focus();
                                }
                        },
                        open: function() {
@@ -1299,13 +1310,15 @@
                                        // Execute the action associated with 
the first button
                                        // when the user presses Enter
                                        $j(this).closest( '.ui-dialog' 
).keypress( function( e ) {
-                                               if ( ( e.keyCode || e.which ) 
== 13 ) {
-                                                       $j(this)
-                                                               .find( 
'button:first' )
-                                                               .click();
-                                               }
+                                               if ( ( e.keyCode || e.which ) 
== 13 )
+                                                       $j(this).find( 
'button:first' ).click();
                                        });
                                }
+                               var dialog = $j(this).closest( '.ui-dialog' );
+                               $j(this).data( 'context' ).$textarea.bind( 
'keypress.srdialog', function( e ) {
+                                       if ( ( e.keyCode || e.which ) == 13 )
+                                               dialog.find( 'button:first' 
).click();
+                               });
                        }
                }
        }

Modified: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php
===================================================================
--- trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php    
2009-10-05 11:30:52 UTC (rev 57375)
+++ trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php    
2009-10-05 11:58:45 UTC (rev 57376)
@@ -19,7 +19,7 @@
 /* Configuration */
 
 // Bump the version number every time you change any of the .css/.js files
-$wgEditToolbarStyleVersion = 48;
+$wgEditToolbarStyleVersion = 49;
 
 // Set this to true to simply override the stock toolbar for everyone
 $wgEditToolbarGlobalEnable = false;



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to