/*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
For licensing, see LICENSE.html or http://ckeditor.com/license\r
*/\r
\r
{\r
var currentTextNode = this.textNode;\r
// Already at the end of document, no more character available.\r
- if( currentTextNode === null )\r
+ if ( currentTextNode === null )\r
return cursorStep.call( this );\r
\r
this._.matchBoundary = false;\r
\r
// There are more characters in the text node, step forward.\r
- if( currentTextNode\r
+ if ( currentTextNode\r
&& rtl\r
&& this.offset > 0 )\r
{\r
this.offset--;\r
return cursorStep.call( this );\r
}\r
- else if( currentTextNode\r
+ else if ( currentTextNode\r
&& this.offset < currentTextNode.getLength() - 1 )\r
{\r
this.offset++;\r
break;\r
\r
// Marking as match character boundaries.\r
- if( !currentTextNode\r
+ if ( !currentTextNode\r
&& checkCharactersBoundary( this._.walker.current ) )\r
this._.matchBoundary = true;\r
\r
getNextCharacterRange : function( maxLength )\r
{\r
var lastCursor,\r
+ nextRangeWalker,\r
cursors = this._.cursors;\r
- if ( !( lastCursor = cursors[ cursors.length - 1 ] ) )\r
- return null;\r
- return new characterRange(\r
- new characterWalker(\r
- getRangeAfterCursor( lastCursor ) ),\r
- maxLength );\r
+\r
+ if ( ( lastCursor = cursors[ cursors.length - 1 ] ) )\r
+ nextRangeWalker = new characterWalker( getRangeAfterCursor( lastCursor ) );\r
+ // In case it's an empty range (no cursors), figure out next range from walker (#4951).\r
+ else\r
+ nextRangeWalker = this._.walker;\r
+\r
+ return new characterRange( nextRangeWalker, maxLength );\r
},\r
\r
getCursors : function()\r
var finder = {\r
searchRange : null,\r
matchRange : null,\r
- find : function( pattern, matchCase, matchWord, matchCyclic, highlightMatched )\r
+ find : function( pattern, matchCase, matchWord, matchCyclic, highlightMatched, cyclicRerun )\r
{\r
- if( !this.matchRange )\r
+ if ( !this.matchRange )\r
this.matchRange =\r
new characterRange(\r
new characterWalker( this.searchRange ),\r
this.matchRange.removeHighlight();\r
// Clear current session and restart with the default search\r
// range.\r
- if ( matchCyclic )\r
+ // Re-run the finding once for cyclic.(#3517)\r
+ if ( matchCyclic && !cyclicRerun )\r
{\r
this.searchRange = getSearchRange( true );\r
this.matchRange = null;\r
+ return arguments.callee.apply( this,\r
+ Array.prototype.slice.call( arguments ).concat( [ true ] ) );\r
}\r
\r
return false;\r
finder.matchRange = null;\r
}\r
editor.fire( 'saveSnapshot' );\r
- while( finder.replace( dialog,\r
+ while ( finder.replace( dialog,\r
dialog.getValueOf( 'replace', 'txtFindReplace' ),\r
dialog.getValueOf( 'replace', 'txtReplace' ),\r
dialog.getValueOf( 'replace', 'txtReplaceCaseChk' ),\r
currPage.initialized = true;\r
}\r
\r
- if( isUserSelect )\r
+ if ( isUserSelect )\r
// synchronize fields on tab switch.\r
syncFieldsBetweenTabs.call( this, pageId );\r
};\r
// Establish initial searching start position.\r
finder.searchRange = getSearchRange();\r
\r
- if ( startupPage == 'replace' )\r
- this.getContentElement( 'replace', 'txtFindReplace' ).focus();\r
- else\r
- this.getContentElement( 'find', 'txtFindFind' ).focus();\r
+ this.selectPage( startupPage );\r
},\r
onHide : function()\r
{\r
\r
// Clear current session before dialog close\r
delete finder.matchRange;\r
+ },\r
+ onFocus : function()\r
+ {\r
+ if ( startupPage == 'replace' )\r
+ return this.getContentElement( 'replace', 'txtFindReplace' );\r
+ else\r
+ return this.getContentElement( 'find', 'txtFindFind' );\r
}\r
};\r
};\r