X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Ffind%2Fdialogs%2Ffind.js;h=70a082cc9cdfef9857ae5bed50f8c79a556c6bfc;hb=059b4c2fef02528bf1af189f7996e80652faddfb;hp=cc1c2c1a78445e35a66919c6a8bd0d519816e1e8;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;p=ckeditor.git diff --git a/_source/plugins/find/dialogs/find.js b/_source/plugins/find/dialogs/find.js index cc1c2c1..70a082c 100644 --- a/_source/plugins/find/dialogs/find.js +++ b/_source/plugins/find/dialogs/find.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -107,20 +107,20 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { var currentTextNode = this.textNode; // Already at the end of document, no more character available. - if( currentTextNode === null ) + if ( currentTextNode === null ) return cursorStep.call( this ); this._.matchBoundary = false; // There are more characters in the text node, step forward. - if( currentTextNode + if ( currentTextNode && rtl && this.offset > 0 ) { this.offset--; return cursorStep.call( this ); } - else if( currentTextNode + else if ( currentTextNode && this.offset < currentTextNode.getLength() - 1 ) { this.offset++; @@ -142,7 +142,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license break; // Marking as match character boundaries. - if( !currentTextNode + if ( !currentTextNode && checkCharactersBoundary( this._.walker.current ) ) this._.matchBoundary = true; @@ -310,13 +310,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license getNextCharacterRange : function( maxLength ) { var lastCursor, + nextRangeWalker, cursors = this._.cursors; - if ( !( lastCursor = cursors[ cursors.length - 1 ] ) ) - return null; - return new characterRange( - new characterWalker( - getRangeAfterCursor( lastCursor ) ), - maxLength ); + + if ( ( lastCursor = cursors[ cursors.length - 1 ] ) ) + nextRangeWalker = new characterWalker( getRangeAfterCursor( lastCursor ) ); + // In case it's an empty range (no cursors), figure out next range from walker (#4951). + else + nextRangeWalker = this._.walker; + + return new characterRange( nextRangeWalker, maxLength ); }, getCursors : function() @@ -425,9 +428,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var finder = { searchRange : null, matchRange : null, - find : function( pattern, matchCase, matchWord, matchCyclic, highlightMatched ) + find : function( pattern, matchCase, matchWord, matchCyclic, highlightMatched, cyclicRerun ) { - if( !this.matchRange ) + if ( !this.matchRange ) this.matchRange = new characterRange( new characterWalker( this.searchRange ), @@ -480,10 +483,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license this.matchRange.removeHighlight(); // Clear current session and restart with the default search // range. - if ( matchCyclic ) + // Re-run the finding once for cyclic.(#3517) + if ( matchCyclic && !cyclicRerun ) { this.searchRange = getSearchRange( true ); this.matchRange = null; + return arguments.callee.apply( this, + Array.prototype.slice.call( arguments ).concat( [ true ] ) ); } return false; @@ -705,7 +711,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license finder.matchRange = null; } editor.fire( 'saveSnapshot' ); - while( finder.replace( dialog, + while ( finder.replace( dialog, dialog.getValueOf( 'replace', 'txtFindReplace' ), dialog.getValueOf( 'replace', 'txtReplace' ), dialog.getValueOf( 'replace', 'txtReplaceCaseChk' ), @@ -798,7 +804,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license currPage.initialized = true; } - if( isUserSelect ) + if ( isUserSelect ) // synchronize fields on tab switch. syncFieldsBetweenTabs.call( this, pageId ); }; @@ -810,10 +816,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Establish initial searching start position. finder.searchRange = getSearchRange(); - if ( startupPage == 'replace' ) - this.getContentElement( 'replace', 'txtFindReplace' ).focus(); - else - this.getContentElement( 'find', 'txtFindFind' ).focus(); + this.selectPage( startupPage ); }, onHide : function() { @@ -827,6 +830,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Clear current session before dialog close delete finder.matchRange; + }, + onFocus : function() + { + if ( startupPage == 'replace' ) + return this.getContentElement( 'replace', 'txtFindReplace' ); + else + return this.getContentElement( 'find', 'txtFindFind' ); } }; };