Skip to content

Commit

Permalink
Merge branch 't/11897'
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Jun 27, 2014
2 parents 89f4a31 + 9a3b014 commit e0542d2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CKEditor 4 Changelog
Fixed Issues:

* [#12110](http://dev.ckeditor.com/ticket/12110): Fixed: Editor crash after deleting a table. Thanks to [Alin Purcaru](https://github.com/mesmerizero)!
* [#11897](http://dev.ckeditor.com/ticket/11897): Fixed: Enter key in an empty formatted list item, creates a new line instead of breaking the list. Thanks to [noam-si](https://github.com/noam-si)!

## CKEditor 4.4.2

Expand Down
26 changes: 18 additions & 8 deletions plugins/enterkey/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
if ( atBlockStart && atBlockEnd ) {
// Exit the list when we're inside an empty list item block. (#5376)
if ( block && ( block.is( 'li' ) || block.getParent().is( 'li' ) ) ) {
// Make sure to point to the li when dealing with empty list item.
if ( !block.is( 'li' ) )
block = block.getParent();

var blockParent = block.getParent(),
blockGrandParent = blockParent.getParent(),

Expand Down Expand Up @@ -175,17 +179,23 @@

block.remove();
} else {
// Use <div> block for ENTER_BR and ENTER_DIV.
newBlock = doc.createElement( mode == CKEDITOR.ENTER_P ? 'p' : 'div' );
// Original path block is the list item, create new block for the list item content.
if ( path.block.is( 'li' ) ) {
// Use <div> block for ENTER_BR and ENTER_DIV.
newBlock = doc.createElement( mode == CKEDITOR.ENTER_P ? 'p' : 'div' );

if ( dirLoose )
newBlock.setAttribute( 'dir', orgDir );
if ( dirLoose )
newBlock.setAttribute('dir', orgDir);

style && newBlock.setAttribute( 'style', style );
className && newBlock.setAttribute( 'class', className );
style && newBlock.setAttribute( 'style', style );
className && newBlock.setAttribute( 'class', className );

// Move all the child nodes to the new block.
block.moveChildren( newBlock );
// Move all the child nodes to the new block.
block.moveChildren( newBlock );
}
// The original path block is not a list item, just copy the block to out side of the list.
else
newBlock = path.block;

// If block is the first or last child of the parent
// list, move it out of the list:
Expand Down
38 changes: 38 additions & 0 deletions tests/plugins/enter/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,44 @@
true, 'Direction should be preserved if different than cointainer\'s.', true );
},

'test enterkey: leaves empty list item with h1 format': function() {
assertEnter( 'enterP',
'<ul>' +
'<li>x</li>' +
'<li><h1>^</h1></li>' +
'<li>y</li>' +
'</ul>',

'<ul>' +
'<li>x</li>' +
'</ul>' +
'<h1>^&nbsp;</h1>' +
'<ul>' +
'<li>y</li>' +
'</ul>',

true, 'List should be split and format preserved.', true );
},

'test enterkey: leaves empty list item with a paragraph': function() {
assertEnter( 'enterP',
'<ul>' +
'<li>x</li>' +
'<li><p>^</p></li>' +
'<li>y</li>' +
'</ul>',

'<ul>' +
'<li>x</li>' +
'</ul>' +
'<p>^&nbsp;</p>' +
'<ul>' +
'<li>y</li>' +
'</ul>',

true, 'List should be split.', true );
},

'test enterkey: force block: style (ENTER_BR)': function() {
assertEnter( 'enterBR',
'<ul>' +
Expand Down

0 comments on commit e0542d2

Please sign in to comment.