X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Ffind%2Fdialogs%2Ffind.js;h=dd7048cf76f9017f966a076a658bd529118236d7;hb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1;hp=ead43bf297293873d62943f3ec05e6b70d1fadbe;hpb=c6e377a02b54abc07129d72b632763c727476a15;p=ckeditor.git diff --git a/_source/plugins/find/dialogs/find.js b/_source/plugins/find/dialogs/find.js index ead43bf..dd7048c 100644 --- a/_source/plugins/find/dialogs/find.js +++ b/_source/plugins/find/dialogs/find.js @@ -5,7 +5,7 @@ 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._ = { @@ -143,7 +145,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Marking as match character boundaries. if ( !currentTextNode - && checkCharactersBoundary( this._.walker.current ) ) + && !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; }, /** @@ -816,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' ); } }; };