|
5 | 5 |
|
6 | 6 | (function() {
|
7 | 7 | CKEDITOR.plugins.add( 'enterkey', {
|
8 |
| - // TODO: should not depend on a particular format plugin. |
9 |
| - requires: 'indent', |
10 |
| - |
11 | 8 | init: function( editor ) {
|
12 | 9 | editor.addCommand( 'enter', { modes:{wysiwyg:1 },
|
13 | 10 | editorFocus: false,
|
|
48 | 45 | var atBlockStart = range.checkStartOfBlock(),
|
49 | 46 | atBlockEnd = range.checkEndOfBlock(),
|
50 | 47 | path = editor.elementPath( range.startContainer ),
|
51 |
| - block = path.block; |
| 48 | + block = path.block, |
| 49 | + |
| 50 | + // Determine the block element to be used. |
| 51 | + blockTag = ( mode == CKEDITOR.ENTER_DIV ? 'div' : 'p' ), |
| 52 | + |
| 53 | + newBlock; |
52 | 54 |
|
53 | 55 | // Exit the list when we're inside an empty list item block. (#5376)
|
54 | 56 | if ( atBlockStart && atBlockEnd ) {
|
55 | 57 | // Exit the list when we're inside an empty list item block. (#5376)
|
56 | 58 | if ( block && ( block.is( 'li' ) || block.getParent().is( 'li' ) ) ) {
|
57 |
| - editor.execCommand( 'outdent' ); |
| 59 | + var blockParent = block.getParent(), |
| 60 | + blockGrandParent = blockParent.getParent(), |
| 61 | + |
| 62 | + firstChild = !block.hasPrevious(), |
| 63 | + lastChild = !block.hasNext(), |
| 64 | + |
| 65 | + selection = editor.getSelection(), |
| 66 | + bookmarks = selection.createBookmarks(), |
| 67 | + |
| 68 | + orgDir = block.getDirection( 1 ), |
| 69 | + className = block.getAttribute( 'class' ), |
| 70 | + style = block.getAttribute( 'style' ), |
| 71 | + dirLoose = blockGrandParent.getDirection( 1 ) != orgDir, |
| 72 | + |
| 73 | + enterMode = editor.config.enterMode, |
| 74 | + needsBlock = enterMode != CKEDITOR.ENTER_BR || dirLoose || style || className, |
| 75 | + |
| 76 | + child; |
| 77 | + |
| 78 | + if ( blockGrandParent.is( 'li' ) ) { |
| 79 | + |
| 80 | + // If block is the first or the last child of the parent |
| 81 | + // list, degrade it and move to the outer list: |
| 82 | + // before the parent list if block is first child and after |
| 83 | + // the parent list if block is the last child, respectively. |
| 84 | + // |
| 85 | + // <ul> => <ul> |
| 86 | + // <li> => <li> |
| 87 | + // <ul> => <ul> |
| 88 | + // <li>x</li> => <li>x</li> |
| 89 | + // <li>^</li> => </ul> |
| 90 | + // </ul> => </li> |
| 91 | + // </li> => <li>^</li> |
| 92 | + // </ul> => </ul> |
| 93 | + // |
| 94 | + // AND |
| 95 | + // |
| 96 | + // <ul> => <ul> |
| 97 | + // <li> => <li>^</li> |
| 98 | + // <ul> => <li> |
| 99 | + // <li>^</li> => <ul> |
| 100 | + // <li>x</li> => <li>x</li> |
| 101 | + // </ul> => </ul> |
| 102 | + // </li> => </li> |
| 103 | + // </ul> => </ul> |
| 104 | + |
| 105 | + if ( firstChild || lastChild ) |
| 106 | + block[ firstChild ? 'insertBefore' : 'insertAfter' ]( blockGrandParent ); |
| 107 | + |
| 108 | + // If the empty block is neither first nor last child |
| 109 | + // then split the list and the block as an element |
| 110 | + // of outer list. |
| 111 | + // |
| 112 | + // => <ul> |
| 113 | + // => <li> |
| 114 | + // <ul> => <ul> |
| 115 | + // <li> => <li>x</li> |
| 116 | + // <ul> => </ul> |
| 117 | + // <li>x</li> => </li> |
| 118 | + // <li>^</li> => <li>^</li> |
| 119 | + // <li>y</li> => <li> |
| 120 | + // </ul> => <ul> |
| 121 | + // </li> => <li>y</li> |
| 122 | + // </ul> => </ul> |
| 123 | + // => </li> |
| 124 | + // => </ul> |
| 125 | + |
| 126 | + else |
| 127 | + block.breakParent( blockGrandParent ); |
| 128 | + } |
| 129 | + |
| 130 | + else if ( !needsBlock ) { |
| 131 | + block.appendBogus(); |
| 132 | + |
| 133 | + // If block is the first or last child of the parent |
| 134 | + // list, move all block's children out of the list: |
| 135 | + // before the list if block is first child and after the list |
| 136 | + // if block is the last child, respectively. |
| 137 | + // |
| 138 | + // <ul> => <ul> |
| 139 | + // <li>x</li> => <li>x</li> |
| 140 | + // <li>^</li> => </ul> |
| 141 | + // </ul> => ^ |
| 142 | + // |
| 143 | + // AND |
| 144 | + // |
| 145 | + // <ul> => ^ |
| 146 | + // <li>^</li> => <ul> |
| 147 | + // <li>x</li> => <li>x</li> |
| 148 | + // </ul> => </ul> |
| 149 | + |
| 150 | + if ( firstChild || lastChild ) { |
| 151 | + while ( ( child = block[ firstChild ? 'getFirst' : 'getLast' ]() ) ) |
| 152 | + child[ firstChild ? 'insertBefore' : 'insertAfter' ]( blockParent ); |
| 153 | + } |
| 154 | + |
| 155 | + // If the empty block is neither first nor last child |
| 156 | + // then split the list and put all the block contents |
| 157 | + // between two lists. |
| 158 | + // |
| 159 | + // <ul> => <ul> |
| 160 | + // <li>x</li> => <li>x</li> |
| 161 | + // <li>^</li> => </ul> |
| 162 | + // <li>y</li> => ^ |
| 163 | + // </ul> => <ul> |
| 164 | + // => <li>y</li> |
| 165 | + // => </ul> |
| 166 | + |
| 167 | + else { |
| 168 | + block.breakParent( blockParent ); |
| 169 | + |
| 170 | + while ( ( child = block.getLast() ) ) |
| 171 | + child.insertAfter( blockParent ); |
| 172 | + } |
| 173 | + |
| 174 | + block.remove(); |
| 175 | + } else { |
| 176 | + // Use <div> block for ENTER_BR and ENTER_DIV. |
| 177 | + newBlock = doc.createElement( mode == CKEDITOR.ENTER_P ? 'p' : 'div' ); |
| 178 | + |
| 179 | + if ( dirLoose ) |
| 180 | + newBlock.setAttribute( 'dir', orgDir ); |
| 181 | + |
| 182 | + style && newBlock.setAttribute( 'style', style ); |
| 183 | + className && newBlock.setAttribute( 'class', className ); |
| 184 | + |
| 185 | + // Move all the child nodes to the new block. |
| 186 | + block.moveChildren( newBlock ); |
| 187 | + |
| 188 | + // If block is the first or last child of the parent |
| 189 | + // list, move it out of the list: |
| 190 | + // before the list if block is first child and after the list |
| 191 | + // if block is the last child, respectively. |
| 192 | + // |
| 193 | + // <ul> => <ul> |
| 194 | + // <li>x</li> => <li>x</li> |
| 195 | + // <li>^</li> => </ul> |
| 196 | + // </ul> => <p>^</p> |
| 197 | + // |
| 198 | + // AND |
| 199 | + // |
| 200 | + // <ul> => <p>^</p> |
| 201 | + // <li>^</li> => <ul> |
| 202 | + // <li>x</li> => <li>x</li> |
| 203 | + // </ul> => </ul> |
| 204 | + |
| 205 | + if ( firstChild || lastChild ) |
| 206 | + newBlock[ firstChild ? 'insertBefore' : 'insertAfter' ]( blockParent ); |
| 207 | + |
| 208 | + // If the empty block is neither first nor last child |
| 209 | + // then split the list and put the new block between |
| 210 | + // two lists. |
| 211 | + // |
| 212 | + // => <ul> |
| 213 | + // <ul> => <li>x</li> |
| 214 | + // <li>x</li> => </ul> |
| 215 | + // <li>^</li> => <p>^</p> |
| 216 | + // <li>y</li> => <ul> |
| 217 | + // </ul> => <li>y</li> |
| 218 | + // => </ul> |
| 219 | + |
| 220 | + else { |
| 221 | + block.breakParent( blockParent ); |
| 222 | + newBlock.insertAfter( blockParent ); |
| 223 | + } |
| 224 | + |
| 225 | + block.remove(); |
| 226 | + } |
| 227 | + |
| 228 | + selection.selectBookmarks( bookmarks ); |
| 229 | + |
58 | 230 | return;
|
59 | 231 | }
|
60 | 232 |
|
|
82 | 254 | }
|
83 | 255 | }
|
84 | 256 |
|
85 |
| - // Determine the block element to be used. |
86 |
| - var blockTag = ( mode == CKEDITOR.ENTER_DIV ? 'div' : 'p' ); |
87 |
| - |
88 | 257 | // Split the range.
|
89 | 258 | var splitInfo = range.splitBlock( blockTag );
|
90 | 259 |
|
|
139 | 308 | if ( nextBlock )
|
140 | 309 | range.moveToElementEditStart( nextBlock );
|
141 | 310 | } else {
|
142 |
| - var newBlock, newBlockDir; |
| 311 | + var newBlockDir; |
143 | 312 |
|
144 | 313 | if ( previousBlock ) {
|
145 | 314 | // Do not enter this block if it's a header tag, or we are in
|
|
0 commit comments