Ticket #1229: 1229.patch

File 1229.patch, 3.9 kB (added by martinkou, 6 months ago)
  • _whatsnew.html

     
    177177                        settings.</li> 
    178178                <li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/1868">#1868</a>] Links 
    179179                        to file browser has been changed to avoid requests containing double dots.</li> 
     180                <li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/1229">#1229</a>] Converting 
     181                        multiple contiguous paragraphs to Formatted will now be merged into a single  
     182                        &lt;PRE&gt; block.</li> 
    180183        </ul> 
    181184        <p> 
    182185                <a href="_whatsnew_history.html">See previous versions history</a> 
  • editor/_source/classes/fckstyle.js

     
    817817                                        value = '\n' ; 
    818818                                results.push( value ) ; 
    819819                        } ) ; 
    820  
     820                 
    821821                // Assigning innerHTML to <PRE> in IE causes all linebreaks to be reduced to spaces. 
    822822                // Assigning outerHTML to <PRE> in IE doesn't work if the <PRE> isn't contained in another node 
    823823                // since the node reference is changed after outerHTML assignment. 
     
    855855                var block ; 
    856856                var doc = range.Window.document ; 
    857857 
     858                var preBlocks = [] ; 
     859                var convertedPreBlocks = [] ; 
     860 
    858861                while( ( block = iterator.GetNextParagraph() ) )                // Only one = 
    859862                { 
    860863                        // Create the new node right before the current one. 
     
    864867                        var newBlockIsPre = newBlock.nodeName.IEquals( 'pre' ) ; 
    865868                        var blockIsPre = block.nodeName.IEquals( 'pre' ) ; 
    866869                        if ( newBlockIsPre && !blockIsPre ) 
     870                        { 
    867871                                newBlock = this._ToPre( doc, block, newBlock ) ; 
     872                                preBlocks.push( newBlock ) ; 
     873                        } 
    868874                        else if ( !newBlockIsPre && blockIsPre ) 
     875                        { 
    869876                                newBlock = this._FromPre( doc, block, newBlock ) ; 
     877                                convertedPreBlocks.push( newBlock ) ; 
     878                        } 
    870879                        else    // Convering from a regular block to another regular block. 
    871880                                FCKDomTools.MoveChildren( block, newBlock ) ; 
    872881 
     
    875884                        FCKDomTools.RemoveNode( block ) ; 
    876885                } 
    877886 
     887                // Merge adjacent <PRE> blocks for #1229. 
     888                for ( var i = 0 ; i < preBlocks.length - 1 ; i++ ) 
     889                { 
     890                        // Check if the next block in HTML equals the next <PRE> block generated. 
     891                        if ( FCKDomTools.GetNextSourceElement( preBlocks[i], true, [], [], true ) != preBlocks[i+1] ) 
     892                                continue ; 
     893 
     894                        // Merge the upper <PRE> block's content into the lower <PRE> block. 
     895                        // Remove the upper <PRE> block. 
     896                        preBlocks[i+1].innerHTML = preBlocks[i].innerHTML + '\n\n' + preBlocks[i+1].innerHTML ; 
     897                        FCKDomTools.RemoveNode( preBlocks[i] ) ; 
     898                } 
     899 
     900                // Split converted <PRE> blocks for #1229. 
     901                for ( var i = 0 ; i < convertedPreBlocks.length ; i++ ) 
     902                { 
     903                        var currentBlock = convertedPreBlocks[i] ; 
     904                        var lastNewBlock = null ; 
     905                        for ( var j = 0 ; j < currentBlock.childNodes.length ; j++ ) 
     906                        { 
     907                                var cursor = currentBlock.childNodes[j] ; 
     908 
     909                                // If we have two <BR>s, and they're not at the beginning or the end, 
     910                                // then we'll split up the contents following them into another block. 
     911                                if ( cursor.nodeName.IEquals( 'br' ) && j != 0 && j != currentBlock.childNodes.length - 2 
     912                                                && cursor.nextSibling && cursor.nextSibling.nodeName.IEquals( 'br' ) ) 
     913                                { 
     914                                        FCKDomTools.RemoveNode( cursor.nextSibling ) ; 
     915                                        FCKDomTools.RemoveNode( cursor ) ; 
     916                                        j-- ;   // restart at current index at next iteration 
     917                                        lastNewBlock = FCKDomTools.InsertAfterNode( lastNewBlock || currentBlock, doc.createElement( currentBlock.nodeName ) ) ; 
     918                                        continue ; 
     919                                } 
     920 
     921                                if ( lastNewBlock ) 
     922                                { 
     923                                        FCKDomTools.MoveNode( cursor, lastNewBlock ) ; 
     924                                        j-- ;   // restart at current index at next iteration 
     925                                } 
     926                        } 
     927                } 
     928 
    878929                // Re-select the original range. 
    879930                if ( selectIt ) 
    880931                        range.SelectBookmark( bookmark ) ;