Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.hooks.php |
— | — | @@ -104,6 +104,7 @@ |
105 | 105 | 'edittoolbar-tool-replace-button', |
106 | 106 | 'edittoolbar-tool-replace-close', |
107 | 107 | 'edittoolbar-tool-replace-nomatch', |
| 108 | + 'edittoolbar-tool-replace-success', |
108 | 109 | /* Special Characters Section */ |
109 | 110 | 'edittoolbar-section-characters', |
110 | 111 | 'edittoolbar-characters-page-latin', |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js |
— | — | @@ -1156,15 +1156,26 @@ |
1157 | 1157 | } |
1158 | 1158 | var regex = new RegExp( searchStr, flags ); |
1159 | 1159 | var $textarea = $j(this).data( 'context' ).$textarea; |
1160 | | - if ( !$textarea.val().match( regex ) ) { |
| 1160 | + var matches = $textarea.val().match( regex ); |
| 1161 | + if ( !matches ) { |
1161 | 1162 | alert( gM( 'edittoolbar-tool-replace-nomatch' ) ); |
1162 | 1163 | } else { |
1163 | | - $textarea.val( $textarea.val().replace( regex, replaceStr ) ); |
| 1164 | + var start, end; |
| 1165 | + for ( var i = 0; i < matches.length; i++ ) { |
| 1166 | + start = $textarea.val().indexOf( matches[i] ); |
| 1167 | + end = start + matches[i].length; |
| 1168 | + $textarea.setSelection( start, end ); |
| 1169 | + $textarea.encapsulateSelection( '', replaceStr, '', false, true ); |
| 1170 | + } |
| 1171 | + if ( i > 1 ) |
| 1172 | + alert( gM( 'edittoolbar-tool-replace-success', i ) ); |
| 1173 | + $textarea.scrollToCaretPosition( start ); |
| 1174 | + $textarea.setSelection( start, start + replaceStr.length ); |
1164 | 1175 | } |
1165 | | - // TODO: Hook for wikEd |
1166 | 1176 | }, |
1167 | 1177 | 'edittoolbar-tool-replace-close': function() { |
1168 | 1178 | $j(this).dialog( 'close' ); |
| 1179 | + $j(this).data( 'context' ).$textarea.focus(); |
1169 | 1180 | } |
1170 | 1181 | } |
1171 | 1182 | } |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.i18n.php |
— | — | @@ -91,6 +91,7 @@ |
92 | 92 | 'edittoolbar-tool-replace-button' => 'Replace', |
93 | 93 | 'edittoolbar-tool-replace-close' => 'Close', |
94 | 94 | 'edittoolbar-tool-replace-nomatch' => 'Your search did not match anything.', |
| 95 | + 'edittoolbar-tool-replace-success' => '$1 replacements made.', |
95 | 96 | /* Special characters Section */ |
96 | 97 | 'edittoolbar-section-characters' => 'Special characters', |
97 | 98 | 'edittoolbar-characters-page-latin' => 'Latin', |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.textSelection.js |
— | — | @@ -205,6 +205,21 @@ |
206 | 206 | } |
207 | 207 | return getCaret( this.get( 0 ) ); |
208 | 208 | }, |
| 209 | +setSelection: function( start, end ) { |
| 210 | + return this.each( function() { |
| 211 | + if ( this.selectionStart || this.selectionStart == '0' ) { |
| 212 | + this.selectionStart = start; |
| 213 | + this.selectionEnd = end; |
| 214 | + } else if ( document.body.createTextRange ) { |
| 215 | + var selection = document.body.createTextRange; |
| 216 | + selection.setToElementText( this ); |
| 217 | + var length = selection.text.length; |
| 218 | + selection.moveStart( 'character', start ); |
| 219 | + selection.moveEnd( 'character', -length + end ); |
| 220 | + selection.select(); |
| 221 | + } |
| 222 | + }); |
| 223 | +}, |
209 | 224 | /** |
210 | 225 | * Ported from Wikia's LinkSuggest extension |
211 | 226 | * https://svn.wikia-code.com/wikia/trunk/extensions/wikia/LinkSuggest |