From 0dc67e8c56e3bb7988d67b50093354dc903510cd Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Thu, 11 May 2023 17:13:57 +0800 Subject: [PATCH] Only select block if there isn't any already --- packages/block-editor/src/components/list-view/block.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/list-view/block.js b/packages/block-editor/src/components/list-view/block.js index 80419901f116f..a5babce273a19 100644 --- a/packages/block-editor/src/components/list-view/block.js +++ b/packages/block-editor/src/components/list-view/block.js @@ -77,6 +77,7 @@ function ListViewBlock( { }, [ isContentLocked, clientId, isSelected ] ); + const { getSelectedBlockClientIds } = useSelect( blockEditorStore ); const canExpand = isContentLocked ? false : canEdit; const isFirstSelectedBlock = @@ -175,7 +176,11 @@ function ListViewBlock( { const updateSelection = useCallback( ( newClientId ) => { - selectBlock( undefined, newClientId, null, null ); + const selectedBlockClientIds = getSelectedBlockClientIds(); + // Select the block to be focused if there isn't any block selected. + if ( ! selectedBlockClientIds.length ) { + selectBlock( undefined, newClientId, null, null ); + } const getFocusElement = () => { const row = treeGridElementRef.current?.querySelector(