Ticket #4344: 4344.patch

File 4344.patch, 2.4 KB (added by Garry Yao, 15 years ago)
  • _tests/dt/plugins/htmldataprocessor/htmldataprocessor.html

     
    224224                        assert.areSame( expected, dataProcessor.toHtml( '<p>Some text<br></p>' ));
    225225                },
    226226
     227                test_toHtml_ticket_2886_5 : function()
     228                {
     229                        var dataProcessor = CKEDITOR.instances.editor1.dataProcessor;
     230                        assert.areSame( '<p>\n\t<br />\n\t&nbsp;</p>\n',
     231                                dataProcessor.toDataFormat( dataProcessor.toHtml( '<p><br />\n<br /></p>' ) ) );
     232                },
     233
    227234                test_ticket_3407 : function()
    228235                {
    229236                        var editor = CKEDITOR.instances.editor1,
  • _source/plugins/htmldataprocessor/plugin.js

     
    1111
    1212        var protectedSourceMarker = '{cke_protected}';
    1313
     14
     15        // Return the last non-space child node of the block (#4344).
     16        function lastNoneSpaceChild( block )
     17        {
     18                var lastIndex = block.children.length,
     19                        last = block.children[ lastIndex - 1 ];
     20                while(  last && last.type == CKEDITOR.NODE_TEXT && !CKEDITOR.tools.trim( last.value ) )
     21                        last = block.children[ --lastIndex ];
     22                return last || null;
     23        }
     24       
    1425        function trimFillers( block, fromSource )
    1526        {
    1627                // If the current node is a block, and if we're converting from source or
     
    1829                //
    1930                // Also, any &nbsp; at the end of blocks are fillers, remove them as well.
    2031                // (#2886)
    21                 var children = block.children;
    22                 var lastChild = children[ children.length - 1 ];
     32                var children = block.children, lastChild = lastNoneSpaceChild( block );
    2333                if ( lastChild )
    2434                {
    2535                        if ( ( fromSource || !CKEDITOR.env.ie ) && lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br' )
     
    3141
    3242        function blockNeedsExtension( block )
    3343        {
    34                 if ( block.children.length < 1 )
    35                         return true;
    36 
    37                 var lastChild = block.children[ block.children.length - 1 ];
    38                 return lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br';
     44                var lastChild = lastNoneSpaceChild( block );
     45                return !lastChild || lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br';
    3946        }
    4047
    4148        function extendBlockForDisplay( block )
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy