Ticket #3790: 3790_4.patch
File 3790_4.patch, 7.7 KB (added by , 13 years ago) |
---|
-
_source/plugins/find/dialogs/find.js
214 214 setMatched : function() 215 215 { 216 216 this._.isMatched = true; 217 this.highlight();218 217 }, 219 218 220 219 clearMatched : function() 221 220 { 222 221 this._.isMatched = false; 223 this.removeHighlight();224 222 }, 225 223 226 224 isMatched : function() … … 427 425 var finder = { 428 426 searchRange : null, 429 427 matchRange : null, 430 find : function( pattern, matchCase, matchWord, matchCyclic )428 find : function( pattern, matchCase, matchWord, matchCyclic, highlightMatched ) 431 429 { 432 430 if( !this.matchRange ) 433 431 this.matchRange = … … 471 469 && isWordSeparator( tailWalker.next().character ) ) ) 472 470 continue; 473 471 } 474 475 472 this.matchRange.setMatched(); 473 if ( highlightMatched !== false ) 474 this.matchRange.highlight(); 476 475 return true; 477 476 } 478 477 } … … 496 495 replaceCounter : 0, 497 496 498 497 replace : function( dialog, pattern, newString, matchCase, matchWord, 499 matchCyclic , matchReplaceAll )498 matchCyclic , isReplaceAll ) 500 499 { 501 500 // Successiveness of current replace/find. 502 501 var result = false; … … 510 509 this.matchRange.removeHighlight(); 511 510 var domRange = this.matchRange.toDomRange(); 512 511 var text = editor.document.createText( newString ); 513 514 // Save undo snaps before and after the replacement. 515 var selection = editor.getSelection(); 516 selection.selectRanges( [ domRange ] ); 517 editor.fire( 'saveSnapshot' ); 518 512 if ( !isReplaceAll ) 513 { 514 // Save undo snaps before and after the replacement. 515 var selection = editor.getSelection(); 516 selection.selectRanges( [ domRange ] ); 517 editor.fire( 'saveSnapshot' ); 518 } 519 519 domRange.deleteContents(); 520 520 domRange.insertNode( text ); 521 522 selection.selectRanges( [ domRange ] ); 523 editor.fire( 'saveSnapshot' ); 524 521 if ( !isReplaceAll ) 522 { 523 selection.selectRanges( [ domRange ] ); 524 editor.fire( 'saveSnapshot' ); 525 } 525 526 this.matchRange.updateFromDomRange( domRange ); 526 this.matchRange.highlight(); 527 if ( !isReplaceAll ) 528 this.matchRange.highlight(); 527 529 this.matchRange._.isReplaced = true; 528 530 this.replaceCounter++; 529 531 result = true; 530 532 } 531 533 else 532 result = this.find( pattern, matchCase, matchWord, matchCyclic );534 result = this.find( pattern, matchCase, matchWord, matchCyclic, !isReplaceAll ); 533 535 534 // Recusively replace all matches. 535 if ( matchReplaceAll && result ) 536 this.replace.apply( this, Array.prototype.slice.call( arguments ) ); 537 538 return matchReplaceAll ? 539 this.replaceCounter : result; 536 return result; 540 537 } 541 538 }; 542 539 … … 702 699 703 700 // Scope to full document. 704 701 finder.searchRange = getSearchRange( true ); 705 finder.matchRange = null; 706 if ( ( replaceNums = finder.replace( dialog, 702 if ( finder.matchRange ) 703 { 704 finder.matchRange.removeHighlight(); 705 finder.matchRange = null; 706 } 707 editor.fire( 'saveSnapshot' ); 708 while( finder.replace( dialog, 707 709 dialog.getValueOf( 'replace', 'txtFindReplace' ), 708 710 dialog.getValueOf( 'replace', 'txtReplace' ), 709 711 dialog.getValueOf( 'replace', 'txtReplaceCaseChk' ), 710 712 dialog.getValueOf( 'replace', 'txtReplaceWordChk' ), 711 false, true ) ) ) 712 alert( editor.lang.findAndReplace.replaceSuccessMsg.replace( /%1/, replaceNums ) ); 713 false, true ) ) 714 ; 715 716 if ( finder.replaceCounter ) 717 { 718 alert( editor.lang.findAndReplace.replaceSuccessMsg.replace( /%1/, finder.replaceCounter ) ); 719 editor.fire( 'saveSnapshot' ); 720 } 713 721 else 714 722 alert( editor.lang.findAndReplace.notFoundMsg ); 715 723 } -
_source/tests/core/dom/range.html
2188 2188 assert.areEqual( range.endOffset, 2 ); 2189 2189 }, 2190 2190 2191 /** 2192 * Trim range which collapsed at text node boundary. 2193 */ 2194 test_trim_3790 : function() 2195 { 2196 2197 var ct = doc.getById( '_trim_ct'); 2198 ct.setHtml( '<span id="_SPAN1">text</span>' ); 2199 var text = doc.getById( '_trim_ct').getFirst(); 2200 2201 // <span id="_SPAN1">text^</span> 2202 var range = new CKEDITOR.dom.range(); 2203 range.setStartAt( doc.getById( '_SPAN1' ).getFirst(), CKEDITOR.POSITION_BEFORE_END ); 2204 range.collapse( true ); 2205 range.trim( true ); 2206 2207 // <span id="_SPAN1">text^</span> 2208 assert.isTrue( range.collapsed ); 2209 assert.areEqual( doc.getById( '_SPAN1').$, range.startContainer.$ ); 2210 assert.areEqual( range.startOffset, 1 ); 2211 }, 2212 2213 /** 2214 * Trim range which collapsed inside text node. 2215 */ 2216 test_trim_3790_2 : function() 2217 { 2218 2219 var ct = doc.getById( '_trim_ct'); 2220 ct.setHtml( '<span id="_SPAN1">text</span>' ); 2221 var text = doc.getById( '_trim_ct').getFirst(); 2222 2223 // <span id="_SPAN1">te^xt</span> 2224 var range = new CKEDITOR.dom.range(); 2225 range.setStart( doc.getById( '_SPAN1' ).getFirst(), 2 ); 2226 range.collapse( true ); 2227 range.trim( true ); 2228 2229 // <span id="_SPAN1">te^xt</span> 2230 assert.isTrue( range.collapsed ); 2231 assert.areEqual( doc.getById( '_SPAN1').$, range.startContainer.$ ); 2232 assert.areEqual( range.startOffset, 1 ); 2233 }, 2191 2234 ///////////// 2192 2235 2193 2236 setUp : function() … … 2200 2243 }; 2201 2244 })() ); 2202 2245 2203 //window.onload = function() 2204 //{ 2205 // tests.test_createBookmark2_3(); 2206 //} 2207 2246 //window.onload = tests.test_trim; 2208 2247 //]]> 2209 2248 </script> 2210 2249 </head> -
_source/core/dom/range.js
703 703 704 704 trim : function( ignoreStart, ignoreEnd ) 705 705 { 706 var startContainer = this.startContainer; 707 var startOffset = this.startOffset; 708 709 if ( !ignoreStart && startContainer && startContainer.type == CKEDITOR.NODE_TEXT ) 706 var startContainer = this.startContainer, 707 startOffset = this.startOffset, 708 collapsed = this.collapsed; 709 if ( ( !ignoreStart || collapsed ) 710 && startContainer && startContainer.type == CKEDITOR.NODE_TEXT ) 710 711 { 711 712 // If the offset is zero, we just insert the new node before 712 713 // the start. … … 730 731 731 732 startOffset = startContainer.getIndex() + 1; 732 733 startContainer = startContainer.getParent(); 733 734 734 // Check if it is necessary to update the end boundary. 735 if ( this.collapsed ) 736 this.setEnd( startContainer, startOffset ); 737 else if ( this.startContainer.equals( this.endContainer ) ) 735 if ( !collapsed && this.startContainer.equals( this.endContainer ) ) 738 736 this.setEnd( nextText, this.endOffset - this.startOffset ); 739 737 } 740 738 741 739 this.setStart( startContainer, startOffset ); 740 741 if ( collapsed ) 742 this.collapse( true ); 742 743 } 743 744 744 745 var endContainer = this.endContainer; 745 746 var endOffset = this.endOffset; 746 747 747 if ( !ignoreEnd && endContainer && !this.collapsed && endContainer.type == CKEDITOR.NODE_TEXT ) 748 if ( ! ( ignoreEnd || this.collapsed ) 749 && endContainer && endContainer.type == CKEDITOR.NODE_TEXT ) 748 750 { 749 751 // If the offset is zero, we just insert the new node before 750 752 // the start.