Skip to content

Commit

Permalink
Merge branch 't/10027' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
oleq committed Jul 5, 2013
2 parents 597a99f + d8ca727 commit 41cbd9d
Show file tree
Hide file tree
Showing 7 changed files with 1,445 additions and 365 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -8,6 +8,7 @@ CKEditor 4 Changelog
* [#10370](http://dev.ckeditor.com/ticket/10370): Inconsistency in data events between framed and inline editors.
* [#9794](http://dev.ckeditor.com/ticket/9794): OnChange event.
* [#9923](http://dev.ckeditor.com/ticket/9923): HiDPI support in editor UI. HiDPI icons for Moono skin.
* [#10027](http://dev.ckeditor.com/ticket/10027): Separated list and block indentation.

## CKEditor 4.1.2

Expand Down
3 changes: 2 additions & 1 deletion config.js
Expand Up @@ -34,7 +34,8 @@ CKEDITOR.editorConfig = function( config ) {
'htmlwriter,' +
'image,' +
'iframe,' +
'indent,' +
'indentlist,' +
'indentblock,' +
'justify,' +
'link,' +
'list,' +
Expand Down
187 changes: 178 additions & 9 deletions plugins/enterkey/plugin.js
Expand Up @@ -5,9 +5,6 @@

(function() {
CKEDITOR.plugins.add( 'enterkey', {
// TODO: should not depend on a particular format plugin.
requires: 'indent',

init: function( editor ) {
editor.addCommand( 'enter', { modes:{wysiwyg:1 },
editorFocus: false,
Expand Down Expand Up @@ -48,13 +45,188 @@
var atBlockStart = range.checkStartOfBlock(),
atBlockEnd = range.checkEndOfBlock(),
path = editor.elementPath( range.startContainer ),
block = path.block;
block = path.block,

// Determine the block element to be used.
blockTag = ( mode == CKEDITOR.ENTER_DIV ? 'div' : 'p' ),

newBlock;

// Exit the list when we're inside an empty list item block. (#5376)
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' ) ) ) {
editor.execCommand( 'outdent' );
var blockParent = block.getParent(),
blockGrandParent = blockParent.getParent(),

firstChild = !block.hasPrevious(),
lastChild = !block.hasNext(),

selection = editor.getSelection(),
bookmarks = selection.createBookmarks(),

orgDir = block.getDirection( 1 ),
className = block.getAttribute( 'class' ),
style = block.getAttribute( 'style' ),
dirLoose = blockGrandParent.getDirection( 1 ) != orgDir,

enterMode = editor.config.enterMode,
needsBlock = enterMode != CKEDITOR.ENTER_BR || dirLoose || style || className,

child;

if ( blockGrandParent.is( 'li' ) ) {

// If block is the first or the last child of the parent
// list, degrade it and move to the outer list:
// before the parent list if block is first child and after
// the parent list if block is the last child, respectively.
//
// <ul> => <ul>
// <li> => <li>
// <ul> => <ul>
// <li>x</li> => <li>x</li>
// <li>^</li> => </ul>
// </ul> => </li>
// </li> => <li>^</li>
// </ul> => </ul>
//
// AND
//
// <ul> => <ul>
// <li> => <li>^</li>
// <ul> => <li>
// <li>^</li> => <ul>
// <li>x</li> => <li>x</li>
// </ul> => </ul>
// </li> => </li>
// </ul> => </ul>

if ( firstChild || lastChild )
block[ firstChild ? 'insertBefore' : 'insertAfter' ]( blockGrandParent );

// If the empty block is neither first nor last child
// then split the list and the block as an element
// of outer list.
//
// => <ul>
// => <li>
// <ul> => <ul>
// <li> => <li>x</li>
// <ul> => </ul>
// <li>x</li> => </li>
// <li>^</li> => <li>^</li>
// <li>y</li> => <li>
// </ul> => <ul>
// </li> => <li>y</li>
// </ul> => </ul>
// => </li>
// => </ul>

else
block.breakParent( blockGrandParent );
}

else if ( !needsBlock ) {
block.appendBogus();

// If block is the first or last child of the parent
// list, move all block's children out of the list:
// before the list if block is first child and after the list
// if block is the last child, respectively.
//
// <ul> => <ul>
// <li>x</li> => <li>x</li>
// <li>^</li> => </ul>
// </ul> => ^
//
// AND
//
// <ul> => ^
// <li>^</li> => <ul>
// <li>x</li> => <li>x</li>
// </ul> => </ul>

if ( firstChild || lastChild ) {
while ( ( child = block[ firstChild ? 'getFirst' : 'getLast' ]() ) )
child[ firstChild ? 'insertBefore' : 'insertAfter' ]( blockParent );
}

// If the empty block is neither first nor last child
// then split the list and put all the block contents
// between two lists.
//
// <ul> => <ul>
// <li>x</li> => <li>x</li>
// <li>^</li> => </ul>
// <li>y</li> => ^
// </ul> => <ul>
// => <li>y</li>
// => </ul>

else {
block.breakParent( blockParent );

while ( ( child = block.getLast() ) )
child.insertAfter( blockParent );
}

block.remove();
} else {
// Use <div> block for ENTER_BR and ENTER_DIV.
newBlock = doc.createElement( mode == CKEDITOR.ENTER_P ? 'p' : 'div' );

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

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

// Move all the child nodes to the new block.
block.moveChildren( newBlock );

// If block is the first or last child of the parent
// list, move it out of the list:
// before the list if block is first child and after the list
// if block is the last child, respectively.
//
// <ul> => <ul>
// <li>x</li> => <li>x</li>
// <li>^</li> => </ul>
// </ul> => <p>^</p>
//
// AND
//
// <ul> => <p>^</p>
// <li>^</li> => <ul>
// <li>x</li> => <li>x</li>
// </ul> => </ul>

if ( firstChild || lastChild )
newBlock[ firstChild ? 'insertBefore' : 'insertAfter' ]( blockParent );

// If the empty block is neither first nor last child
// then split the list and put the new block between
// two lists.
//
// => <ul>
// <ul> => <li>x</li>
// <li>x</li> => </ul>
// <li>^</li> => <p>^</p>
// <li>y</li> => <ul>
// </ul> => <li>y</li>
// => </ul>

else {
block.breakParent( blockParent );
newBlock.insertAfter( blockParent );
}

block.remove();
}

selection.selectBookmarks( bookmarks );

return;
}

Expand Down Expand Up @@ -82,9 +254,6 @@
}
}

// Determine the block element to be used.
var blockTag = ( mode == CKEDITOR.ENTER_DIV ? 'div' : 'p' );

// Split the range.
var splitInfo = range.splitBlock( blockTag );

Expand Down Expand Up @@ -139,7 +308,7 @@
if ( nextBlock )
range.moveToElementEditStart( nextBlock );
} else {
var newBlock, newBlockDir;
var newBlockDir;

if ( previousBlock ) {
// Do not enter this block if it's a header tag, or we are in
Expand Down

0 comments on commit 41cbd9d

Please sign in to comment.