Ticket #6548: 6548.patch

File 6548.patch, 2.5 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/indent/plugin.js

     
    282282                                ranges = selection && selection.getRanges( 1 ),
    283283                                range;
    284284
    285                         var skipBookmarks = CKEDITOR.dom.walker.bookmark( 0, 1 );
    286285
    287286                        var iterator = ranges.createIterator();
    288287                        while ( ( range = iterator.getNextRange() ) )
    289288                        {
    290                                 // Do not indent body. (#6138)
    291                                 range.shrink( CKEDITOR.SHRINK_ELEMENT );
    292                                 if ( range.endContainer.getName() == 'body' )
    293                                         range.setEndAt( range.endContainer.getLast( skipBookmarks ), CKEDITOR.POSITION_BEFORE_END );
    294 
    295                                 var startContainer = range.startContainer,
    296                                         endContainer = range.endContainer,
    297                                         rangeRoot = range.getCommonAncestor(),
     289                                var rangeRoot = range.getCommonAncestor(),
    298290                                        nearestListBlock = rangeRoot;
    299291
    300292                                while ( nearestListBlock && !( nearestListBlock.type == CKEDITOR.NODE_ELEMENT &&
    301293                                        listNodeNames[ nearestListBlock.getName() ] ) )
    302294                                        nearestListBlock = nearestListBlock.getParent();
    303295
     296                                // Avoid having selection enclose the entire list. (#6138)
     297                                // [<ul><li>...</li></ul>] =><ul><li>[...]</li></ul>
     298                                if ( !nearestListBlock )
     299                                {
     300                                        var selectedNode = range.getEnclosedNode();
     301                                        if ( selectedNode
     302                                                && selectedNode.type == CKEDITOR.NODE_ELEMENT
     303                                                && selectedNode.getName() in listNodeNames)
     304                                        {
     305                                                range.setStartAt( selectedNode, CKEDITOR.POSITION_AFTER_START );
     306                                                range.setEndAt( selectedNode, CKEDITOR.POSITION_BEFORE_END );
     307                                                nearestListBlock = selectedNode;
     308                                        }
     309                                }
     310
    304311                                // Avoid selection anchors under list root.
    305312                                // <ul>[<li>...</li>]</ul> =>   <ul><li>[...]</li></ul>
    306                                 if ( nearestListBlock && startContainer.type == CKEDITOR.NODE_ELEMENT
    307                                         && startContainer.getName() in listNodeNames )
     313                                if ( nearestListBlock && range.startContainer.type == CKEDITOR.NODE_ELEMENT
     314                                        && range.startContainer.getName() in listNodeNames )
    308315                                {
    309316                                        var walker = new CKEDITOR.dom.walker( range );
    310317                                        walker.evaluator = isListItem;
    311318                                        range.startContainer = walker.next();
    312319                                }
    313320
    314                                 if ( nearestListBlock && endContainer.type == CKEDITOR.NODE_ELEMENT
    315                                         && endContainer.getName() in listNodeNames )
     321                                if ( nearestListBlock && range.endContainer.type == CKEDITOR.NODE_ELEMENT
     322                                        && range.endContainer.getName() in listNodeNames )
    316323                                {
    317324                                        walker = new CKEDITOR.dom.walker( range );
    318325                                        walker.evaluator = isListItem;
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy