Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Insertion: Clear the insertion point when selecting a different block or clearing block selection #64048

Merged
merged 5 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import clsx from 'clsx';
import { useState, useEffect } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Button, SearchControl } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand Down Expand Up @@ -82,6 +82,8 @@ export default function QuickInserter( {
}
}, [ setInserterIsOpened ] );

const { showInsertionPoint } = useDispatch( blockEditorStore );

// When clicking Browse All select the appropriate block so as
// the insertion point can work as expected.
const onBrowseAll = () => {
Expand All @@ -91,6 +93,7 @@ export default function QuickInserter( {
filterValue,
onSelect,
} );
showInsertionPoint( rootClientId, insertionIndex );
};

let maxBlockPatterns = 0;
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,8 @@ export function insertionPoint( state = null, action ) {
}

case 'HIDE_INSERTION_POINT':
case 'CLEAR_SELECTED_BLOCK':
case 'SELECT_BLOCK':
return null;
}

Expand Down
14 changes: 10 additions & 4 deletions packages/editor/src/components/inserter-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const { PrivateInserterLibrary } = unlock( blockEditorPrivateApis );

export default function InserterSidebar() {
const {
blockInsertionPoint,
blockSectionRootClientId,
inserterSidebarToggleRef,
insertionPoint,
Expand All @@ -33,8 +34,12 @@ export default function InserterSidebar() {
getInsertionPoint,
isPublishSidebarOpened,
} = unlock( select( editorStore ) );
const { getBlockRootClientId, __unstableGetEditorMode, getSettings } =
select( blockEditorStore );
const {
getBlockInsertionPoint,
getBlockRootClientId,
__unstableGetEditorMode,
getSettings,
} = select( blockEditorStore );
const { get } = select( preferencesStore );
const { getActiveComplementaryArea } = select( interfaceStore );
const getBlockSectionRootClientId = () => {
Expand All @@ -47,6 +52,7 @@ export default function InserterSidebar() {
return getBlockRootClientId();
};
return {
blockInsertionPoint: getBlockInsertionPoint(),
inserterSidebarToggleRef: getInserterSidebarToggleRef(),
insertionPoint: getInsertionPoint(),
showMostUsedBlocks: get( 'core', 'mostUsedBlocks' ),
Expand Down Expand Up @@ -85,9 +91,9 @@ export default function InserterSidebar() {
showInserterHelpPanel
shouldFocusBlock={ isMobileViewport }
rootClientId={
blockSectionRootClientId ?? insertionPoint.rootClientId
blockSectionRootClientId ?? blockInsertionPoint.rootClientId
}
__experimentalInsertionIndex={ insertionPoint.insertionIndex }
__experimentalInsertionIndex={ blockInsertionPoint.index }
onSelect={ insertionPoint.onSelect }
__experimentalInitialTab={ insertionPoint.tab }
__experimentalInitialCategory={ insertionPoint.category }
Expand Down
Loading