Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions edit-post/components/header/header-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import {
import './style.scss';
import FullscreenModeClose from '../fullscreen-mode-close';

function HeaderToolbar( { hasFixedToolbar, isLargeViewport } ) {
function HeaderToolbar( { hasFixedToolbar, isLargeViewport, mode } ) {
return (
<NavigableToolbar
className="edit-post-header-toolbar"
aria-label={ __( 'Editor Toolbar' ) }
>
<FullscreenModeClose />
<div>
<Inserter position="bottom right" />
<Inserter disabled={ mode !== 'visual' } position="bottom right" />
Copy link
Member

Choose a reason for hiding this comment

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

These sorts of magic constants always irk me, even when they're strings. This is pretty obvious in its intent, but it's still possible to make typos, etc. 🤷‍♂️

Not really isolated to this PR though.

<DotTip id="core/editor.inserter">
{ __( 'Welcome to the wonderful world of blocks! Click the “+” (“Add block”) button to add a new block. There are blocks available for all kind of content: you can insert text, headings, images, lists, and lots more!' ) }
</DotTip>
Expand All @@ -53,6 +53,7 @@ function HeaderToolbar( { hasFixedToolbar, isLargeViewport } ) {
export default compose( [
withSelect( ( select ) => ( {
hasFixedToolbar: select( 'core/edit-post' ).isFeatureActive( 'fixedToolbar' ),
mode: select( 'core/edit-post' ).getEditorMode(),
} ) ),
withViewportMatch( { isLargeViewport: 'medium' } ),
] )( HeaderToolbar );
7 changes: 6 additions & 1 deletion edit-post/store/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { reduce, some } from 'lodash';
/**
* WordPress dependencies
*/
import { select, subscribe } from '@wordpress/data';
import { select, subscribe, dispatch } from '@wordpress/data';
import { speak } from '@wordpress/a11y';
import { __ } from '@wordpress/i18n';
import apiFetch from '@wordpress/api-fetch';
Expand Down Expand Up @@ -120,6 +120,11 @@ const effects = {
.then( () => store.dispatch( metaBoxUpdatesSuccess() ) );
},
SWITCH_MODE( action ) {
// Unselect blocks when we switch to the code editor.
if ( action.mode !== 'visual' ) {
dispatch( 'core/editor' ).clearSelectedBlock();
}

const message = action.mode === 'visual' ? __( 'Visual editor selected' ) : __( 'Code editor selected' );
speak( message, 'assertive' );
},
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Inserter extends Component {
children,
onInsertBlock,
rootClientId,
disabled,
} = this.props;

if ( items.length === 0 ) {
Expand All @@ -61,6 +62,7 @@ class Inserter extends Component {
className="editor-inserter__toggle"
aria-haspopup="true"
aria-expanded={ isOpen }
disabled={ disabled }
>
{ children }
</IconButton>
Expand Down
31 changes: 30 additions & 1 deletion test/e2e/specs/editor-modes.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
*/
import { clickBlockAppender, newPost } from '../support/utils';
import { clickBlockAppender, newPost, switchToEditor } from '../support/utils';

describe( 'Editing modes (visual/HTML)', () => {
beforeEach( async () => {
Expand Down Expand Up @@ -80,4 +80,33 @@ describe( 'Editing modes (visual/HTML)', () => {
htmlBlockContent = await page.$eval( '.editor-block-list__layout .editor-block-list__block .editor-block-list__block-html-textarea', ( node ) => node.textContent );
expect( htmlBlockContent ).toEqual( '<p class="has-large-font-size">Hello world!</p>' );
} );

it( 'the code editor should unselect blocks and disable the inserter', async () => {
// The paragraph block should be selected
const title = await page.$eval(
'.editor-block-inspector__card-title',
( element ) => element.innerText
);
expect( title ).toBe( 'Paragraph' );

// The Block inspector should be active
let blockInspectorTab = await page.$( '.edit-post-sidebar__panel-tab.is-active[aria-label="Block settings"]' );
expect( blockInspectorTab ).not.toBeNull();

// Switch to Code Editor
await switchToEditor( 'Code' );

// The Block inspector should not be active anymore
blockInspectorTab = await page.$( '.edit-post-sidebar__panel-tab.is-active[aria-label="Block settings"]' );
expect( blockInspectorTab ).toBeNull();

// No block is selected
await page.click( '.edit-post-sidebar__panel-tab[aria-label="Block settings"]' );
const noBlocksElement = await page.$( '.editor-block-inspector__no-blocks' );
expect( noBlocksElement ).not.toBeNull();

// The inserter is disabled
const disabledInserter = await page.$( '.editor-inserter > button:disabled' );
expect( disabledInserter ).not.toBeNull();
} );
} );