Ticket #1229: 1229_2.patch

File 1229_2.patch, 6.2 kB (added by martinkou, 7 months ago)
  • _whatsnew.html

     
    267267                        &lt;PRE&gt; block.</li> 
    268268                <li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/1627">#1627</a>] Samples 
    269269                        failed to load from local filesystem in IE7.</li> 
     270                <li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/1229">#1229</a>] Converting 
     271                        multiple contiguous paragraphs to Formatted will now be merged into a single  
     272                        &lt;PRE&gt; block.</li> 
    270273        </ul> 
    271274        <p> 
    272275                <a href="_whatsnew_history.html">See previous versions history</a> 
  • editor/_source/classes/fckstyle.js

     
    836836                return newBlock ; 
    837837        }, 
    838838 
     839        // The currentBlock must not be moved or deleted from the DOM tree. 
     840        // This guarantees the FCKDomRangeIterator in _ApplyBlockStyle would not 
     841        // get lost at the next iteration. 
     842        _CheckAndMergePre : function( previousBlock, currentBlock ) 
     843        { 
     844                // Check if the next block in HTML equals the next <PRE> block generated. 
     845                if ( FCKDomTools.GetNextSourceElement( previousBlock, true, null, null, true ) != currentBlock ) 
     846                        return ; 
     847 
     848                // Merge the upper <PRE> block's content into the lower <PRE> 
     849                // block. 
     850                // Remove the upper <PRE> block. 
     851                // 
     852                // Another thing to be careful here is that currentBlock might 
     853                // contain a '\n' at the beginning, and previousBlock might 
     854                // contain a '\n' towards the end. These new lines are not 
     855                // normally displayed but they become visible after merging. 
     856                currentBlock.innerHTML = previousBlock.innerHTML.replace( /\n$/, '' ) + '\n\n' + 
     857                        currentBlock.innerHTML.replace( /^\n/, '' ) ; 
     858                FCKDomTools.RemoveNode( previousBlock ) ; 
     859        }, 
     860 
     861        _CheckAndSplitPre : function( doc, previousBlock ) 
     862        { 
     863                var lastNewBlock = null ; 
     864                for ( var j = 0 ; j < previousBlock.childNodes.length ; j++ ) 
     865                { 
     866                        var cursor = previousBlock.childNodes[j] ; 
     867 
     868                        // If we have two <BR>s, and they're not at the beginning or the end, 
     869                        // then we'll split up the contents following them into another block. 
     870                        if ( cursor.nodeName.IEquals( 'br' ) && j != 0 && j != previousBlock.childNodes.length - 2 
     871                                        && cursor.nextSibling && cursor.nextSibling.nodeName.IEquals( 'br' ) ) 
     872                        { 
     873                                FCKDomTools.RemoveNode( cursor.nextSibling ) ; 
     874                                FCKDomTools.RemoveNode( cursor ) ; 
     875                                j-- ;   // restart at current index at next iteration 
     876                                lastNewBlock = FCKDomTools.InsertAfterNode( lastNewBlock || previousBlock, doc.createElement( previousBlock.nodeName ) ) ; 
     877                                continue ; 
     878                        } 
     879 
     880                        if ( lastNewBlock ) 
     881                        { 
     882                                FCKDomTools.MoveNode( cursor, lastNewBlock ) ; 
     883                                j-- ;   // restart at current index at next iteration 
     884                        } 
     885                } 
     886        }, 
     887 
    839888        /** 
    840889         * Apply an inline style to a FCKDomRange. 
    841890         * 
     
    857906                var block ; 
    858907                var doc = range.Window.document ; 
    859908 
    860                 var preBlocks = [] ; 
    861                 var convertedPreBlocks = [] ; 
     909                var previousPreBlock ; 
     910                var previousConvertedPreBlock ; 
    862911 
    863912                while( ( block = iterator.GetNextParagraph() ) )                // Only one = 
    864913                { 
     
    869918                        var newBlockIsPre = newBlock.nodeName.IEquals( 'pre' ) ; 
    870919                        var blockIsPre = block.nodeName.IEquals( 'pre' ) ; 
    871920                        if ( newBlockIsPre && !blockIsPre ) 
    872                         { 
    873921                                newBlock = this._ToPre( doc, block, newBlock ) ; 
    874                                 preBlocks.push( newBlock ) ; 
    875                         } 
    876922                        else if ( !newBlockIsPre && blockIsPre ) 
    877                         { 
    878923                                newBlock = this._FromPre( doc, block, newBlock ) ; 
    879                                 convertedPreBlocks.push( newBlock ) ; 
    880                         } 
    881924                        else    // Convering from a regular block to another regular block. 
    882925                                FCKDomTools.MoveChildren( block, newBlock ) ; 
    883926 
    884927                        // Replace the current block. 
    885928                        block.parentNode.insertBefore( newBlock, block ) ; 
    886929                        FCKDomTools.RemoveNode( block ) ; 
    887                 } 
    888930 
    889                 // Merge adjacent <PRE> blocks for #1229. 
    890                 for ( var i = 0 ; i < preBlocks.length - 1 ; i++ ) 
    891                 { 
    892                         // Check if the next block in HTML equals the next <PRE> block generated. 
    893                         if ( FCKDomTools.GetNextSourceElement( preBlocks[i], true, [], [], true ) != preBlocks[i+1] ) 
    894                                 continue ; 
    895  
    896                         // Merge the upper <PRE> block's content into the lower <PRE> block. 
    897                         // Remove the upper <PRE> block. 
    898                         preBlocks[i+1].innerHTML = preBlocks[i].innerHTML + '\n\n' + preBlocks[i+1].innerHTML ; 
    899                         FCKDomTools.RemoveNode( preBlocks[i] ) ; 
    900                 } 
    901  
    902                 // Split converted <PRE> blocks for #1229. 
    903                 for ( var i = 0 ; i < convertedPreBlocks.length ; i++ ) 
    904                 { 
    905                         var currentBlock = convertedPreBlocks[i] ; 
    906                         var lastNewBlock = null ; 
    907                         for ( var j = 0 ; j < currentBlock.childNodes.length ; j++ ) 
     931                        // Split and merge processed PRE blocks after they're 
     932                        // placed in document. 
     933                        if ( newBlockIsPre && !blockIsPre ) 
    908934                        { 
    909                                 var cursor = currentBlock.childNodes[j] ; 
    910  
    911                                 // If we have two <BR>s, and they're not at the beginning or the end, 
    912                                 // then we'll split up the contents following them into another block. 
    913                                 if ( cursor.nodeName.IEquals( 'br' ) && j != 0 && j != currentBlock.childNodes.length - 2 
    914                                                 && cursor.nextSibling && cursor.nextSibling.nodeName.IEquals( 'br' ) ) 
    915                                 { 
    916                                         FCKDomTools.RemoveNode( cursor.nextSibling ) ; 
    917                                         FCKDomTools.RemoveNode( cursor ) ; 
    918                                         j-- ;   // restart at current index at next iteration 
    919                                         lastNewBlock = FCKDomTools.InsertAfterNode( lastNewBlock || currentBlock, doc.createElement( currentBlock.nodeName ) ) ; 
    920                                         continue ; 
    921                                 } 
    922  
    923                                 if ( lastNewBlock ) 
    924                                 { 
    925                                         FCKDomTools.MoveNode( cursor, lastNewBlock ) ; 
    926                                         j-- ;   // restart at current index at next iteration 
    927                                 } 
     935                                if ( previousPreBlock ) 
     936                                        this._CheckAndMergePre( previousPreBlock, newBlock ) ; 
     937                                previousPreBlock = newBlock ; 
    928938                        } 
     939                        else if ( !newBlockIsPre && blockIsPre ) 
     940                        { 
     941                                if ( previousConvertedPreBlock ) 
     942                                        this._CheckAndSplitPre( doc, previousConvertedPreBlock ) ; 
     943                                previousConvertedPreBlock = newBlock ; 
     944                        } 
    929945                } 
    930946 
     947                if ( previousConvertedPreBlock ) 
     948                        this._CheckAndSplitPre( doc, previousConvertedPreBlock ) ; 
     949 
    931950                // Re-select the original range. 
    932951                if ( selectIt ) 
    933952                        range.SelectBookmark( bookmark ) ;