Skip to content

Commit

Permalink
Page editor: double-click to edit template part (#65024)
Browse files Browse the repository at this point in the history
Adds a doubleclick handler to template part block if the content has `contentOnly` editing mode. Also tighten up the doubleclick handler that triggers the edit template modal. It should not trigger when clicking on template parts now that there's a second double click handler. 

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: richtabor <richtabor@git.wordpress.org>
Co-authored-by: noisysocks <noisysocks@git.wordpress.org>
  • Loading branch information
6 people authored Sep 5, 2024
1 parent f7fd368 commit 9c45985
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
21 changes: 20 additions & 1 deletion packages/block-library/src/template-part/edit/inner-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ function EditableTemplatePartInnerBlocks( {
tagName: TagName,
blockProps,
} ) {
const onNavigateToEntityRecord = useSelect(
( select ) =>
select( blockEditorStore ).getSettings().onNavigateToEntityRecord,
[]
);

const [ blocks, onInput, onChange ] = useEntityBlockEditor(
'postType',
'wp_template_part',
Expand All @@ -114,7 +120,20 @@ function EditableTemplatePartInnerBlocks( {
layout: useLayout( layout ),
} );

return <TagName { ...innerBlocksProps } />;
const blockEditingMode = useBlockEditingMode();

const customProps =
blockEditingMode === 'contentOnly' && onNavigateToEntityRecord
? {
onDoubleClick: () =>
onNavigateToEntityRecord( {
postId: id,
postType: 'wp_template_part',
} ),
}
: {};

return <TagName { ...innerBlocksProps } { ...customProps } />;
}

export default function TemplatePartInnerBlocks( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ export default function EditTemplateBlocksNotification( { contentRef } ) {
return;
}

if ( ! event.target.classList.contains( 'is-root-container' ) ) {
if (
! event.target.classList.contains( 'is-root-container' ) ||
event.target.dataset?.type === 'core/template-part'
) {
return;
}
setIsDialogOpen( true );
Expand Down

0 comments on commit 9c45985

Please sign in to comment.