Ticket #3759: 3759.patch

File 3759.patch, 4.2 KB (added by Garry Yao, 15 years ago)
  • _source/plugins/find/dialogs/find.js

     
    426426                var finder = {
    427427                        searchRange : null,
    428428                        matchRange : null,
     429//                      lastPattern : null,  // The last searched pattern.
     430//                      fullCoverage : null,    // Is the document content been fully searched?
     431                        replaceCounter : 0, //Record how much replacement occurred when 'replace all'.
    429432                        find : function( pattern, matchCase, matchWord, matchCyclic )
    430433                        {
    431434                                if( !this.matchRange )
     
    438441                                        this.matchRange.removeHighlight();
    439442                                        this.matchRange = this.matchRange.getNextCharacterRange( pattern.length );
    440443                                }
    441 
     444                                // Necessary cleanup when search pattern changed.
     445                                if ( pattern != this.lastPattern )
     446                                {
     447                                        this.lastPattern = pattern;
     448                                        this.fullCoverage = null;
     449                                }
    442450                                var matcher = new kmpMatcher( pattern, !matchCase ),
    443451                                        matchState = KMP_NOMATCH,
    444452                                        character = '%';
     
    478486
    479487                                this.matchRange.clearMatched();
    480488                                this.matchRange.removeHighlight();
    481                                 // Clear current session and restart with the default search
    482                                 // range.
    483                                 if ( matchCyclic )
     489                                // On 'cyclic', clear current session and restart with
     490                                // the rest of content in document.
     491                                if ( matchCyclic && !this.fullCoverage )
    484492                                {
    485                                         this.searchRange = getSearchRange( true );
     493                                        this.searchRange = getSearchRange( null, this.searchRange.startContainer );
     494                                        this.fullCoverage = true;
    486495                                        this.matchRange = null;
     496                                        return this.find.apply( this, Array.prototype.slice.call( arguments ) );
    487497                                }
    488498
    489499                                return false;
    490500                        },
    491501
    492                         /**
    493                          * Record how much replacement occurred toward one replacing.
    494                          */
    495                         replaceCounter : 0,
    496 
    497502                        replace : function( dialog, pattern, newString, matchCase, matchWord,
    498503                                matchCyclic, matchReplaceAll )
    499504                        {
    500                                 // Successiveness of current replace/find.
     505
     506                                // Success of current replace/find.
    501507                                var result = false;
    502508
    503509                                // 1. Perform the replace when there's already a match here.
     
    530536                                else
    531537                                        result = this.find( pattern, matchCase, matchWord, matchCyclic );
    532538                               
    533                                 // Recusively replace all matches.
     539                                // Recursively replace all matches.
    534540                                if ( matchReplaceAll && result )
    535541                                        this.replace.apply( this, Array.prototype.slice.call( arguments ) );
    536542
     
    540546                };
    541547
    542548                /**
    543                  * The range in which find/replace happened, receive from user
    544                  * selection prior.
     549                 * The range in which find/replace happened.
    545550                 */
    546                 function getSearchRange( isDefault )
     551                function getSearchRange( start, end )
    547552                {
    548                         var searchRange,
    549                                 sel = editor.getSelection(),
    550                                 body = editor.document.getBody();
    551                         if ( sel && !isDefault )
    552                         {
    553                                 searchRange = sel.getRanges()[ 0 ].clone();
    554                                 searchRange.collapse( true );
    555                         }
    556                         else
    557                         {
    558                                 searchRange = new CKEDITOR.dom.range();
    559                                 searchRange.setStartAt( body, CKEDITOR.POSITION_AFTER_START );
    560                         }
    561                         searchRange.setEndAt( body, CKEDITOR.POSITION_BEFORE_END );
     553                        var doc = editor.document,
     554                                searchRange = new CKEDITOR.dom.range( doc ),
     555                                body = doc.getBody();
     556                        searchRange.setStartAt( start || body, CKEDITOR.POSITION_AFTER_START );
     557                        searchRange.setEndAt( end || body, CKEDITOR.POSITION_BEFORE_END );
    562558                        return searchRange;
    563559                }
    564560
     
    698694                                                                                var replaceNums;
    699695
    700696                                                                                finder.replaceCounter = 0;
     697                                                                                finder.fullCoverage = null;
    701698                                                                                if ( ( replaceNums = finder.replace( dialog,
    702699                                                                                        dialog.getValueOf( 'replace', 'txtFindReplace' ),
    703700                                                                                        dialog.getValueOf( 'replace', 'txtReplace' ),
     
    794791                        },
    795792                        onShow : function()
    796793                        {
    797                                 // Establish initial searching start position.
    798                                 finder.searchRange = getSearchRange();
     794                                // Initialize search range with document selection.
     795                                var sel = editor.getSelection();
     796                                finder.searchRange = getSearchRange( sel && sel.getStartElement() );
    799797
    800798                                if ( startupPage == 'replace' )
    801799                                        this.getContentElement( 'replace', 'txtFindReplace' ).focus();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy