Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List View: Append when dragging into collapsed blocks #50936

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe( 'getListViewDropTarget', () => {
} );
} );

it( 'should nest when dragging a block over the right side and bottom half of a collapsed block with children', () => {
it( 'should nest and append to end when dragging a block over the right side and bottom half of a collapsed block with children', () => {
const position = { x: 160, y: 90 };

const collapsedBlockData = [ ...blocksData ];
Expand All @@ -188,6 +188,26 @@ describe( 'getListViewDropTarget', () => {

const target = getListViewDropTarget( collapsedBlockData, position );

expect( target ).toEqual( {
blockIndex: 1,
dropPosition: 'inside',
rootClientId: 'block-1',
} );
} );

it( 'should nest and prepend when dragging a block over the right side and bottom half of an expanded block with children', () => {
const position = { x: 160, y: 90 };

const collapsedBlockData = [ ...blocksData ];

// Set the first block to be collapsed.
collapsedBlockData[ 0 ] = {
...collapsedBlockData[ 0 ],
isExpanded: true,
};

const target = getListViewDropTarget( collapsedBlockData, position );

expect( target ).toEqual( {
blockIndex: 0,
dropPosition: 'inside',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,15 @@ export function getListViewDropTarget( blocksData, position ) {
candidateBlockParents.length
) )
) {
// If the block is expanded, insert the block as the first child.
// Otherwise, for collapsed blocks, insert the block as the last child.
const newBlockIndex = candidateBlockData.isExpanded
? 0
: candidateBlockData.innerBlockCount || 0;

return {
rootClientId: candidateBlockData.clientId,
blockIndex: 0,
blockIndex: newBlockIndex,
dropPosition: 'inside',
};
}
Expand Down