Skip to content

Commit

Permalink
make the select in anchor setting rerun when block selection changes
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu committed Oct 7, 2024
1 parent b8ca907 commit 0192f7b
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions packages/block-editor/src/components/block-popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,32 +80,34 @@ function BlockPopover(
const {
isZoomOut,
sectionRootClientId,
getParentSectionBlock,
getBlockOrder,
} = useSelect( ( select ) => {
const {
isZoomOut: isZoomOutSelector,
getSectionRootClientId,
getParentSectionBlock: getParentSectionBlockSelector,
getBlockOrder: getBlockOrderSelector,
} = unlock( select( blockEditorStore ) );

return {
sectionRootClientId: getSectionRootClientId(),
isZoomOut: isZoomOutSelector(),
getParentSectionBlock: getParentSectionBlockSelector,
getBlockOrder: getBlockOrderSelector,
};
}, [] );
parentSectionBlock,
isSectionSelected,
} = useSelect(
( select ) => {
const {
isZoomOut: isZoomOutSelector,
getSectionRootClientId,
getParentSectionBlock,
getBlockOrder,
} = unlock( select( blockEditorStore ) );

return {
sectionRootClientId: getSectionRootClientId(),
isZoomOut: isZoomOutSelector(),
parentSectionBlock:
getParentSectionBlock( clientId ) ?? clientId,
isSectionSelected: getBlockOrder(
getSectionRootClientId()
).includes( clientId ),
};
},
[ clientId ]
);

// These elements are used to position the zoom out view vertical toolbar
// correctly, relative to the selected section.
const rootSectionElement = useBlockElement( sectionRootClientId );
const parentSectionElement = useBlockElement(
getParentSectionBlock( clientId ) ?? clientId
);
const isSectionSelected =
getBlockOrder( sectionRootClientId ).includes( clientId );
const parentSectionElement = useBlockElement( parentSectionBlock );

const popoverAnchor = useMemo( () => {
if (
Expand Down

0 comments on commit 0192f7b

Please sign in to comment.