X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Ffind%2Fdialogs%2Ffind.js;h=8b668397955bb453ab4d7a582e836d786561506a;hb=66f4ae0bf0280ed56bf7c0f4ab175424dd1d47a0;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..8b66839 100644 --- a/_source/plugins/find/dialogs/find.js +++ b/_source/plugins/find/dialogs/find.js @@ -1,11 +1,11 @@ /* -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 */ (function() { - function guardDomWalkerNonEmptyTextNode( node ) + function nonEmptyText( node ) { return ( node.type == CKEDITOR.NODE_TEXT && node.getLength() > 0 ); } @@ -13,11 +13,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license /** * Elements which break characters been considered as sequence. */ - function checkCharactersBoundary ( node ) + function nonCharactersBoundary ( node ) { - var dtd = CKEDITOR.dtd; - return node.isBlockBoundary( - CKEDITOR.tools.extend( {}, dtd.$empty, dtd.$nonEditable ) ); + return !( node.type == CKEDITOR.NODE_ELEMENT && node.isBlockBoundary( + CKEDITOR.tools.extend( {}, CKEDITOR.dtd.$empty, CKEDITOR.dtd.$nonEditable ) ) ); } /** @@ -67,8 +66,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var findDialog = function( editor, startupPage ) { - // Style object for highlights. - var highlightStyle = new CKEDITOR.style( editor.config.find_highlight ); + // Style object for highlights: (#5018) + // 1. Defined as full match style to avoid compromising ordinary text color styles. + // 2. Must be apply onto inner-most text to avoid conflicting with ordinary text color styles visually. + var highlightStyle = new CKEDITOR.style( CKEDITOR.tools.extend( { fullMatch : true, childRule : function(){ return false; } }, + editor.config.find_highlight ) ); /** * Iterator which walk through the specified range char by char. By @@ -81,8 +83,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { var walker = new CKEDITOR.dom.walker( range ); - walker[ matchWord ? 'guard' : 'evaluator' ] = - guardDomWalkerNonEmptyTextNode; + walker.guard = matchWord ? nonCharactersBoundary : null; + walker[ 'evaluator' ] = nonEmptyText; walker.breakOnFalse = true; this._ = { @@ -107,20 +109,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,8 +144,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license break; // Marking as match character boundaries. - if( !currentTextNode - && checkCharactersBoundary( this._.walker.current ) ) + if ( !currentTextNode + && !nonCharactersBoundary( this._.walker.current ) ) this._.matchBoundary = true; } @@ -181,16 +183,25 @@ For licensing, see LICENSE.html or http://ckeditor.com/license */ toDomRange : function() { + var range = new CKEDITOR.dom.range( editor.document ); var cursors = this._.cursors; if ( cursors.length < 1 ) - return null; + { + var textNode = this._.walker.textNode; + if ( textNode ) + range.setStartAfter( textNode ); + else + return null; + } + else + { + var first = cursors[0], + last = cursors[ cursors.length - 1 ]; - var first = cursors[0], - last = cursors[ cursors.length - 1 ], - range = new CKEDITOR.dom.range( editor.document ); + range.setStart( first.textNode, first.offset ); + range.setEnd( last.textNode, last.offset + 1 ); + } - range.setStart( first.textNode, first.offset ); - range.setEnd( last.textNode, last.offset + 1 ); return range; }, /** @@ -310,13 +321,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 ] ) && lastCursor.textNode ) + 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 +439,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 +494,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 +722,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 +815,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,23 +827,30 @@ 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() { + var range; if ( finder.matchRange && finder.matchRange.isMatched() ) { finder.matchRange.removeHighlight(); editor.focus(); - editor.getSelection().selectRanges( - [ finder.matchRange.toDomRange() ] ); + + range = finder.matchRange.toDomRange(); + if ( range ) + editor.getSelection().selectRanges( [ range ] ); } // 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' ); } }; };