Skip to content

Commit

Permalink
Merge pull request #12419 from ckeditor/ck/11082-ordering-problem-wit…
Browse files Browse the repository at this point in the history
…h-block-quoted-list

Fix (list): List properties changes made on a list inside a container element (e.g. block quote) were incorrectly propagated also to a list directly after that container. Closes #11082.
  • Loading branch information
scofalik committed Sep 6, 2022
2 parents 961d05c + 3c3bbe0 commit c3aa4ba
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/ckeditor5-list/src/list/utils.js
Expand Up @@ -289,6 +289,8 @@ export function findNestedList( viewElement ) {
*
* It means that values of `listIndent`, `listType`, `listStyle`, `listReversed` and `listStart` for all items are equal.
*
* Additionally, if the `position` is inside a list item, that list item will be returned as well.
*
* @param {module:engine/model/position~Position} position Starting position.
* @param {'forward'|'backward'} direction Walking direction.
* @returns {Array.<module:engine/model/element~Element>}
Expand All @@ -297,7 +299,7 @@ export function getSiblingNodes( position, direction ) {
const items = [];
const listItem = position.parent;
const walkerOptions = {
ignoreElementEnd: true,
ignoreElementEnd: false,
startPosition: position,
shallow: true,
direction
Expand Down
48 changes: 47 additions & 1 deletion packages/ckeditor5-list/tests/list/utils.js
Expand Up @@ -13,6 +13,7 @@ import ListPropertiesEditing from '../../src/listproperties/listpropertieseditin

import { createViewListItemElement, getListTypeFromListStyleType, getSiblingListItem, getSiblingNodes } from '../../src/list/utils';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import BlockQuoteEditing from '@ckeditor/ckeditor5-block-quote/src/blockquoteediting';

describe( 'utils', () => {
let writer;
Expand Down Expand Up @@ -271,7 +272,7 @@ describe( 'utils', () => {
let editor, model, document;

beforeEach( () => {
return VirtualTestEditor.create( { plugins: [ Paragraph, ListPropertiesEditing ] } )
return VirtualTestEditor.create( { plugins: [ Paragraph, BlockQuoteEditing, ListPropertiesEditing ] } )
.then( newEditor => {
editor = newEditor;
model = editor.model;
Expand Down Expand Up @@ -309,6 +310,7 @@ describe( 'utils', () => {
);

expect( getSiblingNodes( document.selection.getFirstPosition(), 'forward' ) ).to.deep.equal( [
document.getRoot().getChild( 2 ),
document.getRoot().getChild( 3 ),
document.getRoot().getChild( 4 )
] );
Expand Down Expand Up @@ -342,6 +344,7 @@ describe( 'utils', () => {
);

expect( getSiblingNodes( document.selection.getFirstPosition(), 'forward' ) ).to.deep.equal( [
document.getRoot().getChild( 0 ),
document.getRoot().getChild( 1 ),
document.getRoot().getChild( 2 )
] );
Expand Down Expand Up @@ -374,6 +377,7 @@ describe( 'utils', () => {
);

expect( getSiblingNodes( document.selection.getFirstPosition(), 'forward' ) ).to.deep.equal( [
document.getRoot().getChild( 0 ),
document.getRoot().getChild( 1 ),
document.getRoot().getChild( 2 )
] );
Expand Down Expand Up @@ -406,6 +410,7 @@ describe( 'utils', () => {
);

expect( getSiblingNodes( document.selection.getFirstPosition(), 'forward' ) ).to.deep.equal( [
document.getRoot().getChild( 0 ),
document.getRoot().getChild( 1 ),
document.getRoot().getChild( 2 )
] );
Expand All @@ -425,6 +430,7 @@ describe( 'utils', () => {
);

expect( getSiblingNodes( document.selection.getFirstPosition(), 'forward' ) ).to.deep.equal( [
document.getRoot().getChild( 0 ),
document.getRoot().getChild( 1 ),
document.getRoot().getChild( 2 ),
document.getRoot().getChild( 5 ),
Expand All @@ -444,10 +450,50 @@ describe( 'utils', () => {
);

expect( getSiblingNodes( document.selection.getFirstPosition(), 'forward' ) ).to.deep.equal( [
document.getRoot().getChild( 2 ),
document.getRoot().getChild( 3 ),
document.getRoot().getChild( 4 )
] );
} );

it( 'should return only list items that are inside the same parent element (direction="backward")', () => {
setData( model,
'<listItem listStart="0" listType="numbered" listIndent="0">0.</listItem>' +
'<listItem listStart="0" listType="numbered" listIndent="0">1.</listItem>' +
'<blockQuote>' +
'<listItem listStart="0" listType="numbered" listIndent="0">[]2.</listItem>' +
'<listItem listStart="0" listType="numbered" listIndent="0">3.</listItem>' +
'</blockQuote>' +
'<listItem listStart="0" listType="numbered" listIndent="0">4.</listItem>' +
'<listItem listStart="0" listType="numbered" listIndent="0">5.</listItem>'
);

const blockQuoteElement = document.getRoot().getChild( 2 );

expect( getSiblingNodes( document.selection.getFirstPosition(), 'backward' ) ).to.deep.equal( [
blockQuoteElement.getChild( 0 )
] );
} );

it( 'should return only list items that are inside the same parent element (direction="forward")', () => {
setData( model,
'<listItem listStart="0" listType="numbered" listIndent="0">0.</listItem>' +
'<listItem listStart="0" listType="numbered" listIndent="0">1.</listItem>' +
'<blockQuote>' +
'<listItem listStart="0" listType="numbered" listIndent="0">[]2.</listItem>' +
'<listItem listStart="0" listType="numbered" listIndent="0">3.</listItem>' +
'</blockQuote>' +
'<listItem listStart="0" listType="numbered" listIndent="0">4.</listItem>' +
'<listItem listStart="0" listType="numbered" listIndent="0">5.</listItem>'
);

const blockQuoteElement = document.getRoot().getChild( 2 );

expect( getSiblingNodes( document.selection.getFirstPosition(), 'forward' ) ).to.deep.equal( [
blockQuoteElement.getChild( 0 ),
blockQuoteElement.getChild( 1 )
] );
} );
} );

describe( 'getListTypeFromListStyleType()', () => {
Expand Down

0 comments on commit c3aa4ba

Please sign in to comment.