Skip to content

Commit

Permalink
Clear selection on drop
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Dec 16, 2020
1 parent 5dc1f7a commit 5de85ef
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/block-editor/src/components/use-on-block-drop/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ export function parseDropEvent( event ) {
/**
* A function that returns an event handler function for block drop events.
*
* @param {string} targetRootClientId The root client id where the block(s) will be inserted.
* @param {number} targetBlockIndex The index where the block(s) will be inserted.
* @param {string} targetRootClientId The root client id where the block(s) will be inserted.
* @param {number} targetBlockIndex The index where the block(s) will be inserted.
* @param {Function} getBlockIndex A function that gets the index of a block.
* @param {Function} getClientIdsOfDescendants A function that gets the client ids of descendant blocks.
* @param {Function} moveBlocksToPosition A function that moves blocks.
* @param {Function} insertBlocks A function that inserts blocks.
* @param {Function} clearSelectedBlock A function that clears block selection.
* @return {Function} The event handler for a block drop event.
*/
export function onBlockDrop(
Expand All @@ -59,7 +60,8 @@ export function onBlockDrop(
getBlockIndex,
getClientIdsOfDescendants,
moveBlocksToPosition,
insertBlocks
insertBlocks,
clearSelectedBlock
) {
return ( event ) => {
const {
Expand All @@ -71,6 +73,7 @@ export function onBlockDrop(

// If the user is inserting a block
if ( dropType === 'inserter' ) {
clearSelectedBlock();
insertBlocks( blocks, targetBlockIndex, targetRootClientId, false );
}

Expand Down Expand Up @@ -215,6 +218,7 @@ export default function useOnBlockDrop( targetRootClientId, targetBlockIndex ) {
insertBlocks,
moveBlocksToPosition,
updateBlockAttributes,
clearSelectedBlock,
} = useDispatch( 'core/block-editor' );

return {
Expand All @@ -224,7 +228,8 @@ export default function useOnBlockDrop( targetRootClientId, targetBlockIndex ) {
getBlockIndex,
getClientIdsOfDescendants,
moveBlocksToPosition,
insertBlocks
insertBlocks,
clearSelectedBlock
),
onFilesDrop: onFilesDrop(
targetRootClientId,
Expand Down

0 comments on commit 5de85ef

Please sign in to comment.