https://bugzilla.wikimedia.org/show_bug.cgi?id=42073

--- Comment #5 from kipod <[email protected]> 2012-11-14 19:14:01 UTC ---
i may be a complete dunce, but i can't understand this piece of code (could not
find it in the repo - where is WikiEditor in the repo anyway? i had to cut it
from the browser's debugger):

=== BIZARRE CODE BEGIN ===============
                        } else if ( mode == 'replaceAll' ) {
                            // Instead of using repetitive .match() calls, we
use one .match() call with /g
                            // and indexOf() followed by substr() to find the
offsets. This is actually
                            // faster because our indexOf+substr loop is faster
than a match loop, and the
                            // /g match is so ridiculously fast that it's
negligible.
                            // FIXME: Repetitively calling
encapsulateSelection() is probably the best strategy
                            // in Firefox/Webkit, but in IE replacing the
entire content once is better.
                            for ( i = 0; i < match.length; i++ ) {
                                index = textRemainder.indexOf( match[i] );
                                if ( index === -1 ) {
                                    // This shouldn't happen
                                    break;
                                }
                                var matchedText = textRemainder.substr( index,
match[i].length );
                                textRemainder = textRemainder.substr( index +
match[i].length );

                                start = index + offset;
                                end = start + match[i].length;
                                // Make regex placeholder substitution ($1)
work
                                var replace = isRegex ? matchedText.replace(
regex, replaceStr ) : replaceStr;
                                var newEnd = start + replace.length;
                                $textarea
                                    .textSelection( 'setSelection', { 'start':
start, 'end': end } )
                                    .textSelection( 'encapsulateSelection', {
                                            'peri': replace,
                                            'replace': true } )
                                    .textSelection( 'setSelection', { 'start':
start, 'end': newEnd } );
                                offset = newEnd;
                            }
                            $( '#wikieditor-toolbar-replace-success' )
                                .text( mw.msg(
'wikieditor-toolbar-tool-replace-success', match.length ) )
                                .show();
                            $(this).data( 'offset', 0 );
                        } else {
======= BIZARRE CODE END =============

this looks very strange. for the "ReplaceAll", all you have to do is
$textarea.val($textarea.val().replace(regex));
$( '#wikieditor-toolbar-replace-success' )
                                .text( mw.msg(
'wikieditor-toolbar-tool-replace-success', match.length ) )
                                .show();

using the "textSelection" tool for repetitive replacement, where in reality
there *is* no selection, and the code iterate through loop of setting the
selection and then using the selection tool with "replace" looks very
perverted.

completely unrelated to this bug, but since i am here anyway: the most glaring
omission of the "text and replace" tool is the ability to limit the "replace
all" to current selection.

(i hate it that bugzilla does not have a "preview" feature).

peace.

-- 
Configure bugmail: https://bugzilla.wikimedia.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
You are on the CC list for the bug.

_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to