Skip to content

Commit

Permalink
Page Content Focus: Default insertion point to the Post Content block (
Browse files Browse the repository at this point in the history
…#51773)

* Page Content Focus: Default insertion point to the Post Content block

* Don't prioritise patterns if there is a specified root
  • Loading branch information
noisysocks committed Jun 23, 2023
1 parent f0cf318 commit c64bee4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/block-editor/src/components/inserter/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function InserterLibrary(
return {
destinationRootClientId: _rootClientId,
prioritizePatterns:
getSettings().__experimentalPreferPatternsOnRoot,
getSettings().__experimentalPreferPatternsOnRoot &&
! _rootClientId,
};
},
[ clientId, rootClientId ]
Expand Down
35 changes: 30 additions & 5 deletions packages/edit-site/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import deprecated from '@wordpress/deprecated';
import { uploadMedia } from '@wordpress/media-utils';
import { Platform } from '@wordpress/element';
import { store as preferencesStore } from '@wordpress/preferences';
import { store as blockEditorStore } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand Down Expand Up @@ -224,11 +225,35 @@ export function isInserterOpened( state ) {
*
* @return {Object} The root client ID, index to insert at and starting filter value.
*/
export function __experimentalGetInsertionPoint( state ) {
const { rootClientId, insertionIndex, filterValue } =
state.blockInserterPanel;
return { rootClientId, insertionIndex, filterValue };
}
export const __experimentalGetInsertionPoint = createRegistrySelector(
( select ) => ( state ) => {
if ( typeof state.blockInserterPanel === 'object' ) {
const { rootClientId, insertionIndex, filterValue } =
state.blockInserterPanel;
return { rootClientId, insertionIndex, filterValue };
}

if ( hasPageContentFocus( state ) ) {
const [ postContentClientId ] =
select( blockEditorStore ).__experimentalGetGlobalBlocksByName(
'core/post-content'
);
if ( postContentClientId ) {
return {
rootClientId: postContentClientId,
insertionIndex: undefined,
filterValue: undefined,
};
}
}

return {
rootClientId: undefined,
insertionIndex: undefined,
filterValue: undefined,
};
}
);

/**
* Returns the current opened/closed state of the list view panel.
Expand Down

1 comment on commit c64bee4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in c64bee4.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5352812555
📝 Reported issues:

Please sign in to comment.