Ticket #3190: 3190_3.patch

File 3190_3.patch, 1.9 KB (added by Garry Yao, 16 years ago)
  • _source/plugins/wysiwygarea/plugin.js

     
    114114                                this.getSelection().lock();
    115115                }
    116116        }
     117       
     118        /**
     119         * Auto-fixing for block-less paragraph contents on selection change, includes:
     120         *  1. Make sure there's always a padding node before document end;
     121         *  1. Auto creating wrapping paragraphs when enterMode is block.
     122         */
     123        function onSelectionChangeFixBody( evt )
     124        {
     125                var path = evt.data.path,
     126                        blockLimit = path.blockLimit,
     127                        editor = evt.editor,
     128                        body = editor.document.getBody();
     129                       
     130                // Padding BR if the last element of document is a block.
     131                if ( body.getLast().getName() in CKEDITOR.dtd.$block )
     132                        body.appendBogus();
     133
     134                // Establing new paragraph if there's an inline element within body and it's block-less.
     135                if ( editor.config.enterMode != CKEDITOR.ENTER_BR
     136                         && blockLimit.getName() == 'body'
     137                         && !path.block )
     138                {
     139                        // Ignore document line-height maintaining 'br's.
     140                        var firstBlockless = body.getFirst();
     141                        if ( firstBlockless && firstBlockless.getName
     142                                && firstBlockless.getName() == 'br'
     143                                && blockLimit.getChildren().count() == 1 )
     144                                return;
     145
     146                        var sel = editor.getSelection(),
     147                                ranges = sel.getRanges(),
     148                                range = ranges[ 0 ];
     149
     150                        range.fixBlock( true,
     151                                editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p'  );
     152                        sel.selectRanges( ranges );
     153                }
     154        }
    117155
    118156        CKEDITOR.plugins.add( 'wysiwygarea',
    119157        {
     
    420458
    421459                                        editor.on( 'insertHtml', onInsertHtml, null, null, 20 );
    422460                                        editor.on( 'insertElement', onInsertElement, null, null, 20 );
     461                                        // Auto fixing block-less paragraphs. (#3190)
     462                                        editor.on( 'selectionChange', onSelectionChangeFixBody, null, null, 1 );
    423463                                });
    424464                }
    425465        });
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy