Ticket #7037: 7037_2.patch

File 7037_2.patch, 3.1 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/styles/plugin.js

     
    895895
    896896                var block;
    897897                while ( ( block = iterator.getNextParagraph() ) )
    898                         this.checkElementRemovable( block ) && removeFromElement( this, block, 1 );
     898                {
     899                        if ( this.checkElementRemovable( block ) )
     900                        {
     901                                // <pre> get special treatment.
     902                                if ( block.is( 'pre' ) )
     903                                {
     904                                        var newBlock = this._.enterMode == CKEDITOR.ENTER_BR ?
     905                                                                null : range.document.createElement(
     906                                                                        this._.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' );
    899907
     908                                        newBlock && block.copyAttributes( newBlock );
     909                                        replaceBlock( block, newBlock );
     910                                }
     911                                else
     912                                         removeFromElement( this, block, 1 );
     913                        }
     914                }
     915
    900916                range.moveToBookmark( bookmark );
    901917        }
    902918
     
    905921        // when necessary.(#3188)
    906922        function replaceBlock( block, newBlock )
    907923        {
    908                 var newBlockIsPre       = newBlock.is( 'pre' );
    909                 var blockIsPre          = block.is( 'pre' );
     924                // Block is to be removed, create a temp element to
     925                // save contents.
     926                var removeBlock = !newBlock;
     927                if ( removeBlock )
     928                {
     929                        newBlock = block.getDocument().createElement( 'div' );
     930                        block.copyAttributes( newBlock );
     931                }
     932
     933                var newBlockIsPre       = newBlock && newBlock.is( 'pre' );
     934                var blockIsPre  = block.is( 'pre' );
    910935
    911936                var isToPre     = newBlockIsPre && !blockIsPre;
    912937                var isFromPre   = !newBlockIsPre && blockIsPre;
     
    915940                        newBlock = toPre( block, newBlock );
    916941                else if ( isFromPre )
    917942                        // Split big <pre> into pieces before start to convert.
    918                         newBlock = fromPres( splitIntoPres( block ), newBlock );
     943                        newBlock = fromPres( removeBlock ?
     944                                                [ block.getHtml() ] : splitIntoPres( block ), newBlock );
    919945                else
    920946                        block.moveChildren( newBlock );
    921947
     
    926952                        // Merge previous <pre> blocks.
    927953                        mergePre( newBlock );
    928954                }
     955                else if ( removeBlock )
     956                        removeNoAttribsElement( newBlock );
    929957        }
    930958
    931959        var nonWhitespaces = CKEDITOR.dom.walker.whitespaces( 1 );
     
    10021030         */
    10031031        function fromPres( preHtmls, newBlock )
    10041032        {
    1005                 var docFrag = new CKEDITOR.dom.documentFragment( newBlock.getDocument() );
     1033                var docFrag;
     1034                if ( preHtmls.length > 1 )
     1035                        docFrag = new CKEDITOR.dom.documentFragment( newBlock.getDocument() );
     1036
    10061037                for ( var i = 0 ; i < preHtmls.length ; i++ )
    10071038                {
    10081039                        var blockHtml = preHtmls[ i ];
     
    10321063                                                return CKEDITOR.tools.repeat( '&nbsp;', match.length - 1 ) + ' ' ;
    10331064                                        } ) ;
    10341065
    1035                         var newBlockClone = newBlock.clone();
    1036                         newBlockClone.setHtml(  blockHtml );
    1037                         docFrag.append( newBlockClone );
    1038                 }
    1039                 return docFrag;
    1040         }
     1066                        if ( docFrag )
     1067                        {
     1068                                var newBlockClone = newBlock.clone();
     1069                                newBlockClone.setHtml(  blockHtml );
     1070                                docFrag.append( newBlockClone );
     1071                        }
     1072                        else
     1073                                newBlock.setHtml( blockHtml );
     1074                }
    10411075
     1076                return docFrag || newBlock;
     1077        }
     1078
    10421079        /**
    10431080         * Converting from a non-PRE block to a PRE block in formatting operations.
    10441081         */
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy