Skip to content

Commit

Permalink
Select Mode: Hide tool selector in the post editor and force design m…
Browse files Browse the repository at this point in the history
…ode (#66784)

Co-authored-by: youknowriad <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
Co-authored-by: richtabor <[email protected]>
  • Loading branch information
4 people authored Nov 6, 2024
1 parent 84048f8 commit bd11f59
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
7 changes: 5 additions & 2 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2764,8 +2764,11 @@ export function isNavigationMode( state ) {
* @return {string} the editor mode.
*/
export const __unstableGetEditorMode = createRegistrySelector(
( select ) => () => {
return select( preferencesStore ).get( 'core', 'editorTool' );
( select ) => ( state ) => {
return (
state.settings.editorTool ??
select( preferencesStore ).get( 'core', 'editorTool' )
);
}
);

Expand Down
8 changes: 7 additions & 1 deletion packages/editor/src/components/document-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ function DocumentTools( { className, disableBlockTools = false } ) {
inserterSidebarToggleRef,
listViewToggleRef,
showIconLabels,
showTools,
} = useSelect( ( select ) => {
const { get } = select( preferencesStore );
const {
isListViewOpened,
getEditorMode,
getInserterSidebarToggleRef,
getListViewToggleRef,
getRenderingMode,
getCurrentPostType,
} = unlock( select( editorStore ) );
const { getShortcutRepresentation } = select( keyboardShortcutsStore );

Expand All @@ -56,6 +59,9 @@ function DocumentTools( { className, disableBlockTools = false } ) {
showIconLabels: get( 'core', 'showIconLabels' ),
isDistractionFree: get( 'core', 'distractionFree' ),
isVisualMode: getEditorMode() === 'visual',
showTools:
getRenderingMode() !== 'post-only' ||
getCurrentPostType() === 'wp_template',
};
}, [] );

Expand Down Expand Up @@ -128,7 +134,7 @@ function DocumentTools( { className, disableBlockTools = false } ) {
) }
{ ( isWideViewport || ! showIconLabels ) && (
<>
{ isLargeViewport && (
{ showTools && isLargeViewport && (
<ToolbarItem
as={ ToolSelector }
showTooltip={ ! showIconLabels }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
: settings.template,
__experimentalSetIsInserterOpened: setIsInserterOpened,
[ sectionRootClientIdKey ]: sectionRootClientId,
editorTool:
renderingMode === 'post-only' && postType !== 'wp_template'
? 'edit'
: undefined,
};

return blockEditorSettings;
Expand Down Expand Up @@ -355,6 +359,7 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
sectionRootClientId,
globalStylesData,
globalStylesLinksData,
renderingMode,
] );
}

Expand Down
20 changes: 14 additions & 6 deletions test/e2e/specs/editor/various/write-design-mode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Write/Design mode', () => {
test.beforeEach( async ( { admin, editor } ) => {
await admin.createNewPost();
await expect(
editor.canvas.getByRole( 'textbox', { name: 'Add title' } )
).toBeFocused();
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'emptytheme' );
} );

test.beforeEach( async ( { admin } ) => {
await admin.visitSiteEditor( {
postId: 'emptytheme//index',
postType: 'wp_template',
canvas: 'edit',
} );
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.deleteAllPosts();
await requestUtils.activateTheme( 'twentytwentyone' );
} );

test( 'Should prevent selecting intermediary blocks', async ( {
editor,
page,
} ) => {
// Clear all content
await editor.setContent( '' );

// Insert a section with a nested block and an editable block.
await editor.insertBlock( {
name: 'core/group',
Expand Down

0 comments on commit bd11f59

Please sign in to comment.