From bd11f595ffab2ace207663117c05ddcddcda8c60 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Wed, 6 Nov 2024 11:10:04 +0100 Subject: [PATCH] Select Mode: Hide tool selector in the post editor and force design mode (#66784) Co-authored-by: youknowriad Co-authored-by: ntsekouras Co-authored-by: richtabor --- packages/block-editor/src/store/selectors.js | 7 +++++-- .../src/components/document-tools/index.js | 8 +++++++- .../provider/use-block-editor-settings.js | 5 +++++ .../editor/various/write-design-mode.spec.js | 20 +++++++++++++------ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index b5afb2891ef1c..b09c3d3d01b16 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -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' ) + ); } ); diff --git a/packages/editor/src/components/document-tools/index.js b/packages/editor/src/components/document-tools/index.js index b2295b555ce08..74118caaf5849 100644 --- a/packages/editor/src/components/document-tools/index.js +++ b/packages/editor/src/components/document-tools/index.js @@ -35,6 +35,7 @@ function DocumentTools( { className, disableBlockTools = false } ) { inserterSidebarToggleRef, listViewToggleRef, showIconLabels, + showTools, } = useSelect( ( select ) => { const { get } = select( preferencesStore ); const { @@ -42,6 +43,8 @@ function DocumentTools( { className, disableBlockTools = false } ) { getEditorMode, getInserterSidebarToggleRef, getListViewToggleRef, + getRenderingMode, + getCurrentPostType, } = unlock( select( editorStore ) ); const { getShortcutRepresentation } = select( keyboardShortcutsStore ); @@ -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', }; }, [] ); @@ -128,7 +134,7 @@ function DocumentTools( { className, disableBlockTools = false } ) { ) } { ( isWideViewport || ! showIconLabels ) && ( <> - { isLargeViewport && ( + { showTools && isLargeViewport && ( { - 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',