Ticket #6107: 6107_9.patch

File 6107_9.patch, 6.1 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/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)
     
    10631082        function removeFromElement( style, element )
    10641083        {
    10651084                var def = style._.definition,
    1066                         attributes = CKEDITOR.tools.extend( {}, def.attributes, getOverrides( style )[ element.getName() ] ),
     1085                        elementName = element.getName(),
     1086                        attributes = CKEDITOR.tools.extend( {}, def.attributes, getOverrides( style )[ elementName ] ),
    10671087                        styles = def.styles,
    10681088                        // If the style is only about the element itself, we have to remove the element.
    10691089                        removeEmpty = CKEDITOR.tools.isEmpty( attributes ) && CKEDITOR.tools.isEmpty( styles );
     
    10901110                        element.removeStyle( styleName );
    10911111                }
    10921112
    1093                 removeEmpty && removeNoAttribsElement( element );
    1094         }
     1113                if ( removeEmpty )
     1114                {
     1115                        ( !CKEDITOR.dtd.$block[ elementName ] || style._.enterMode == CKEDITOR.ENTER_BR ) && !element.hasAttributes() ?
     1116                                removeNoAttribsElement( element ) :
     1117                                element.renameNode( elementName in CKEDITOR.dtd.$block ?
     1118                                        style._.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' : 'span' );
     1119                }
     1120        }
    10951121
    10961122        // Removes a style from inside an element.
    10971123        function removeFromInsideElement( style, element )
     
    11601186                removeNoAttribsElement( element );
    11611187        }
    11621188
     1189        var nonWhitespaces = CKEDITOR.dom.walker.whitespaces( 1 );
    11631190        // If the element has no more attributes, remove it.
    11641191        function removeNoAttribsElement( element )
    11651192        {
     
    11671194                // leaving its children.
    11681195                if ( !element.hasAttributes() )
    11691196                {
    1170                         // Removing elements may open points where merging is possible,
    1171                         // so let's cache the first and last nodes for later checking.
    1172                         var firstChild  = element.getFirst();
    1173                         var lastChild   = element.getLast();
     1197                        if ( CKEDITOR.dtd.$block[ element.getName() ] )
     1198                        {
     1199                                var previous = element.getPrevious( nonWhitespaces ),
     1200                                                next = element.getNext( nonWhitespaces );
     1201
     1202                                if ( previous && ( previous.type == CKEDITOR.NODE_TEXT || !previous.isBlockBoundary( { br : 1 } ) ) )
     1203                                        element.append( 'br', 1 );
     1204                                if ( next && ( next.type == CKEDITOR.NODE_TEXT || !next.isBlockBoundary( { br : 1 } ) ) )
     1205                                        element.append( 'br' );
     1206
     1207                                element.remove( true );
     1208                        }
     1209                        else
     1210                        {
     1211                                // Removing elements may open points where merging is possible,
     1212                                // so let's cache the first and last nodes for later checking.
     1213                                var firstChild = element.getFirst();
     1214                                var lastChild = element.getLast();
    11741215
    1175                         element.remove( true );
     1216                                element.remove( true );
    11761217
    1177                         if ( firstChild )
    1178                         {
    1179                                 // Check the cached nodes for merging.
    1180                                 firstChild.type == CKEDITOR.NODE_ELEMENT && firstChild.mergeSiblings();
     1218                                if ( firstChild )
     1219                                {
     1220                                        // Check the cached nodes for merging.
     1221                                        firstChild.type == CKEDITOR.NODE_ELEMENT && firstChild.mergeSiblings();
    11811222
    1182                                 if ( lastChild && !firstChild.equals( lastChild )
    1183                                         && lastChild.type == CKEDITOR.NODE_ELEMENT  )
    1184                                         lastChild.mergeSiblings();
    1185                         }
    1186                 }
    1187         }
     1223                                        if ( lastChild && !firstChild.equals( lastChild )
     1224                                                        && lastChild.type == CKEDITOR.NODE_ELEMENT )
     1225                                                lastChild.mergeSiblings();
     1226                                }
     1227
     1228                        }
     1229                }
     1230        }
    11881231
    11891232        function getElement( style, targetDocument, element )
    11901233        {
     
    14361479
    14371480                var iterator = ranges.createIterator();
    14381481                while ( ( range = iterator.getNextRange() ) )
    1439                 {
    14401482                        func.call( this, range );
    1441                 }
    14421483
    14431484                selection.selectRanges( ranges );
    14441485
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy