Skip to content

Commit 41cbd9d

Browse files
committed
Merge branch 't/10027' into major
2 parents 597a99f + d8ca727 commit 41cbd9d

File tree

7 files changed

+1445
-365
lines changed

7 files changed

+1445
-365
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CKEditor 4 Changelog
88
* [#10370](http://dev.ckeditor.com/ticket/10370): Inconsistency in data events between framed and inline editors.
99
* [#9794](http://dev.ckeditor.com/ticket/9794): OnChange event.
1010
* [#9923](http://dev.ckeditor.com/ticket/9923): HiDPI support in editor UI. HiDPI icons for Moono skin.
11+
* [#10027](http://dev.ckeditor.com/ticket/10027): Separated list and block indentation.
1112

1213
## CKEditor 4.1.2
1314

config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ CKEDITOR.editorConfig = function( config ) {
3434
'htmlwriter,' +
3535
'image,' +
3636
'iframe,' +
37-
'indent,' +
37+
'indentlist,' +
38+
'indentblock,' +
3839
'justify,' +
3940
'link,' +
4041
'list,' +

plugins/enterkey/plugin.js

Lines changed: 178 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
(function() {
77
CKEDITOR.plugins.add( 'enterkey', {
8-
// TODO: should not depend on a particular format plugin.
9-
requires: 'indent',
10-
118
init: function( editor ) {
129
editor.addCommand( 'enter', { modes:{wysiwyg:1 },
1310
editorFocus: false,
@@ -48,13 +45,188 @@
4845
var atBlockStart = range.checkStartOfBlock(),
4946
atBlockEnd = range.checkEndOfBlock(),
5047
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;
5254

5355
// Exit the list when we're inside an empty list item block. (#5376)
5456
if ( atBlockStart && atBlockEnd ) {
5557
// Exit the list when we're inside an empty list item block. (#5376)
5658
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+
58230
return;
59231
}
60232

@@ -82,9 +254,6 @@
82254
}
83255
}
84256

85-
// Determine the block element to be used.
86-
var blockTag = ( mode == CKEDITOR.ENTER_DIV ? 'div' : 'p' );
87-
88257
// Split the range.
89258
var splitInfo = range.splitBlock( blockTag );
90259

@@ -139,7 +308,7 @@
139308
if ( nextBlock )
140309
range.moveToElementEditStart( nextBlock );
141310
} else {
142-
var newBlock, newBlockDir;
311+
var newBlockDir;
143312

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

0 commit comments

Comments
 (0)