Skip to content

Commit

Permalink
List View: Append when dragging into collapsed blocks (#50936)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong authored May 25, 2023
1 parent 91a268d commit 277a9ff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
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

1 comment on commit 277a9ff

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 277a9ff.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5075907342
📝 Reported issues:

Please sign in to comment.