Ticket #6107: 6107_4.patch

File 6107_4.patch, 5.5 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/stylescombo/plugin.js

     
    106106
    107107                                                var elementPath = new CKEDITOR.dom.elementPath( selection.getStartElement() );
    108108
    109                                                 if ( style.type == CKEDITOR.STYLE_INLINE && style.checkActive( elementPath ) )
    110                                                         style.remove( editor.document );
    111                                                 else if ( style.type == CKEDITOR.STYLE_OBJECT && style.checkActive( elementPath ) )
    112                                                         style.remove( editor.document );
    113                                                 else
    114                                                         style.apply( editor.document );
     109                                                style[ style.checkActive( elementPath ) ? 'remove' : 'apply' ]( editor.document );
    115110
    116111                                                editor.fire( 'saveSnapshot' );
    117112                                        },
  • _source/plugins/format/plugin.js

     
    5454                                        editor.focus();
    5555                                        editor.fire( 'saveSnapshot' );
    5656
    57                                         styles[ value ].apply( editor.document );
     57                                        var style = styles[ value ],
     58                                                elementPath = new CKEDITOR.dom.elementPath( editor.getSelection().getStartElement() );
    5859
     60                                        style[ style.checkActive( elementPath ) ? 'remove' : 'apply' ]( editor.document );
     61
    5962                                        // Save the undo snapshot after all changes are affected. (#4899)
    6063                                        setTimeout( function()
    6164                                        {
  • _source/core/dom/walker.js

     
    345345                                || nodeNameMatches[ this.getName() ];
    346346        };
    347347
    348         CKEDITOR.dom.walker.blockBoundary = function( customNodeNames )
     348        CKEDITOR.dom.walker.blockBoundary = function( customNodeNames, isReject )
    349349        {
    350350                return function( node , type )
    351351                {
    352                         return ! ( node.type == CKEDITOR.NODE_ELEMENT
    353                                                 && node.isBlockBoundary( customNodeNames ) );
     352                        return !! ( isReject ^ ( node.type == CKEDITOR.NODE_ELEMENT
     353                                                && node.isBlockBoundary( customNodeNames ) ) );
    354354                };
    355355        };
    356356
    357         CKEDITOR.dom.walker.listItemBoundary = function()
     357        CKEDITOR.dom.walker.listItemBoundary = function( isReject )
    358358        {
    359                         return this.blockBoundary( { br : 1 } );
     359                return this.blockBoundary( { br : 1 }, isReject );
    360360        };
    361361
    362362        /**
  • _source/plugins/styles/plugin.js

     
    149149                        return ( this.removeFromRange =
    150150                                                this.type == CKEDITOR.STYLE_INLINE ?
    151151                                                        removeInlineStyle
     152                                                : this.type == CKEDITOR.STYLE_BLOCK ?
     153                                                        removeBlockStyle
    152154                                                : this.type == CKEDITOR.STYLE_OBJECT ?
    153155                                                        removeObjectStyle
    154156                                                : null ).call( this, range );
     
    881883                range.moveToBookmark( bookmark );
    882884        }
    883885
     886        function removeBlockStyle( range )
     887        {
     888                // Serializible bookmarks is needed here since
     889                // elements may be merged.
     890                var bookmark = range.createBookmark( 1 );
     891
     892                var iterator = range.createIterator();
     893                iterator.enforceRealBlocks = true;
     894                iterator.enlargeBr = this._.enterMode != CKEDITOR.ENTER_BR;
     895
     896                var block;
     897                while ( ( block = iterator.getNextParagraph() ) )
     898                        this.checkElementRemovable( block ) && removeFromElement( this, block, 1 );
     899
     900                range.moveToBookmark( bookmark );
     901        }
     902
    884903        // Replace the original block with new one, with special treatment
    885904        // for <pre> blocks to make sure content format is well preserved, and merging/splitting adjacent
    886905        // when necessary.(#3188)
     
    10871106                        element.removeStyle( styleName );
    10881107                }
    10891108
    1090                 removeEmpty && removeNoAttribsElement( element );
    1091         }
     1109                if ( removeEmpty )
     1110                {
     1111                        CKEDITOR.dtd.$block[ element.getName() ] ?
     1112                                ( style._.enterMode == CKEDITOR.ENTER_BR ?
     1113                                        blockToBrs( element ) :
     1114                                        element.renameNode( style._.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) )
     1115                                : removeNoAttribsElement( element );
     1116                }
     1117        }
    10921118
    10931119        // Removes a style from inside an element.
    10941120        function removeFromInsideElement( style, element )
     
    11831209                }
    11841210        }
    11851211
     1212        var isBlock = CKEDITOR.dom.walker.listItemBoundary();
     1213        function blockToBrs( block )
     1214        {
     1215                var previousIsBlock = block.getPrevious( isBlock ),
     1216                        nextIsBlock = block.getNext( isBlock );
     1217
     1218                !previousIsBlock && block.append( 'br', 1 );
     1219                !nextIsBlock && block.append( 'br' );
     1220                block.remove( 1 );
     1221        }
     1222
    11861223        function getElement( style, targetDocument, element )
    11871224        {
    11881225                var el;
     
    14331470
    14341471                var iterator = ranges.createIterator();
    14351472                while ( ( range = iterator.getNextRange() ) )
    1436                 {
    14371473                        func.call( this, range );
    1438                 }
    14391474
    14401475                selection.selectRanges( ranges );
    14411476
  • _source/core/dom/range.js

     
    11861186                                            blockBoundary,  // The node on which the enlarging should stop.
    11871187                                                tailBr, // In case BR as block boundary.
    11881188                                            notBlockBoundary = CKEDITOR.dom.walker.blockBoundary(
    1189                                                                 ( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) ? { br : 1 } : null ),
     1189                                                                ( unit == CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS ) ? { br : 1 } : null, 1 ),
    11901190                                                // Record the encountered 'blockBoundary' for later use.
    11911191                                                boundaryGuard = function( node )
    11921192                                                {
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy