Skip to content

Commit 03c3329

Browse files
committed
Merge branch 't/13409'
2 parents e3ee229 + 592bc94 commit 03c3329

File tree

5 files changed

+155
-4
lines changed

5 files changed

+155
-4
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Fixed Issues:
2323
* [#13494](http://dev.ckeditor.com/ticket/13494): Fixed: Error thrown in toolbar configurator if plugin requirements are unsatisfied.
2424
* [#11376](http://dev.ckeditor.com/ticket/11376): [IE11] Fixed: Loss of text when pasting bullet lists from Microsoft Word.
2525
* [#13387](http://dev.ckeditor.com/ticket/13387): [Edge] Fixed: "Permission denied" error thrown while loading the editor with developer tools open.
26+
* [#13409](http://dev.ckeditor.com/ticket/13409): Fixed: List elements incorrectly merged when pressing *Backspace* or *Delete*.
2627

2728
## CKEditor 4.5.1
2829

plugins/list/plugin.js

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,6 @@
945945
}
946946

947947
} else {
948-
949948
var next, nextLine;
950949

951950
li = path.contains( 'li' );
@@ -977,12 +976,79 @@
977976
isAtEnd = 2;
978977
}
979978

980-
981979
if ( isAtEnd && next ) {
982980
// Put cursor range there.
983981
nextLine = range.clone();
984982
nextLine.moveToElementEditStart( next );
985983

984+
// #13409
985+
// For the following case and similar
986+
//
987+
// <ul>
988+
// <li>
989+
// <p><a href="#one"><em>x^</em></a></p>
990+
// <ul>
991+
// <li><span>y</span></li>
992+
// </ul>
993+
// </li>
994+
// </ul>
995+
if ( isAtEnd == 1 ) {
996+
// Move the cursor to <em> if attached to "x" text node.
997+
cursor.optimize();
998+
999+
// Abort if the range is attached directly in <li>, like
1000+
//
1001+
// <ul>
1002+
// <li>
1003+
// x^
1004+
// <ul>
1005+
// <li><span>y</span></li>
1006+
// </ul>
1007+
// </li>
1008+
// </ul>
1009+
if ( !cursor.startContainer.equals( li ) ) {
1010+
var node = cursor.startContainer,
1011+
farthestInlineAscendant;
1012+
1013+
// Find <a>, which is farthest from <em> but still inline element.
1014+
while ( node.is( CKEDITOR.dtd.$inline ) ) {
1015+
farthestInlineAscendant = node;
1016+
node = node.getParent();
1017+
}
1018+
1019+
// Move the range so it does not contain inline elements.
1020+
// It prevents <span> from being included in <em>.
1021+
//
1022+
// <ul>
1023+
// <li>
1024+
// <p><a href="#one"><em>x</em></a>^</p>
1025+
// <ul>
1026+
// <li><span>y</span></li>
1027+
// </ul>
1028+
// </li>
1029+
// </ul>
1030+
//
1031+
// so instead of
1032+
//
1033+
// <ul>
1034+
// <li>
1035+
// <p><a href="#one"><em>x^<span>y</span></em></a></p>
1036+
// </li>
1037+
// </ul>
1038+
//
1039+
// pressing DELETE produces
1040+
//
1041+
// <ul>
1042+
// <li>
1043+
// <p><a href="#one"><em>x</em></a>^<span>y</span></p>
1044+
// </li>
1045+
// </ul>
1046+
if ( farthestInlineAscendant ) {
1047+
cursor.moveToPosition( farthestInlineAscendant, CKEDITOR.POSITION_AFTER_END );
1048+
}
1049+
}
1050+
}
1051+
9861052
// Moving `cursor` and `next line` only when at the end literally (#12729).
9871053
if ( isAtEnd == 2 ) {
9881054
cursor.moveToPosition( cursor.endPath().block, CKEDITOR.POSITION_BEFORE_END );

tests/plugins/list/backspace.html

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,81 @@ <h1>2.1</h1>
347347
<li><a href="#one"><span>one</span></a>^<a href="#two">two</a>@</li>
348348
</ul>
349349
</textarea>
350+
<!-- #13409 -->
351+
<textarea id="join_list17_del">
352+
<ul>
353+
<li>
354+
<a href="#one">x^</a>
355+
<ul>
356+
<li><span>y</span></li>
357+
</ul>
358+
</li>
359+
</ul>
360+
=>
361+
<ul>
362+
<li><a href="#one">x</a>^<span>y</span>@</li>
363+
</ul>
364+
</textarea>
365+
<!-- #13409 -->
366+
<textarea id="join_list18_del">
367+
<ul>
368+
<li>
369+
<a href="#one"><strong>x^</strong></a>
370+
<ul>
371+
<li><span><em>y</em></span></li>
372+
</ul>
373+
</li>
374+
</ul>
375+
=>
376+
<ul>
377+
<li><a href="#one"><strong>x</strong></a>^<span><em>y</em></span>@</li>
378+
</ul>
379+
</textarea>
380+
<!-- #13409 -->
381+
<textarea id="join_list19_del">
382+
<ul>
383+
<li>
384+
<p><a href="#one"><strong>x^</strong></a></p>
385+
<ul>
386+
<li><span><em>y</em></span></li>
387+
</ul>
388+
</li>
389+
</ul>
390+
=>
391+
<ul>
392+
<li><p><a href="#one"><strong>x</strong></a>^<span><em>y</em></span>@</p></li>
393+
</ul>
394+
</textarea>
395+
<!-- #13409 -->
396+
<textarea id="join_list20_del">
397+
<ul>
398+
<li>
399+
x^
400+
<ul>
401+
<li><span><em>y</em></span></li>
402+
</ul>
403+
</li>
404+
</ul>
405+
=>
406+
<ul>
407+
<li>x^<span><em>y</em></span>@@</li>
408+
</ul>
409+
</textarea>
410+
<!-- #13409 -->
411+
<textarea id="join_list21_del">
412+
<ul>
413+
<li>
414+
<blockquote>x^</blockquote>
415+
<ul>
416+
<li><span><em>y</em></span></li>
417+
</ul>
418+
</li>
419+
</ul>
420+
=>
421+
<ul>
422+
<li><blockquote>x^<span><em>y</em></span></blockquote></li>
423+
</ul>
424+
</textarea>
350425

351426
<textarea id="outdent_list">
352427
<ol>

tests/plugins/list/backspace.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ addTests( 'test del join list items', 'join_list13_del', DEL );
8181
addTests( 'test del join list items', 'join_list14_del', DEL );
8282
addTests( 'test del join list items', 'join_list15_del', DEL, undefined, assertNotNestedAnchors );
8383
addTests( 'test del join list items', 'join_list16_del', DEL, undefined, assertNotNestedAnchors );
84+
addTests( 'test del join list items', 'join_list17_del', DEL );
85+
addTests( 'test del join list items', 'join_list18_del', DEL );
86+
addTests( 'test del join list items', 'join_list19_del', DEL );
87+
addTests( 'test del join list items', 'join_list20_del', DEL );
88+
addTests( 'test del join list items', 'join_list21_del', DEL );
8489

8590
addTests( 'test del join with next list item', 'merge_next_list', DEL );
8691
addTests( 'test del join with next list item', 'merge_next_list2', DEL );

tests/plugins/list/manual/mergelistitems.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
----
66

7-
Test merging lists items (and blocks around) with <kbd>backspace</kbd>/<kbd>delete</kbd> in both editors.
7+
Test merging lists items and blocks around lists using <kbd>backspace</kbd>/<kbd>delete</kbd> in both editors.
88

99
Notes:
1010

11-
* Contents of one block should not be inserted into inline elements in the second block, but next to them (link should not be nested into `em` and vice versa).
11+
* Contents of one block should not be inserted into inline elements in the second block, but next to them. For example:
12+
* place caret at the end of the first list item,
13+
* press <kbd>delete</kbd>,
14+
* **expected:** `<li><a>foo</a><em>foo</em></li>`.
15+
* **bad:** `<li><a>foo<em>foo</em></a></li>`.
1216
* When trying to merge the first list item with a block outside it, it's:
1317
* expected that selection moves, but structure does not change (that's due to the nested list).
1418
* [BR mode] known that on FF and IE11 caret is rendered inside list even though it's in the previous line.

0 commit comments

Comments
 (0)