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
…WordPress#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 authored and sethrubenstein committed Jul 13, 2023
1 parent 9a7c115 commit 3bf16e2
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

0 comments on commit 3bf16e2

Please sign in to comment.