| | 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 | } |