Ticket #3759: 3759.patch
File 3759.patch, 4.2 KB (added by , 15 years ago) |
---|
-
_source/plugins/find/dialogs/find.js
426 426 var finder = { 427 427 searchRange : null, 428 428 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'. 429 432 find : function( pattern, matchCase, matchWord, matchCyclic ) 430 433 { 431 434 if( !this.matchRange ) … … 438 441 this.matchRange.removeHighlight(); 439 442 this.matchRange = this.matchRange.getNextCharacterRange( pattern.length ); 440 443 } 441 444 // Necessary cleanup when search pattern changed. 445 if ( pattern != this.lastPattern ) 446 { 447 this.lastPattern = pattern; 448 this.fullCoverage = null; 449 } 442 450 var matcher = new kmpMatcher( pattern, !matchCase ), 443 451 matchState = KMP_NOMATCH, 444 452 character = '%'; … … 478 486 479 487 this.matchRange.clearMatched(); 480 488 this.matchRange.removeHighlight(); 481 // Clear current session and restart with the default search482 // 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 ) 484 492 { 485 this.searchRange = getSearchRange( true ); 493 this.searchRange = getSearchRange( null, this.searchRange.startContainer ); 494 this.fullCoverage = true; 486 495 this.matchRange = null; 496 return this.find.apply( this, Array.prototype.slice.call( arguments ) ); 487 497 } 488 498 489 499 return false; 490 500 }, 491 501 492 /**493 * Record how much replacement occurred toward one replacing.494 */495 replaceCounter : 0,496 497 502 replace : function( dialog, pattern, newString, matchCase, matchWord, 498 503 matchCyclic, matchReplaceAll ) 499 504 { 500 // Successiveness of current replace/find. 505 506 // Success of current replace/find. 501 507 var result = false; 502 508 503 509 // 1. Perform the replace when there's already a match here. … … 530 536 else 531 537 result = this.find( pattern, matchCase, matchWord, matchCyclic ); 532 538 533 // Recu sively replace all matches.539 // Recursively replace all matches. 534 540 if ( matchReplaceAll && result ) 535 541 this.replace.apply( this, Array.prototype.slice.call( arguments ) ); 536 542 … … 540 546 }; 541 547 542 548 /** 543 * The range in which find/replace happened, receive from user 544 * selection prior. 549 * The range in which find/replace happened. 545 550 */ 546 function getSearchRange( isDefault)551 function getSearchRange( start, end ) 547 552 { 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 ); 562 558 return searchRange; 563 559 } 564 560 … … 698 694 var replaceNums; 699 695 700 696 finder.replaceCounter = 0; 697 finder.fullCoverage = null; 701 698 if ( ( replaceNums = finder.replace( dialog, 702 699 dialog.getValueOf( 'replace', 'txtFindReplace' ), 703 700 dialog.getValueOf( 'replace', 'txtReplace' ), … … 794 791 }, 795 792 onShow : function() 796 793 { 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() ); 799 797 800 798 if ( startupPage == 'replace' ) 801 799 this.getContentElement( 'replace', 'txtFindReplace' ).focus();