Ticket #7380: 7380.patch

File 7380.patch, 2.7 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/list/plugin.js

     
    633633        };
    634634
    635635        var dtd = CKEDITOR.dtd;
    636         var tailNbspRegex = /[\t\r\n ]*(?: |\xa0)$/;
     636        var tailNbspRegex = /^[\t\r\n ]*(?: |\xa0)$/;
    637637
    638638        function indexOfFirstChildElement( element, tagNameList )
    639639        {
     
    653653
    654654        function getExtendNestedListFilter( isHtmlFilter )
    655655        {
    656                 // An element filter function that corrects nested list start in an empty
    657                 // list item for better displaying/outputting. (#3165)
     656                function createFillerNode()
     657                {
     658                        return ( isHtmlFilter || CKEDITOR.env.ie ) ?
     659                                   new CKEDITOR.htmlParser.text( '\xa0' ) :
     660                                        new CKEDITOR.htmlParser.element( 'br', {} );
     661                }
     662
     663                // Handle BRs before nested list element (pseudo list item). (#3165) (#7380)
    658664                return function( listItem )
    659665                {
    660666                        var children = listItem.children,
    661667                                firstNestedListIndex = indexOfFirstChildElement( listItem, dtd.$list ),
    662668                                firstNestedList = children[ firstNestedListIndex ],
    663669                                nodeBefore = firstNestedList && firstNestedList.previous,
     670                                nodeIndex = firstNestedListIndex - 1,
    664671                                tailNbspmatch;
    665672
    666                         if ( nodeBefore
    667                                 && ( nodeBefore.name && nodeBefore.name == 'br'
    668                                         || nodeBefore.value && ( tailNbspmatch = nodeBefore.value.match( tailNbspRegex ) ) ) )
     673                        // BR at the end of a pseudo block is required only if it's the first child
     674                        // or it's proceeded by other brs.
     675                        if ( nodeBefore && nodeBefore.name && nodeBefore.name == 'br' )
    669676                        {
    670677                                var fillerNode = nodeBefore;
    671 
    672                                 // Always use 'nbsp' as filler node if we found a nested list appear
    673                                 // in front of a list item.
    674                                 if ( !( tailNbspmatch && tailNbspmatch.index ) && fillerNode == children[ 0 ] )
    675                                         children[ 0 ] = ( isHtmlFilter || CKEDITOR.env.ie ) ?
    676                                                          new CKEDITOR.htmlParser.text( '\xa0' ) :
    677                                                                          new CKEDITOR.htmlParser.element( 'br', {} );
    678 
    679                                 // Otherwise the filler is not needed anymore.
    680                                 else if ( fillerNode.name == 'br' )
    681                                         children.splice( firstNestedListIndex - 1, 1 );
     678                                nodeBefore = fillerNode.previous;
     679                                if ( !nodeBefore || nodeBefore.type == CKEDITOR.NODE_ELEMENT && nodeBefore.name == 'br' )
     680                                        children.splice( nodeIndex, 1, createFillerNode() );
    682681                                else
    683                                         fillerNode.value = fillerNode.value.replace( tailNbspRegex, '' );
     682                                        children.splice( nodeIndex, 1 );
    684683                        }
    685684
     685                        if ( nodeBefore && nodeBefore.type == CKEDITOR.NODE_TEXT && tailNbspRegex.test( nodeBefore.value ) )
     686                                children.splice( nodeIndex, 1, createFillerNode() );
    686687                };
    687688        }
    688689
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy