diff --git a/packages/ckeditor5-list/src/list/utils.js b/packages/ckeditor5-list/src/list/utils.js index 436e4847c20..a56a21f5d56 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.} @@ -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 diff --git a/packages/ckeditor5-list/tests/list/utils.js b/packages/ckeditor5-list/tests/list/utils.js index 6601eafce4d..102b3289d28 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; @@ -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 ) ] ); @@ -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 ) ] ); @@ -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 ) ] ); @@ -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 ) ] ); @@ -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 ), @@ -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, + '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.' + + '
' + + '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()', () => {