Ticket #3515: 3515.patch
File 3515.patch, 5.1 KB (added by , 15 years ago) |
---|
-
_source/plugins/find/dialogs/find.js
26 26 */ 27 27 var cursorStep = function() 28 28 { 29 var obj ={29 return { 30 30 textNode : this.textNode, 31 31 offset : this.offset, 32 32 character : this.textNode ? 33 33 this.textNode.getText().charAt( this.offset ) : null, 34 34 hitMatchBoundary : this._.matchBoundary 35 35 }; 36 return obj;37 36 }; 38 37 39 38 var pages = [ 'find', 'replace' ], … … 72 71 var highlightStyle = new CKEDITOR.style( editor.config.find_highlight ); 73 72 74 73 /** 75 * Iterator which walk through document char by char. 76 * @param {Object} start 77 * @param {Number} offset 78 * @param {Boolean} isStrict 74 * Iterator which walk through the specified range char by char. By 75 * default the walking will not stop at the character boundaries, until 76 * the end of the range is encountered. 77 * @param { CKEDITOR.dom.range } range 78 * @param {Boolean} matchWord Whether the walking will stop at character boundary. 79 79 */ 80 80 var characterWalker = function( range , matchWord ) 81 81 { … … 193 193 range.setEnd( last.textNode, last.offset + 1 ); 194 194 return range; 195 195 }, 196 196 /** 197 * Reflect the latest changes from dom range. 198 */ 197 199 updateFromDomRange : function( domRange ) 198 200 { 199 var startNode = domRange.startContainer,200 startIndex = domRange.startOffset,201 endNode = domRange.endContainer,202 endIndex = domRange.endOffset,203 boundaryNodes = domRange.getBoundaryNodes();204 205 if ( startNode.type != CKEDITOR.NODE_TEXT )206 {207 startNode = boundaryNodes.startNode;208 while ( startNode.type != CKEDITOR.NODE_TEXT )209 startNode = startNode.getFirst();210 startIndex = 0;211 }212 213 if ( endNode.type != CKEDITOR.NODE_TEXT )214 {215 endNode = boundaryNodes.endNode;216 while ( endNode.type != CKEDITOR.NODE_TEXT )217 endNode = endNode.getLast();218 endIndex = endNode.getLength();219 }220 221 // If the endNode is an empty text node, our walker would just walk through222 // it without stopping. So need to backtrack to the nearest non-emtpy text223 // node.224 if ( endNode.getLength() < 1 )225 {226 while ( ( endNode = endNode.getPreviousSourceNode() )227 && !( endNode.type == CKEDITOR.NODE_TEXT228 && endNode.getLength() > 0 ) )229 { /*jsl:pass*/ }230 231 endIndex = endNode.getLength();232 }233 234 // Rebuild the character range.235 201 var cursor, 236 walker = new characterWalker( 237 getRangeAfterCursor( 238 ( { textNode: startNode, offset : startIndex } ), 239 true ) ); 202 walker = new characterWalker( domRange ); 240 203 this._.cursors = []; 241 204 do 242 205 { 243 206 cursor = walker.next(); 244 this._.cursors.push( cursor ); 207 if ( cursor.character ) 208 this._.cursors.push( cursor ); 245 209 } 246 while ( !( cursor.textNode.equals( endNode ) 247 && cursor.offset == endIndex - 1 ) ); 210 while ( cursor.character ); 248 211 this._.rangeLength = this._.cursors.length; 249 212 }, 250 213 … … 439 402 this._.state = this._.overlap[ this._.state ]; 440 403 } 441 404 442 return null;443 405 }, 444 406 445 407 reset : function() … … 535 497 replace : function( dialog, pattern, newString, matchCase, matchWord, 536 498 matchCyclic, matchReplaceAll ) 537 499 { 538 var replaceResult = false; 539 if ( this.range && this.range.isMatched() ) 500 // Successiveness of current replace/find. 501 var result = false; 502 503 // 1. Perform the replace when there's already a match here. 504 // 2. Otherwise perform the find but don't replace it immediately. 505 if ( this.matchRange && this.matchRange.isMatched() ) 540 506 { 541 var domRange = this. range.toDomRange();507 var domRange = this.matchRange.toDomRange(); 542 508 var text = editor.document.createText( newString ); 543 509 domRange.deleteContents(); 544 510 domRange.insertNode( text ); 545 this. range.updateFromDomRange( domRange );546 511 this.matchRange.updateFromDomRange( domRange ); 512 this.matchRange._.isMatched = false; 547 513 this.replaceCounter++; 548 re placeResult = true;514 result = true; 549 515 } 550 551 var findResult = this.find( pattern, matchCase, matchWord, matchCyclic ); 552 if ( findResult && matchReplaceAll ) 516 else 517 result = this.find( pattern, matchCase, matchWord, matchCyclic ); 518 519 // Recusively replace all matches. 520 if ( matchReplaceAll && result ) 553 521 this.replace.apply( this, Array.prototype.slice.call( arguments ) ); 522 554 523 return matchReplaceAll ? 555 this.replaceCounter : re placeResult || findResult;524 this.replaceCounter : result; 556 525 } 557 526 }; 558 527 559 528 /** 560 * Get the default cursor which is the start of this document.561 */562 function getDefaultStartCursor()563 {564 return { textNode : editor.document.getBody(), offset: 0 };565 }566 567 /**568 529 * The range in which find/replace happened, receive from user 569 530 * selection prior. 570 531 */