X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Ffind%2Fdialogs%2Ffind.js;h=bc9f8a4317db5d81e62c08e629b98fb752613878;hb=e371ddf8abcb89013e20e6d0dd746adec344d0e5;hp=dd7048cf76f9017f966a076a658bd529118236d7;hpb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1;p=ckeditor.git diff --git a/_source/plugins/find/dialogs/find.js b/_source/plugins/find/dialogs/find.js index dd7048c..bc9f8a4 100644 --- a/_source/plugins/find/dialogs/find.js +++ b/_source/plugins/find/dialogs/find.js @@ -5,15 +5,17 @@ For licensing, see LICENSE.html or http://ckeditor.com/license (function() { - function nonEmptyText( 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 nonCharactersBoundary ( node ) + function nonCharactersBoundary( node ) { return !( node.type == CKEDITOR.NODE_ELEMENT && node.isBlockBoundary( CKEDITOR.tools.extend( {}, CKEDITOR.dtd.$empty, CKEDITOR.dtd.$nonEditable ) ) ); @@ -84,7 +86,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var walker = new CKEDITOR.dom.walker( range ); walker.guard = matchWord ? nonCharactersBoundary : null; - walker[ 'evaluator' ] = nonEmptyText; + walker[ 'evaluator' ] = findEvaluator; walker.breakOnFalse = true; this._ = { @@ -251,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. @@ -273,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(), @@ -324,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 @@ -514,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(); @@ -550,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; } };