Ticket #6957: 6957.patch

File 6957.patch, 5.5 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/find/dialogs/find.js

     
    6868
    6969        var findDialog = function( editor, startupPage )
    7070        {
    71                 // Style object for highlights: (#5018)
    72                 // 1. Defined as full match style to avoid compromising ordinary text color styles.
    73                 // 2. Must be apply onto inner-most text to avoid conflicting with ordinary text color styles visually.
    74                 var highlightStyle = new CKEDITOR.style( CKEDITOR.tools.extend( { fullMatch : true, childRule : function(){ return 0; } },
    75                         editor.config.find_highlight ) );
    76 
    7771                /**
    7872                 * Iterator which walk through the specified range char by char. By
    7973                 * default the walking will not stop at the character boundaries, until
     
    252246                                if ( this._.cursors.length < 1 )
    253247                                        return;
    254248
    255                                 // Remove the previous highlight if there's one.
    256                                 if ( this._.highlightRange )
    257                                         this.removeHighlight();
     249                                var range = this.toDomRange();
     250                                range.select();
    258251
    259                                 // Apply the highlight.
    260                                 var range = this.toDomRange(),
    261                                         bookmark = range.createBookmark();
    262                                 highlightStyle.applyToRange( range );
    263                                 range.moveToBookmark( bookmark );
    264                                 this._.highlightRange = range;
    265 
    266                                 // Scroll the editor to the highlighted area.
    267                                 var element = range.startContainer;
    268                                 if ( element.type != CKEDITOR.NODE_ELEMENT )
    269                                         element = element.getParent();
    270                                 element.scrollIntoView();
    271 
    272                                 // Update the character cursors.
    273                                 this.updateFromDomRange( range );
    274                         },
     252                                if ( !CKEDITOR.env.ie )
     253                                {
     254                                        // Scroll the range into view for non-IEs.
     255                                        var root = range.getCommonAncestor( 1, 1 );
     256                                        root.scrollIntoView();
     257                                }
     258                                else
     259                                {
     260                                        // Update the character range in IE
     261                                        // after making a selection.
     262                                        this.updateFromDomRange( range );
     263                                }
    275264
    276                         /**
    277                          * Remove highlighted find result.
    278                          */
    279                         removeHighlight : function()
    280                         {
    281                                 if ( !this._.highlightRange )
    282                                         return;
    283 
    284                                 var bookmark = this._.highlightRange.createBookmark();
    285                                 highlightStyle.removeFromRange( this._.highlightRange );
    286                                 this._.highlightRange.moveToBookmark( bookmark );
    287                                 this.updateFromDomRange( this._.highlightRange );
    288                                 this._.highlightRange = null;
     265                                this._.highlightRange = range;
    289266                        },
    290267
    291268                        isReadOnly : function()
    292269                        {
    293                                 if ( !this._.highlightRange )
    294                                         return 0;
    295 
    296270                                return this._.highlightRange.startContainer.isReadOnly();
    297271                        },
    298272
     
    454428                                || wordSeparatorRegex.test( c );
    455429                };
    456430
     431                function toggleDesignMode( on )
     432                {
     433                        if ( CKEDITOR.env.ie && editor.mode == 'wysiwyg' )
     434                                editor.document.getBody().$.contentEditable = !!on;
     435                }
     436
    457437                var finder = {
    458438                        searchRange : null,
    459439                        matchRange : null,
     
    466446                                                        pattern.length );
    467447                                else
    468448                                {
    469                                         this.matchRange.removeHighlight();
    470449                                        this.matchRange = this.matchRange.getNextCharacterRange( pattern.length );
    471450                                }
    472451
     
    509488                                }
    510489
    511490                                this.matchRange.clearMatched();
    512                                 this.matchRange.removeHighlight();
    513491                                // Clear current session and restart with the default search
    514492                                // range.
    515493                                // Re-run the finding once for cyclic.(#3517)
     
    543521                                                && !this.matchRange._.isReplaced && !this.matchRange.isReadOnly() )
    544522                                {
    545523                                        // Turn off highlight for a while when saving snapshots.
    546                                         this.matchRange.removeHighlight();
    547524                                        var domRange = this.matchRange.toDomRange();
    548525                                        var text = editor.document.createText( newString );
    549526                                        if ( !isReplaceAll )
     
    742719
    743720                                                                                // Scope to full document.
    744721                                                                                finder.searchRange = getSearchRange( 1 );
    745                                                                                 if ( finder.matchRange )
    746                                                                                 {
    747                                                                                         finder.matchRange.removeHighlight();
    748                                                                                         finder.matchRange = null;
    749                                                                                 }
     722                                                                                finder.matchRange = null;
    750723                                                                                editor.fire( 'saveSnapshot' );
    751724                                                                                while ( finder.replace( dialog,
    752725                                                                                        dialog.getValueOf( 'replace', 'txtFindReplace' ),
     
    850823                        },
    851824                        onShow : function()
    852825                        {
     826                                toggleDesignMode( 0 );
     827
    853828                                // Establish initial searching start position.
    854829                                finder.searchRange = getSearchRange();
    855830
     
    867842                        },
    868843                        onHide : function()
    869844                        {
     845                                toggleDesignMode( 1 );
     846
    870847                                var range;
    871848                                if ( finder.matchRange && finder.matchRange.isMatched() )
    872849                                {
    873                                         finder.matchRange.removeHighlight();
    874850                                        editor.focus();
    875 
    876851                                        range = finder.matchRange.toDomRange();
    877852                                        if ( range )
    878853                                                editor.getSelection().selectRanges( [ range ] );
  • _source/plugins/find/plugin.js

     
    3131
    3232        requires : [ 'styles' ]
    3333} );
    34 
    35 /**
    36  * Defines the style to be used to highlight results with the find dialog.
    37  * @type Object
    38  * @default { element : 'span', styles : { 'background-color' : '#004', 'color' : '#fff' } }
    39  * @example
    40  * // Highlight search results with blue on yellow.
    41  * config.find_highlight =
    42  *     {
    43  *         element : 'span',
    44  *         styles : { 'background-color' : '#ff0', 'color' : '#00f' }
    45  *     };
    46  */
    47 CKEDITOR.config.find_highlight = { element : 'span', styles : { 'background-color' : '#004', 'color' : '#fff' } };
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy