From 59eae4bddbe7b90ab0c849ccd7c50614bcfa0004 Mon Sep 17 00:00:00 2001 From: DawidKossowski Date: Tue, 6 Sep 2022 12:03:53 +0200 Subject: [PATCH 1/3] Fix (list): Ordering problem when block quote is being inserted into the middle of the list. Closes #11082. --- packages/ckeditor5-list/src/list/utils.js | 3 +-- packages/ckeditor5-list/tests/list/utils.js | 30 +++++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/ckeditor5-list/src/list/utils.js b/packages/ckeditor5-list/src/list/utils.js index 436e4847c20..30c721b4b06 100644 --- a/packages/ckeditor5-list/src/list/utils.js +++ b/packages/ckeditor5-list/src/list/utils.js @@ -297,7 +297,7 @@ export function getSiblingNodes( position, direction ) { const items = []; const listItem = position.parent; const walkerOptions = { - ignoreElementEnd: true, + ignoreElementEnd: false, startPosition: position, shallow: true, direction @@ -395,7 +395,6 @@ export function getSelectedListItems( model ) { .filter( element => element.is( 'element', 'listItem' ) ) .map( element => { const position = model.change( writer => writer.createPositionAt( element, 0 ) ); - return [ ...getSiblingNodes( position, 'backward' ), ...getSiblingNodes( position, 'forward' ) diff --git a/packages/ckeditor5-list/tests/list/utils.js b/packages/ckeditor5-list/tests/list/utils.js index 6601eafce4d..abcb74d3f92 100644 --- a/packages/ckeditor5-list/tests/list/utils.js +++ b/packages/ckeditor5-list/tests/list/utils.js @@ -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; @@ -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; @@ -307,8 +308,8 @@ describe( 'utils', () => { '3.' + '4.' ); - expect( getSiblingNodes( document.selection.getFirstPosition(), 'forward' ) ).to.deep.equal( [ + document.getRoot().getChild( 2 ), document.getRoot().getChild( 3 ), document.getRoot().getChild( 4 ) ] ); @@ -342,6 +343,7 @@ describe( 'utils', () => { ); expect( getSiblingNodes( document.selection.getFirstPosition(), 'forward' ) ).to.deep.equal( [ + document.getRoot().getChild( 0 ), document.getRoot().getChild( 1 ), document.getRoot().getChild( 2 ) ] ); @@ -374,6 +376,7 @@ describe( 'utils', () => { ); expect( getSiblingNodes( document.selection.getFirstPosition(), 'forward' ) ).to.deep.equal( [ + document.getRoot().getChild( 0 ), document.getRoot().getChild( 1 ), document.getRoot().getChild( 2 ) ] ); @@ -406,6 +409,7 @@ describe( 'utils', () => { ); expect( getSiblingNodes( document.selection.getFirstPosition(), 'forward' ) ).to.deep.equal( [ + document.getRoot().getChild( 0 ), document.getRoot().getChild( 1 ), document.getRoot().getChild( 2 ) ] ); @@ -425,6 +429,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 ), @@ -444,10 +449,31 @@ 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 from block quoted list when selection is inside (direction="forward")', () => { + setData( model, + '0.' + + '1.' + + '
' + + '[]2.' + + '3.' + + '
' + + '4.' + + '5.' + ); + + const blockQuoteElement = document.getRoot().getChild( 2 ); + + expect( getSiblingNodes( document.selection.getFirstPosition(), 'forward' ) ).to.deep.equal( [ + blockQuoteElement.getChild( 0 ), + blockQuoteElement.getChild( 1 ) + ] ); + } ); } ); describe( 'getListTypeFromListStyleType()', () => { From 822fda7da5dfabf6904c0b24a12bc91c36bfd25c Mon Sep 17 00:00:00 2001 From: DawidKossowski Date: Tue, 6 Sep 2022 13:15:21 +0200 Subject: [PATCH 2/3] The getSbilingNodes method description was updated and additional unit tests were created --- packages/ckeditor5-list/src/list/utils.js | 3 +++ packages/ckeditor5-list/tests/list/utils.js | 26 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/ckeditor5-list/src/list/utils.js b/packages/ckeditor5-list/src/list/utils.js index 30c721b4b06..104c7be094f 100644 --- a/packages/ckeditor5-list/src/list/utils.js +++ b/packages/ckeditor5-list/src/list/utils.js @@ -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.} @@ -395,6 +397,7 @@ export function getSelectedListItems( model ) { .filter( element => element.is( 'element', 'listItem' ) ) .map( element => { const position = model.change( writer => writer.createPositionAt( element, 0 ) ); + return [ ...getSiblingNodes( position, 'backward' ), ...getSiblingNodes( position, 'forward' ) diff --git a/packages/ckeditor5-list/tests/list/utils.js b/packages/ckeditor5-list/tests/list/utils.js index abcb74d3f92..102b3289d28 100644 --- a/packages/ckeditor5-list/tests/list/utils.js +++ b/packages/ckeditor5-list/tests/list/utils.js @@ -308,6 +308,7 @@ describe( 'utils', () => { '3.' + '4.' ); + expect( getSiblingNodes( document.selection.getFirstPosition(), 'forward' ) ).to.deep.equal( [ document.getRoot().getChild( 2 ), document.getRoot().getChild( 3 ), @@ -455,13 +456,32 @@ describe( 'utils', () => { ] ); } ); - it( 'should return only list items from block quoted list when selection is inside (direction="forward")', () => { + it( 'should return only list items that are inside the same parent element (direction="backward")', () => { + setData( model, + '0.' + + '1.' + + '
' + + '[]2.' + + '3.' + + '
' + + '4.' + + '5.' + ); + + 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, '0.' + '1.' + '
' + - '[]2.' + - '3.' + + '[]2.' + + '3.' + '
' + '4.' + '5.' From 3c3bbe0b3000afd187637505afcc91d217b3b8d8 Mon Sep 17 00:00:00 2001 From: DawidKossowski Date: Tue, 6 Sep 2022 13:19:04 +0200 Subject: [PATCH 3/3] Typo in getSiblingsNodes method description --- packages/ckeditor5-list/src/list/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ckeditor5-list/src/list/utils.js b/packages/ckeditor5-list/src/list/utils.js index 104c7be094f..a56a21f5d56 100644 --- a/packages/ckeditor5-list/src/list/utils.js +++ b/packages/ckeditor5-list/src/list/utils.js @@ -289,7 +289,7 @@ 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. + * 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.