Ticket #4944: 4944_2.patch

File 4944_2.patch, 4.5 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/pastefromword/filter/default.js

     
    123123        var cssLengthRelativeUnit = /^(\d[.\d]*)+(em|ex|px|gd|rem|vw|vh|vm|ch|mm|cm|in|pt|pc|deg|rad|ms|s|hz|khz){1}?/i;
    124124        var emptyMarginRegex = /^(?:\b0[^\s]*\s*){1,4}$/;
    125125
    126         var listBaseIndent;
     126        var listBaseIndent = 0,
     127                 previousListItemMargin;
    127128
    128129        CKEDITOR.plugins.pastefromword =
    129130        {
     
    217218                                                                        [ 'text-indent' ],
    218219                                                                        [ 'line-height' ],
    219220                                                                        // Resolve indent level from 'margin-left' value.
    220                                                                         [ ( /^margin(:?-left)?$/ ), null, function( value )
     221                                                                        [ ( /^margin(:?-left)?$/ ), null, function( margin )
    221222                                                                        {
    222223                                                                                // Be able to deal with component/short-hand form style.
    223                                                                                 var values = value.split( ' ' );
    224                                                                                 value = values[ 3 ] || values[ 1 ] || values [ 0 ];
    225                                                                                 value = parseInt( value, 10 );
     224                                                                                var values = margin.split( ' ' );
     225                                                                                margin = values[ 3 ] || values[ 1 ] || values [ 0 ];
     226                                                                                margin = parseInt( margin, 10 );
    226227
    227                                                                                 // Figure out the indent unit by looking at the first list item.
    228                                                                                 !listBaseIndent && ( listBaseIndent = value );
     228                                                                                // Figure out the indent unit by looking at the first increament.
     229                                                                                if ( !listBaseIndent && previousListItemMargin && margin > previousListItemMargin )
     230                                                                                        listBaseIndent = margin - previousListItemMargin;
    229231
    230                                                                                 // Indent level start with one.
    231                                                                                 attrs[ 'cke:indent' ] = Math.floor( value / listBaseIndent ) + 1;
     232                                                                                attrs[ 'cke:margin' ] = previousListItemMargin = margin;
    232233                                                                        } ]
    233234                                                        ] )( attrs.style, element ) || '' ;
    234235                                        }
     
    241242                                        CKEDITOR.tools.extend( attrs, listBulletAttrs );
    242243                                        return true;
    243244                                }
    244                                 // Indicate a list has ended.
    245                                 else
    246                                         listBaseIndent = 0;
    247245
    248246                                return false;
    249247                        },
     
    349347
    350348                                                        child.name = 'cke:li';
    351349                                                        attributes[ 'cke:indent' ] = indentLevel;
     350                                                        previousListItemMargin = 0;
    352351                                                        attributes[ 'cke:listtype' ] = element.name;
    353352                                                        listStyleType && child.addStyle( 'list-style-type', listStyleType, true );
    354353                                                }
     
    386385                                                        listItem = child;
    387386                                                        listItemAttrs = listItem.attributes;
    388387                                                        listType = listItem.attributes[ 'cke:listtype' ];
    389                                                         // The indent attribute might not present.
    390                                                         listItemIndent = parseInt( listItemAttrs[ 'cke:indent' ], 10 ) || 0;
    391388
     389                                                        // List item indent level might come from a real list indentation or
     390                                                        // been resolved from a pseudo list item's margin value, even get
     391                                                        // no indentation at all.
     392                                                        listItemIndent = parseInt( listItemAttrs[ 'cke:indent' ], 10 )
     393                                                                                                        || listBaseIndent && ( Math.ceil( listItemAttrs[ 'cke:margin' ] / listBaseIndent ) )
     394                                                                                                        || 1;
     395
    392396                                                        // Ignore the 'list-style-type' attribute if it's matched with
    393397                                                        // the list root element's default style type.
    394398                                                        listItemAttrs.style && ( listItemAttrs.style =
     
    400404
    401405                                                        if ( !list )
    402406                                                        {
    403                                                                 parentList = list = new CKEDITOR.htmlParser.element( listType );
     407                                                                list = new CKEDITOR.htmlParser.element( listType );
    404408                                                                list.add( listItem );
    405409                                                                children[ i ] = list;
    406410                                                        }
     
    408412                                                        {
    409413                                                                if ( listItemIndent > indent )
    410414                                                                {
    411                                                                         parentList = list;
    412415                                                                        list = new CKEDITOR.htmlParser.element( listType );
    413416                                                                        list.add( listItem );
    414417                                                                        lastListItem.add( list );
    415418                                                                }
    416419                                                                else if ( listItemIndent < indent )
    417420                                                                {
    418                                                                         list = parentList;
    419                                                                         parentList = list.parent ? list.parent.parent : list;
     421                                                                        // There might be a negative gap between two list levels. (#4944)
     422                                                                        var diff = indent - listItemIndent,
     423                                                                                parent = list.parent;
     424                                                                        while( diff-- && parent )
     425                                                                                list = parent.parent;
     426
    420427                                                                        list.add( listItem );
    421428                                                                }
    422429                                                                else
     
    431438                                                else
    432439                                                        list = null;
    433440                                        }
     441                                       
     442                                        listBaseIndent = 0;
    434443                                },
    435444
    436445                                /**
     
    11301139                // Remove the dummy spans ( having no inline style ).
    11311140                data = data.replace( /<span>/g, '' );
    11321141
    1133                 // Clean up certain stateful session variables.
    1134                 listBaseIndent = 0;
    11351142                return data;
    11361143        };
    11371144})();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy