Changeset 811

Show
Ignore:
Timestamp:
2007-09-14 09:52:14 (3 years ago)
Author:
fredck
Message:

Fixed #68 : The style system now properly handles Format styles when EnterMode=br. The FCKStyle class has been drastically changed to use now the new FCKDomRangeInterator when applying block styles.

Location:
FCKeditor/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor/trunk/editor/_source/classes/fckstyle.js

    r801 r811  
    605605        { 
    606606                // Bookmark the range so we can re-select it after processing. 
    607                 var bookmark = range.CreateBookmark( true ) ; 
    608  
    609                 var startNode   = range.StartNode ; 
    610                 var endNode             = range.EndNode ; 
    611  
    612                 if ( !range.CheckIsCollapsed() ) 
    613                 { 
    614                         // Get the neighborhood nodes for the bookmark <span> tags. 
    615                         startNode       = range.GetBookmarkNode( bookmark, true ).nextSibling ; 
    616                         endNode         = range.GetBookmarkNode( bookmark, false ).previousSibling ; 
    617                 } 
    618  
    619                 var currentNodePath = new FCKElementPath( startNode ) ; 
    620  
    621                 var currentNode = currentNodePath.Block || startNode ; 
    622                 var isLast = false ; 
    623  
    624                 while ( !isLast && currentNode ) 
    625                 { 
    626                         // Check if this is the last node to be processed. 
    627                         isLast = ( currentNode == endNode ) ; 
    628  
    629                         switch ( currentNode.nodeType ) 
    630                         { 
    631                                 case 1 :        // Element Node 
    632  
    633                                         var elementName = currentNode.nodeName.toLowerCase() ; 
    634  
    635                                         // If the node is a block node, exchange it with the new block. 
    636                                         if ( FCKListsLib.StyleBlockElements[ elementName ] != null ) 
    637                                         { 
    638                                                 // Create the new node right before the current one. 
    639                                                 var newNode = currentNode.parentNode.insertBefore( this.BuildElement( range.Window.document ), currentNode ) ; 
    640  
    641                                                 // Move everything from the current node to the new one. 
    642                                                 FCKDomTools.MoveChildren( currentNode, newNode ) ; 
    643  
    644                                                 // Delete the current node. 
    645                                                 FCKDomTools.RemoveNode( currentNode ) ; 
    646  
    647                                                 currentNode = newNode ; 
    648  
    649                                                 break ; 
    650                                         } 
    651  
    652                                         // If it is an inline element, fell in the Text Node case. 
    653                                         if ( FCKListsLib.InlineChildReqElements[ elementName ] == null ) 
    654                                                 break ; 
    655  
    656                                 case 3 :        // Text Node 
    657  
    658                                         // Ignore empty text nodes. 
    659                                         if ( currentNode.nodeType == 3 && ( !currentNode.nodeValue || currentNode.nodeValue.length == 0 ) ) 
    660                                                 break ; 
    661  
    662                                         currentNodePath = new FCKElementPath( currentNode ) ; 
    663  
    664                                         // If the node doesn't have a parent block element, fix it with the new block. 
    665                                         if ( !currentNodePath.Block ) 
    666                                         { 
    667                                                 // Create a range for the current node. 
    668                                                 var fixRange = new FCKDomRange( range.Window ) ; 
    669                                                 fixRange.MoveToNodeContents( currentNode ) ; 
    670  
    671                                                 // Expands it to the block contents. 
    672                                                 fixRange.Expand( 'block_contents' ) ; 
    673  
    674                                                 // Ignore empty text blocks. 
    675                                                 if ( fixRange.CheckIsEmpty() ) 
    676                                                         break ; 
    677  
    678                                                 // Create the fixed block. 
    679                                                 var fixBlock = this.BuildElement( range.Window.document ) ; 
    680  
    681                                                 // Move the contents of the temporary range to the fixed block. 
    682                                                 fixRange.ExtractContents().AppendTo( fixBlock ) ; 
    683  
    684                                                 // Insert the fixed block into the DOM. 
    685                                                 fixRange.InsertNode( fixBlock ) ; 
    686  
    687                                                 currentNode = fixBlock.firstChild ; 
    688                                         } 
    689                         } 
    690  
    691                         if ( !isLast ) 
    692                                 currentNode = FCKDomTools.GetNextSourceNode( currentNode ) ; 
    693                 } 
    694  
    695                 // As the style system break text nodes constantly, let's normalize 
    696                 // things for performance. 
    697                 // With IE, some paragraphs get broken when calling normalize() 
    698                 // repeatedly. Also, for IE, we must normalize body, not documentElement. 
    699                 // IE is also known for having a "crash effect" with normalize(). 
    700                 // We should try to normalize with IE too in some way, somewhere. 
    701                 if ( !FCKBrowserInfo.IsIE ) 
    702                         range.Window.document.body.normalize() ; 
     607                var bookmark  
     608                 
     609                if ( selectIt ) 
     610                        bookmark = range.CreateBookmark( true ) ; 
     611 
     612                var interator = new FCKDomRangeInterator( range ) ; 
     613                interator.EnforceRealBlocks = true ; 
     614                 
     615                var block  
     616                while( ( block = interator.GetNextParagraph() ) )               // Only one = 
     617                { 
     618                        // Create the new node right before the current one. 
     619                        var newBlock = block.parentNode.insertBefore( this.BuildElement( range.Window.document ), block ) ; 
     620 
     621                        // Move everything from the current node to the new one. 
     622                        FCKDomTools.MoveChildren( block, newBlock ) ; 
     623 
     624                        // Delete the current node. 
     625                        FCKDomTools.RemoveNode( block ) ; 
     626                } 
    703627 
    704628                // Re-select the original range. 
  • FCKeditor/trunk/editor/_source/fckscriptloader.js

    r809 r811  
    104104FCKScriptLoader.AddScript( 'FCKImagePreloader'  , 'classes/' ) ; 
    105105FCKScriptLoader.AddScript( 'FCKKeystrokeHandler', 'classes/'    , ['FCKConstants','FCKBrowserInfo','FCKTools'], FCK_GENERIC ) ; 
    106 FCKScriptLoader.AddScript( 'FCKStyle'                   , 'classes/'    , ['FCKConstants','FCKDomRange','FCKDomTools','FCKListsLib','FCK_Xhtml10Transitional'], FCK_GENERIC ) ; 
     106FCKScriptLoader.AddScript( 'FCKStyle'                   , 'classes/'    , ['FCKConstants','FCKDomRange','FCKDomRangeInterator','FCKDomTools','FCKListsLib','FCK_Xhtml10Transitional'], FCK_GENERIC ) ; 
    107107FCKScriptLoader.AddScript( 'FCKW3CRange'                , 'classes/'    , ['FCKDomTools','FCKTools','FCKDocumentFragment'], FCK_GENERIC ) ; 
    108108 
  • FCKeditor/trunk/_whatsnew.html

    r783 r811  
    215215                <li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/1160">#1160</a>] [<a target="_blank" href="http://dev.fckeditor.net/ticket/1184">#1184</a>] Home, End 
    216216                        and Tab keys are working properly for numeric fields in dialogs. </li> 
     217                <li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/68">#68</a>] The style 
     218                        system now properly handles Format styles when EnterMode=br.</li> 
    217219        </ul> 
    218220        <h3>