From 24e0dec72ad900429e6849f247b780b14ec06d69 Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Mon, 5 Sep 2022 14:41:17 +0300 Subject: [PATCH] Lodash: Remove _.first() and _.last() from block tools --- .../src/components/block-tools/index.js | 13 ++++--------- .../src/components/writing-flow/use-select-all.js | 10 ++++------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/packages/block-editor/src/components/block-tools/index.js b/packages/block-editor/src/components/block-tools/index.js index cf03e19083ebd..34c72025706da 100644 --- a/packages/block-editor/src/components/block-tools/index.js +++ b/packages/block-editor/src/components/block-tools/index.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { first, last } from 'lodash'; - /** * WordPress dependencies */ @@ -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 ) ) { @@ -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(); diff --git a/packages/block-editor/src/components/writing-flow/use-select-all.js b/packages/block-editor/src/components/writing-flow/use-select-all.js index 93c55c185b8c7..c56549acf54ad 100644 --- a/packages/block-editor/src/components/writing-flow/use-select-all.js +++ b/packages/block-editor/src/components/writing-flow/use-select-all.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { first, last } from 'lodash'; - /** * WordPress dependencies */ @@ -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 );