JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.2.1
[ckeditor.git] / _source / plugins / find / dialogs / find.js
index 70a082c..dd7048c 100644 (file)
@@ -5,7 +5,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
 (function()\r
 {\r
-       function guardDomWalkerNonEmptyTextNode( node )\r
+       function nonEmptyText( node )\r
        {\r
                return ( node.type == CKEDITOR.NODE_TEXT && node.getLength() > 0 );\r
        }\r
@@ -13,11 +13,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        /**\r
         * Elements which break characters been considered as sequence.\r
        */\r
-       function checkCharactersBoundary ( node )\r
+       function nonCharactersBoundary ( node )\r
        {\r
-               var dtd = CKEDITOR.dtd;\r
-               return node.isBlockBoundary(\r
-                       CKEDITOR.tools.extend( {}, dtd.$empty, dtd.$nonEditable ) );\r
+               return !( node.type == CKEDITOR.NODE_ELEMENT && node.isBlockBoundary(\r
+                       CKEDITOR.tools.extend( {}, CKEDITOR.dtd.$empty, CKEDITOR.dtd.$nonEditable ) ) );\r
        }\r
 \r
        /**\r
@@ -67,8 +66,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
        var findDialog = function( editor, startupPage )\r
        {\r
-               // Style object for highlights.\r
-               var highlightStyle = new CKEDITOR.style( editor.config.find_highlight );\r
+               // Style object for highlights: (#5018)\r
+               // 1. Defined as full match style to avoid compromising ordinary text color styles.\r
+               // 2. Must be apply onto inner-most text to avoid conflicting with ordinary text color styles visually.\r
+               var highlightStyle = new CKEDITOR.style( CKEDITOR.tools.extend( { fullMatch : true, childRule : function(){ return false; } },\r
+                       editor.config.find_highlight ) );\r
 \r
                /**\r
                 * Iterator which walk through the specified range char by char. By\r
@@ -81,8 +83,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                {\r
                        var walker =\r
                                new CKEDITOR.dom.walker( range );\r
-                       walker[ matchWord ? 'guard' : 'evaluator' ] =\r
-                               guardDomWalkerNonEmptyTextNode;\r
+                       walker.guard = matchWord ? nonCharactersBoundary : null;\r
+                       walker[ 'evaluator' ] = nonEmptyText;\r
                        walker.breakOnFalse = true;\r
 \r
                        this._ = {\r
@@ -143,7 +145,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                                // Marking as match character boundaries.\r
                                                if ( !currentTextNode\r
-                                                  && checkCharactersBoundary( this._.walker.current ) )\r
+                                                  && !nonCharactersBoundary( this._.walker.current ) )\r
                                                        this._.matchBoundary = true;\r
 \r
                                        }\r
@@ -181,16 +183,25 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                         */\r
                        toDomRange : function()\r
                        {\r
+                               var range = new CKEDITOR.dom.range( editor.document );\r
                                var cursors = this._.cursors;\r
                                if ( cursors.length < 1 )\r
-                                       return null;\r
+                               {\r
+                                       var textNode = this._.walker.textNode;\r
+                                       if ( textNode )\r
+                                                       range.setStartAfter( textNode );\r
+                                       else\r
+                                               return null;\r
+                               }\r
+                               else\r
+                               {\r
+                                       var first = cursors[0],\r
+                                                       last = cursors[ cursors.length - 1 ];\r
 \r
-                               var first = cursors[0],\r
-                                       last = cursors[ cursors.length - 1 ],\r
-                                       range = new CKEDITOR.dom.range( editor.document );\r
+                                       range.setStart( first.textNode, first.offset );\r
+                                       range.setEnd( last.textNode, last.offset + 1 );\r
+                               }\r
 \r
-                               range.setStart( first.textNode, first.offset );\r
-                               range.setEnd( last.textNode, last.offset + 1 );\r
                                return range;\r
                        },\r
                        /**\r
@@ -820,12 +831,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        },\r
                        onHide : function()\r
                        {\r
+                               var range;\r
                                if ( finder.matchRange && finder.matchRange.isMatched() )\r
                                {\r
                                        finder.matchRange.removeHighlight();\r
                                        editor.focus();\r
-                                       editor.getSelection().selectRanges(\r
-                                               [ finder.matchRange.toDomRange() ] );\r
+\r
+                                       range = finder.matchRange.toDomRange();\r
+                                       if ( range )\r
+                                               editor.getSelection().selectRanges( [ range ] );\r
                                }\r
 \r
                                // Clear current session before dialog close\r