Changeset 207

Show
Ignore:
Timestamp:
2007-03-14 12:55:12 (21 months ago)
Author:
fredck
Message:

Fixed #213 : Styles are now preserved when hitting enter at the end of a paragraph.

Location:
FCKeditor/trunk
Files:
3 modified

Legend:

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

    r132 r207  
    118118        }, 
    119119 
     120        // Moves to the first editing point inside a element. For example, in a 
     121        // element tree like "<p><b><i></i></b> Text</p>", the start editing point 
     122        // is "<p><b><i>^</i></b> Text</p>" (inside <i>). 
     123        MoveToElementEditStart : function( targetElement ) 
     124        { 
     125                var child ; 
     126 
     127                while ( ( child = targetElement.firstChild ) && child.nodeType == 1 && FCKListsLib.EmptyElements[ child.nodeName.toLowerCase() ] == null ) 
     128                        targetElement = child ; 
     129 
     130                this.MoveToElementStart( targetElement ) ; 
     131        }, 
     132 
    120133        InsertNode : function( node ) 
    121134        { 
     
    167180                oTestRange.SetEnd( oTestRange.EndBlock || oTestRange.EndBlockLimit, 2 ) ; 
    168181 
    169                 var bIsEndOfBlock = oTestRange.CheckIsEmpty( true ) ; 
    170  
     182                var bIsEndOfBlock = oTestRange.CheckIsCollapsed() ; 
     183                 
     184                if ( !bIsEndOfBlock ) 
     185                { 
     186                        // Inserts the contents of the range in a div tag. 
     187                        var eToolDiv = this.Window.document.createElement( 'div' ) ; 
     188                        oTestRange._Range.cloneContents().AppendTo( eToolDiv ) ; 
     189                        FCKDomTools.TrimNode( eToolDiv, true ) ; 
     190                         
     191                        // Find out if we are in an empty tree of inline elements, like <b><i><span></span></i></b> 
     192                        bIsEndOfBlock = true ; 
     193                        var eLastChild = eToolDiv ; 
     194                        while ( ( eLastChild = eLastChild.lastChild ) ) 
     195                        { 
     196                                // Check the following: 
     197                                //              1. Is there more than one node in the parents children? 
     198                                //              2. Is the node not an element node? 
     199                                //              3. Is it not a inline element. 
     200                                if ( eLastChild.previousSibling || eLastChild.nodeType != 1 || FCKListsLib.InlineChildReqElements[ eLastChild.nodeName.toLowerCase() ] == null ) 
     201                                { 
     202                                        // So we are not in the end of the range. 
     203                                        bIsEndOfBlock = false ; 
     204                                        break ; 
     205                                } 
     206                        } 
     207                } 
     208                 
    171209                oTestRange.Release() ; 
    172210 
  • FCKeditor/trunk/editor/_source/classes/fckenterkey.js

    r184 r207  
    5757        var oEnterKey = this._EnterKey ; 
    5858 
     59        /* @Packager.RemoveLine 
    5960        try 
    6061        { 
     62        @Packager.RemoveLine */ 
    6163                switch ( keystrokeValue ) 
    6264                { 
     
    7678                                return oEnterKey.DoDelete() ; 
    7779                } 
     80        /* @Packager.RemoveLine 
    7881        } 
    7982        catch (e) 
     
    8285                // ahead with the browser default behavior. 
    8386        } 
     87        @Packager.RemoveLine */ 
    8488 
    8589        return false ; 
     
    277281        // Get the current selection. 
    278282        var oRange = range || new FCKDomRange( this.Window ) ; 
    279          
     283 
    280284        // If we don't have a range, move it to the selection. 
    281285        if ( !range ) 
     
    330334 
    331335                                // Move the selection to the new block. 
    332                                 oRange.MoveToElementStart( eStartBlock ) ; 
     336                                oRange.MoveToElementEditStart( eStartBlock ) ; 
    333337                        } 
    334338                        else 
     
    343347                                        { 
    344348                                                var eOutdented = FCKListHandler.OutdentListItem( eStartBlock ) ; 
    345                                                 oRange.MoveToElementStart( eOutdented ) ; 
     349                                                oRange.MoveToElementEditStart( eOutdented ) ; 
    346350                                        } 
    347351                                        else 
     
    352356                                                // Otherwise, duplicate the current block. 
    353357                                                else 
     358                                                { 
    354359                                                        eNewBlock = eStartBlock.cloneNode(false) ; 
     360                                                        this._RecreateEndingTree( eStartBlock, eNewBlock ) ; 
     361                                                } 
    355362 
    356363                                                if ( FCKBrowserInfo.IsGeckoLike ) 
     
    384391                                        { 
    385392                                                // In Gecko, the last child node must be a bogus <br>. 
    386                                                 var eLastChild = FCKDomTools.GetLastChild( eNewBlock ) ; 
    387  
    388                                                 if ( !eLastChild || eLastChild.nodeName.toLowerCase() != 'br' || eLastChild.getAttribute( 'type', 2 ) != '_moz' ) 
    389                                                         eNewBlock.appendChild( FCKTools.CreateBogusBR( this.Window.document ) ) ; 
     393                                                this._AppendBogusBr( eStartBlock ) ; 
     394                                                this._AppendBogusBr( eNewBlock ) ; 
    390395                                        } 
    391396                                } 
     
    396401 
    397402                                        // Move the selection to the new block. 
    398                                         oRange.MoveToElementStart( eNewBlock ) ; 
     403                                        oRange.MoveToElementEditStart( eNewBlock ) ; 
    399404 
    400405                                        if ( FCKBrowserInfo.IsGecko ) 
     
    406411                { 
    407412                        // Move the selection to the end block. 
    408                         oRange.MoveToElementStart( eEndBlock ) ; 
     413                        oRange.MoveToElementEditStart( eEndBlock ) ; 
    409414                } 
    410415 
     
    471476                        // If we are at the end of a block, we must be sure the bogus node is available in that block. 
    472477                        if ( bIsEndOfBlock && FCKBrowserInfo.IsGecko ) 
    473                         { 
    474                                 var eLastBr = FCKDomTools.GetLastChild( eBr.parentNode, 'BR' ) ; 
    475  
    476                                 if ( eLastBr && eLastBr.getAttribute( 'type', 2 ) != '_moz' ) 
    477                                         eBr.parentNode.appendChild( FCKTools.CreateBogusBR( this.Window.document ) ) ; 
    478                         } 
     478                                this._AppendBogusBr( eBr.parentNode ) ; 
    479479 
    480480                        if ( FCKBrowserInfo.IsIE ) 
     
    522522        range.MoveToBookmark( oBookmark ) ; 
    523523} 
     524 
     525// Appends a bogus <br> at the end of the element, if not yet available. 
     526FCKEnterKey.prototype._AppendBogusBr = function( element ) 
     527{ 
     528        var eLastChild = element.getElementsByTagName('br') ; 
     529 
     530        if ( eLastChild ) 
     531                eLastChild = eLastChild[ eLastChild.legth - 1 ] ; 
     532 
     533        if ( !eLastChild || eLastChild.getAttribute( 'type', 2 ) != '_moz' ) 
     534                element.appendChild( FCKTools.CreateBogusBR( this.Window.document ) ) ; 
     535} 
     536 
     537// Recreate the elements tree at the end of the source block, at the beginning 
     538// of the target block. Eg.:  
     539//      If source = <p><u>Some</u> sample <b><i>text</i></b></p> then target = <p><b><i></i></b></p> 
     540//      If source = <p><u>Some</u> sample text</p> then target = <p></p> 
     541FCKEnterKey.prototype._RecreateEndingTree = function( source, target ) 
     542{ 
     543        while ( ( source = source.lastChild ) && source.nodeType == 1 && FCKListsLib.InlineChildReqElements[ source.nodeName.toLowerCase() ] != null ) 
     544                target = target.insertBefore( source.cloneNode( false ), target.firstChild ) ; 
     545} 
  • FCKeditor/trunk/_whatsnew.html

    r202 r207  
    106106                <li>Hidden fields will now show up as an icon in IE, instead of a normal text field. 
    107107                        They are also selectable and draggable, in all browsers.</li> 
     108                <li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/213">#213</a>] Styles 
     109                        are now preserved when hitting enter at the end of a paragraph.</li> 
    108110        </ul> 
    109111        <h3>