Ticket #3509: 3509_3.patch

File 3509_3.patch, 4.2 KB (added by Josh Nisly, 15 years ago)
  • _source/plugins/styles/plugin.js

     
    283283        function applyInlineStyle( range )
    284284        {
    285285                var document = range.document;
     286               
     287                var wasCollapsed = range.collapsed;
    286288
    287                 if ( range.collapsed )
     289                // Get next element after range. If it's a Gecko-appended BR,
     290                // we want to include it in the range, so that the style will
     291                // be maintained in new text added at the end of the line.
     292                var nextElement = range.endContainer.getNextSourceNode( false, CKEDITOR.NODE_ELEMENT );
     293                if ( CKEDITOR.env.gecko && nextElement && nextElement.is( 'br' ))
    288294                {
     295                        if (range.endContainer.type != CKEDITOR.NODE_TEXT || range.endOffset === range.endContainer.getLength() )
     296                                range.setEndAfter(nextElement);
     297                }
     298
     299                if ( wasCollapsed )
     300                {
    289301                        // Create the element to be inserted in the DOM.
    290302                        var collapsedElement = getElement( this, document );
     303                       
     304                        // Even though the range was collapsed, it may now contain a single BR.
     305                        var contents = range.extractContents();
    291306
    292307                        // Insert the empty element into the DOM at the range position.
    293308                        range.insertNode( collapsedElement );
     309                        contents.appendTo( collapsedElement );
    294310
    295311                        // Place the selection right inside the empty element.
    296                         range.moveToPosition( collapsedElement, CKEDITOR.POSITION_BEFORE_END );
     312                        range.moveToPosition( collapsedElement, CKEDITOR.POSITION_AFTER_START );
    297313
    298314                        return;
    299315                }
  • _source/plugins/enterkey/plugin.js

     
    139139                        if ( !newBlock )
    140140                                newBlock = doc.createElement( blockTag );
    141141
     142                        // We need to insert the bogus element inside all of the inline
     143                        // style elements, so that clicking after the line or pressing end
     144                        // and typing makes the typed text keep these inline styles.
     145                        var blockWithBogus = newBlock;
     146
    142147                        // Recreate the inline elements tree, which was available
    143148                        // before hitting enter, so the same styles will be available in
    144149                        // the new block.
     
    157162                                                element = element.clone();
    158163                                                newBlock.moveChildren( element );
    159164                                                newBlock.append( element );
     165
     166                                                blockWithBogus = element;
    160167                                        }
    161168                                }
    162169                        }
    163170
    164171                        if ( !CKEDITOR.env.ie )
    165                                 newBlock.appendBogus();
     172                                blockWithBogus.appendBogus();
    166173
    167174                        range.insertNode( newBlock );
    168175
  • _source/core/dom/element.js

     
    243243                                lastChild = lastChild.getPrevious();
    244244                        if ( !lastChild || !lastChild.is || !lastChild.is( 'br' ) )
    245245                        {
    246                                 this.append(
    247                                         CKEDITOR.env.opera ?
    248                                                 this.getDocument().createText('') :
    249                                                 this.getDocument().createElement( 'br' ) );
     246                                var bogusElement = CKEDITOR.env.opera ?
     247                                                this.getDocument().createText( '' ) :
     248                                                this.getDocument().createElement( 'br' );
     249                                this.append( bogusElement );
     250                                return bogusElement;
    250251                        }
    251252                },
    252253
  • _source/core/dom/range.js

     
    12991299
    13001300                        this.collapse( isStart );
    13011301
     1302                        // If endContainer is at the end of the document, we need to create
     1303                        // a bogus element so that the range can include the entire endContainer.
     1304                        // (This isn't necessary otherwise, but doesn't hurt.)
     1305                        var tempBogus = null;
     1306                        if ( !CKEDITOR.env.ie )
     1307                                tempBogus = this.endContainer.getParent().appendBogus();
     1308
    13021309                        this.enlarge( CKEDITOR.ENLARGE_BLOCK_CONTENTS );
    13031310
    13041311                        this.extractContents().appendTo( fixedBlock );
     
    13071314                        if ( !CKEDITOR.env.ie )
    13081315                                fixedBlock.appendBogus();
    13091316
     1317                        if ( tempBogus )
     1318                                tempBogus.remove();
     1319
    13101320                        this.insertNode( fixedBlock );
    13111321
    13121322                        this.moveToBookmark( bookmark );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy