Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js |
— | — | @@ -1179,6 +1179,40 @@ |
1180 | 1180 | dialog: { |
1181 | 1181 | buttons: { |
1182 | 1182 | 'edittoolbar-tool-replace-button': function() { |
| 1183 | + function fixOperaBrokenness( s ) { |
| 1184 | + // This function works around Opera's |
| 1185 | + // broken newline handling in textareas. |
| 1186 | + // .val() has \n while selection functions |
| 1187 | + // treat newlines as \r\n |
| 1188 | + |
| 1189 | + if ( typeof $j.isOperaBroken == 'undefined' ) { |
| 1190 | + // Create a textarea inside a div |
| 1191 | + // with zero area, to hide it properly |
| 1192 | + var div = $j( '<div />' ) |
| 1193 | + .height( 0 ) |
| 1194 | + .width( 0 ) |
| 1195 | + .insertBefore( $textarea ); |
| 1196 | + var textarea = $j( '<textarea></textarea' ) |
| 1197 | + .height( 0 ) |
| 1198 | + .appendTo( div ) |
| 1199 | + .val( "foo\r\nbar" ); |
| 1200 | + |
| 1201 | + // Try to search&replace bar --> BAR |
| 1202 | + var index = textarea.val().indexOf( 'bar' ); |
| 1203 | + textarea.select(); |
| 1204 | + textarea.setSelection( index, index + 3 ); |
| 1205 | + textarea.encapsulateSelection( '', 'BAR', '', false, true ); |
| 1206 | + if ( textarea.val().substr( -1 ) == 'R' ) |
| 1207 | + $j.isOperaBroken = false; |
| 1208 | + else |
| 1209 | + $j.isOperaBroken = true; |
| 1210 | + div.remove(); |
| 1211 | + } |
| 1212 | + if ( $j.isOperaBroken ) |
| 1213 | + s = s.replace( /\n/g, "\r\n" ); |
| 1214 | + return s; |
| 1215 | + } |
| 1216 | + |
1183 | 1217 | var searchStr = $j( '#edittoolbar-replace-search' ).val(); |
1184 | 1218 | var replaceStr = $j( '#edittoolbar-replace-replace' ).val(); |
1185 | 1219 | var flags = ''; |
— | — | @@ -1193,13 +1227,14 @@ |
1194 | 1228 | } |
1195 | 1229 | var regex = new RegExp( searchStr, flags ); |
1196 | 1230 | var $textarea = $j(this).data( 'context' ).$textarea; |
1197 | | - var matches = $textarea.val().match( regex ); |
| 1231 | + var text = fixOperaBrokenness( $textarea.val() ); |
| 1232 | + var matches = text.match( regex ); |
1198 | 1233 | if ( !matches ) { |
1199 | 1234 | alert( gM( 'edittoolbar-tool-replace-nomatch' ) ); |
1200 | 1235 | } else { |
1201 | 1236 | var start, end; |
1202 | 1237 | for ( var i = 0; i < matches.length; i++ ) { |
1203 | | - start = $textarea.val().indexOf( matches[i] ); |
| 1238 | + start = text.indexOf( matches[i] ); |
1204 | 1239 | end = start + matches[i].length; |
1205 | 1240 | $textarea.setSelection( start, end ); |
1206 | 1241 | $textarea.encapsulateSelection( '', replaceStr, '', false, true ); |
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 = 35; |
| 23 | +$wgEditToolbarStyleVersion = 36; |
24 | 24 | |
25 | 25 | // Set this to true to simply override the stock toolbar for everyone |
26 | 26 | $wgEditToolbarGlobalEnable = false; |