Ticket #3893: 3893.patch

File 3893.patch, 6.6 KB (added by Garry Yao, 14 years ago)
  • _source/core/dom/elementpath.js

     
    100100                }
    101101
    102102                return true;
    103         }
     103        },
     104
     105        contains : function( tagNames )
     106        {
     107                var elements = this.elements,
     108                                critieria = typeof tagNames == 'string' ?
     109                                        { tagNames : 1 } : tagNames;
     110
     111                for ( var i = 0 ; i < elements.length ; i++ )
     112                {
     113                        if ( elements[i].getName() in critieria )
     114                                return elements[i];
     115                }
     116        }
    104117};
  • _source/plugins/indent/plugin.js

     
    1818
    1919        function onSelectionChange( evt )
    2020        {
    21                 var elements = evt.data.path.elements,
    22                         listNode, listItem,
    23                         editor = evt.editor;
     21                var editor = evt.editor;
    2422
    25                 for ( var i = 0 ; i < elements.length ; i++ )
    26                 {
    27                         if ( elements[i].getName() == 'li' )
    28                         {
    29                                 listItem = elements[i];
    30                                 continue;
    31                         }
    32                         if ( listNodeNames[ elements[i].getName() ] )
    33                         {
    34                                 listNode = elements[i];
    35                                 break;
    36                         }
    37                 }
     23                var elementPath = evt.data.path,
     24                                list = elementPath && elementPath.contains( listNodeNames );
    3825
    39                 if ( listNode )
    40                 {
    41                         if ( this.name == 'outdent' )
    42                                 return setState.call( this, editor, CKEDITOR.TRISTATE_OFF );
    43                         else
    44                         {
    45                                 while ( listItem && ( listItem = listItem.getPrevious( CKEDITOR.dom.walker.whitespaces( true ) ) ) )
    46                                 {
    47                                         if ( listItem.getName && listItem.getName() == 'li' )
    48                                                 return setState.call( this, editor, CKEDITOR.TRISTATE_OFF );
    49                                 }
    50                                 return setState.call( this, editor, CKEDITOR.TRISTATE_DISABLED );
    51                         }
    52                 }
     26                if ( list )
     27                        return setState.call( this, editor, CKEDITOR.TRISTATE_OFF );
    5328
    5429                if ( !this.useIndentClasses && this.name == 'indent' )
    5530                        return setState.call( this, editor, CKEDITOR.TRISTATE_OFF );
     
    200175                iterator.enlargeBr = enterMode != CKEDITOR.ENTER_BR;
    201176                var block;
    202177                while ( ( block = iterator.getNextParagraph() ) )
    203                 {
     178                        indentElement.call( this, editor, block );
     179        }
    204180
    205                         if ( this.useIndentClasses )
    206                         {
    207                                 // Transform current class name to indent step index.
    208                                 var indentClass = block.$.className.match( this.classNameRegex ),
    209                                         indentStep = 0;
    210                                 if ( indentClass )
    211                                 {
    212                                         indentClass = indentClass[1];
    213                                         indentStep = this.indentClassMap[ indentClass ];
    214                                 }
     181        function indentElement( editor, element )
     182        {
     183                if ( this.useIndentClasses )
     184                {
     185                        // Transform current class name to indent step index.
     186                        var indentClass = element.$.className.match( this.classNameRegex ),
     187                                indentStep = 0;
     188                        if ( indentClass )
     189                        {
     190                                indentClass = indentClass[1];
     191                                indentStep = this.indentClassMap[ indentClass ];
     192                        }
    215193
    216                                 // Operate on indent step index, transform indent step index back to class
    217                                 // name.
    218                                 if ( this.name == 'outdent' )
    219                                         indentStep--;
    220                                 else
    221                                         indentStep++;
    222                                 indentStep = Math.min( indentStep, editor.config.indentClasses.length );
    223                                 indentStep = Math.max( indentStep, 0 );
    224                                 var className = CKEDITOR.tools.ltrim( block.$.className.replace( this.classNameRegex, '' ) );
    225                                 if ( indentStep < 1 )
    226                                         block.$.className = className;
    227                                 else
    228                                         block.$.className = CKEDITOR.tools.ltrim( className + ' ' + editor.config.indentClasses[ indentStep - 1 ] );
    229                         }
    230                         else
    231                         {
    232                                 var currentOffset = parseInt( block.getStyle( this.indentCssProperty ), 10 );
    233                                 if ( isNaN( currentOffset ) )
    234                                         currentOffset = 0;
    235                                 currentOffset += ( this.name == 'indent' ? 1 : -1 ) * editor.config.indentOffset;
    236                                 currentOffset = Math.max( currentOffset, 0 );
    237                                 currentOffset = Math.ceil( currentOffset / editor.config.indentOffset ) * editor.config.indentOffset;
    238                                 block.setStyle( this.indentCssProperty, currentOffset ? currentOffset + editor.config.indentUnit : '' );
    239                                 if ( block.getAttribute( 'style' ) === '' )
    240                                         block.removeAttribute( 'style' );
    241                         }
    242                 }
    243         }
     194                        // Operate on indent step index, transform indent step index back to class
     195                        // name.
     196                        if ( this.name == 'outdent' )
     197                                indentStep--;
     198                        else
     199                                indentStep++;
     200                        indentStep = Math.min( indentStep, editor.config.indentClasses.length );
     201                        indentStep = Math.max( indentStep, 0 );
     202                        var className = CKEDITOR.tools.ltrim( element.$.className.replace( this.classNameRegex, '' ) );
     203                        if ( indentStep < 1 )
     204                                element.$.className = className;
     205                        else
     206                                element.addClass( editor.config.indentClasses[ indentStep - 1 ] );
     207                }
     208                else
     209                {
     210                        var currentOffset = parseInt( element.getStyle( this.indentCssProperty ), 10 );
     211                        if ( isNaN( currentOffset ) )
     212                                currentOffset = 0;
     213                        currentOffset += ( this.name == 'indent' ? 1 : -1 ) * editor.config.indentOffset;
     214                        currentOffset = Math.max( currentOffset, 0 );
     215                        currentOffset = Math.ceil( currentOffset / editor.config.indentOffset ) * editor.config.indentOffset;
     216                        element.setStyle( this.indentCssProperty, currentOffset ? currentOffset + editor.config.indentUnit : '' );
     217                        if ( element.getAttribute( 'style' ) === '' )
     218                                element.removeAttribute( 'style' );
     219                }
     220        }
    244221
    245222        function indentCommand( editor, name )
    246223        {
     
    267244                                return;
    268245
    269246                        var bookmarks = selection.createBookmarks( true ),
    270                                 nearestListBlock = range.getCommonAncestor();
     247                                rangeRoot = range.getCommonAncestor(),
     248                                nearestListBlock = rangeRoot;
    271249
    272250                        while ( nearestListBlock && !( nearestListBlock.type == CKEDITOR.NODE_ELEMENT &&
    273251                                listNodeNames[ nearestListBlock.getName() ] ) )
    274252                                nearestListBlock = nearestListBlock.getParent();
    275253
    276                         if ( nearestListBlock )
    277                                 indentList.call( this, editor, range, nearestListBlock );
    278                         else
    279                                 indentBlock.call( this, editor, range );
     254                        var previousListItem = rangeRoot.getAscendant( 'li', true );
     255                        while ( previousListItem && ( previousListItem =
     256                                previousListItem.getPrevious( CKEDITOR.dom.walker.whitespaces( true ) ) ) )
     257                        {
     258                                if ( previousListItem.getName && previousListItem.getName() == 'li' )
     259                                {
     260                                        indentList.call( this, editor, range, nearestListBlock );
     261                                        break;
     262                                }
     263                        }
     264
     265                        if( !previousListItem )
     266                        {
     267                                // Indent the entire list if  cursor is inside the first list item. (#3893)
     268                                if( nearestListBlock )
     269                                        indentElement.call( this, editor, nearestListBlock );
     270                                else
     271                                        indentBlock.call( this, editor, range );
     272                        }
    280273
    281274                        editor.focus();
    282275                        editor.forceNextSelectionCheck();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy