X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Ffind%2Fdialogs%2Ffind.js;h=bc9f8a4317db5d81e62c08e629b98fb752613878;hb=refs%2Ftags%2Fv3.4;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..bc9f8a4 100644 --- a/_source/plugins/find/dialogs/find.js +++ b/_source/plugins/find/dialogs/find.js @@ -5,19 +5,20 @@ For licensing, see LICENSE.html or http://ckeditor.com/license (function() { - function guardDomWalkerNonEmptyTextNode( node ) + var isReplace; + + function findEvaluator( node ) { - return ( node.type == CKEDITOR.NODE_TEXT && node.getLength() > 0 ); + return node.type == CKEDITOR.NODE_TEXT && node.getLength() > 0 && ( !isReplace || !node.isReadOnly() ); } /** * 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 +68,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 +85,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' ] = findEvaluator; walker.breakOnFalse = true; this._ = { @@ -143,7 +147,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 +185,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; }, /** @@ -240,8 +253,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license this.removeHighlight(); // Apply the highlight. - var range = this.toDomRange(); + var range = this.toDomRange(), + bookmark = range.createBookmark(); highlightStyle.applyToRange( range ); + range.moveToBookmark( bookmark ); this._.highlightRange = range; // Scroll the editor to the highlighted area. @@ -262,11 +277,21 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( !this._.highlightRange ) return; + var bookmark = this._.highlightRange.createBookmark(); highlightStyle.removeFromRange( this._.highlightRange ); + this._.highlightRange.moveToBookmark( bookmark ); this.updateFromDomRange( this._.highlightRange ); this._.highlightRange = null; }, + isReadOnly : function() + { + if ( !this._.highlightRange ) + return 0; + + return this._.highlightRange.startContainer.isReadOnly(); + }, + moveBack : function() { var retval = this._.walker.back(), @@ -313,7 +338,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license nextRangeWalker, cursors = this._.cursors; - if ( ( lastCursor = cursors[ cursors.length - 1 ] ) ) + 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 @@ -503,13 +528,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license replace : function( dialog, pattern, newString, matchCase, matchWord, matchCyclic , isReplaceAll ) { + isReplace = 1; + // Successiveness of current replace/find. var result = false; // 1. Perform the replace when there's already a match here. // 2. Otherwise perform the find but don't replace it immediately. if ( this.matchRange && this.matchRange.isMatched() - && !this.matchRange._.isReplaced ) + && !this.matchRange._.isReplaced && !this.matchRange.isReadOnly() ) { // Turn off highlight for a while when saving snapshots. this.matchRange.removeHighlight(); @@ -539,6 +566,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license else result = this.find( pattern, matchCase, matchWord, matchCyclic, !isReplaceAll ); + isReplace = 0; + return result; } }; @@ -816,23 +845,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' ); } }; };