Skip to content

Commit

Permalink
Lodash: Remove _.first() and _.last() from block tools (#43855)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Sep 5, 2022
1 parent 35b0bd0 commit fd9c48e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
13 changes: 4 additions & 9 deletions packages/block-editor/src/components/block-tools/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { first, last } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -59,14 +54,14 @@ export default function BlockTools( {
const clientIds = getSelectedBlockClientIds();
if ( clientIds.length ) {
event.preventDefault();
const rootClientId = getBlockRootClientId( first( clientIds ) );
const rootClientId = getBlockRootClientId( clientIds[ 0 ] );
moveBlocksUp( clientIds, rootClientId );
}
} else if ( isMatch( 'core/block-editor/move-down', event ) ) {
const clientIds = getSelectedBlockClientIds();
if ( clientIds.length ) {
event.preventDefault();
const rootClientId = getBlockRootClientId( first( clientIds ) );
const rootClientId = getBlockRootClientId( clientIds[ 0 ] );
moveBlocksDown( clientIds, rootClientId );
}
} else if ( isMatch( 'core/block-editor/duplicate', event ) ) {
Expand All @@ -85,13 +80,13 @@ export default function BlockTools( {
const clientIds = getSelectedBlockClientIds();
if ( clientIds.length ) {
event.preventDefault();
insertAfterBlock( last( clientIds ) );
insertAfterBlock( clientIds[ clientIds.length - 1 ] );
}
} else if ( isMatch( 'core/block-editor/insert-before', event ) ) {
const clientIds = getSelectedBlockClientIds();
if ( clientIds.length ) {
event.preventDefault();
insertBeforeBlock( first( clientIds ) );
insertBeforeBlock( clientIds[ 0 ] );
}
} else if ( isMatch( 'core/block-editor/unselect', event ) ) {
const clientIds = getSelectedBlockClientIds();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { first, last } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -55,7 +50,10 @@ export default function useSelectAll() {
return;
}

multiSelect( first( blockClientIds ), last( blockClientIds ) );
multiSelect(
blockClientIds[ 0 ],
blockClientIds[ blockClientIds.length - 1 ]
);
}

node.addEventListener( 'keydown', onKeyDown );
Expand Down

0 comments on commit fd9c48e

Please sign in to comment.