Skip to content

Commit

Permalink
Merge pull request #11123 from ckeditor/i/8642-crash-list-styles
Browse files Browse the repository at this point in the history
Fix (list): The list properties feature will no longer crash when removing content from the last list item which is next to a non-list element. Closes #8642.
  • Loading branch information
niegowski authored Jan 18, 2022
2 parents 17dbe41 + 28d6ff5 commit 8b69b95
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/ckeditor5-list/src/listpropertiesediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ export default class ListPropertiesEditing extends Plugin {
direction: 'forward'
} );

// If the selection ends in a non-list element, there are no <listItem>s that would require adjustments.
// See: #8642.
if ( !secondListMostOuterItem ) {
firstMostOuterItem = null;
return;
}

const items = [
secondListMostOuterItem,
...getSiblingNodes( writer.createPositionAt( secondListMostOuterItem, 0 ), 'forward' )
Expand Down
57 changes: 57 additions & 0 deletions packages/ckeditor5-list/tests/listpropertiesediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,25 @@ describe( 'ListPropertiesEditing', () => {
);
} );

// See: #8642.
it( 'should not crash when removing entire list item followed by a paragraph element with another list', () => {
setModelData( model,
'<listItem listIndent="0" listStyle="default" listType="bulleted">aaaa</listItem>' +
'<listItem listIndent="0" listStyle="default" listType="bulleted">[bbbb</listItem>' +
'<paragraph>]foo</paragraph>' +
'<listItem listIndent="0" listStyle="default" listType="bulleted">aaaa</listItem>'
);

editor.execute( 'delete' );

expect( getModelData( model ) ).to.equal(
'<listItem listIndent="0" listStyle="default" listType="bulleted">aaaa</listItem>' +
'<listItem listIndent="0" listStyle="default" listType="bulleted">[]</listItem>' +
'<paragraph>foo</paragraph>' +
'<listItem listIndent="0" listStyle="default" listType="bulleted">aaaa</listItem>'
);
} );

function simulateTyping( text ) {
// While typing, every character is an atomic change.
text.split( '' ).forEach( character => {
Expand Down Expand Up @@ -3198,6 +3217,25 @@ describe( 'ListPropertiesEditing', () => {
);
} );

// See: #8642.
it( 'should not crash when removing entire list item followed by a paragraph element with another list', () => {
setModelData( model,
'<listItem listIndent="0" listReversed="true" listType="numbered">aaaa</listItem>' +
'<listItem listIndent="0" listReversed="true" listType="numbered">[bbbb</listItem>' +
'<paragraph>]foo</paragraph>' +
'<listItem listIndent="0" listReversed="true" listType="numbered">aaaa</listItem>'
);

editor.execute( 'delete' );

expect( getModelData( model ) ).to.equal(
'<listItem listIndent="0" listReversed="true" listType="numbered">aaaa</listItem>' +
'<listItem listIndent="0" listReversed="true" listType="numbered">[]</listItem>' +
'<paragraph>foo</paragraph>' +
'<listItem listIndent="0" listReversed="true" listType="numbered">aaaa</listItem>'
);
} );

it(
'should read the `listReversed` attribute from the most outer selected list while removing content between lists',
() => {
Expand Down Expand Up @@ -4828,6 +4866,25 @@ describe( 'ListPropertiesEditing', () => {
);
} );

// See: #8642.
it( 'should not crash when removing entire list item followed by a paragraph element with another list', () => {
setModelData( model,
'<listItem listIndent="0" listStart="1" listType="numbered">aaaa</listItem>' +
'<listItem listIndent="0" listStart="1" listType="numbered">[bbbb</listItem>' +
'<paragraph>]foo</paragraph>' +
'<listItem listIndent="0" listStart="1" listType="numbered">aaaa</listItem>'
);

editor.execute( 'delete' );

expect( getModelData( model ) ).to.equal(
'<listItem listIndent="0" listStart="1" listType="numbered">aaaa</listItem>' +
'<listItem listIndent="0" listStart="1" listType="numbered">[]</listItem>' +
'<paragraph>foo</paragraph>' +
'<listItem listIndent="0" listStart="1" listType="numbered">aaaa</listItem>'
);
} );

it(
'should read the `listStart` attribute from the most outer selected list while removing content between lists',
() => {
Expand Down

0 comments on commit 8b69b95

Please sign in to comment.