Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 3 additions & 1 deletion packages/block-editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ function Items( {
'disabled' &&
__unstableGetEditorMode() !== 'zoom-out'
: rootClientId === selectedBlockClientId ||
( ! rootClientId && ! selectedBlockClientId ) ),
( ! rootClientId &&
! selectedBlockClientId &&
! _order.length ) ),
};
},
[ rootClientId, hasAppender, hasCustomAppender ]
Expand Down
39 changes: 34 additions & 5 deletions packages/editor/src/components/editor-canvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import {
__experimentalUseResizeCanvas as useResizeCanvas,
} from '@wordpress/block-editor';
import { useEffect, useRef, useMemo } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { useRegistry, useSelect } from '@wordpress/data';
import { parse } from '@wordpress/blocks';
import { store as coreStore } from '@wordpress/core-data';
import { useMergeRefs } from '@wordpress/compose';
import { useMergeRefs, useRefEffect } from '@wordpress/compose';

/**
* Internal dependencies
Expand All @@ -39,8 +39,6 @@ const {
useFlashEditableBlocks,
} = unlock( blockEditorPrivateApis );

const noop = () => {};

/**
* These post types have a special editor where they don't allow you to fill the title
* and they don't apply the layout styles.
Expand Down Expand Up @@ -97,6 +95,7 @@ function EditorCanvas( {
iframeProps,
children,
} ) {
const registry = useRegistry();
const {
renderingMode,
postContentAttributes,
Expand Down Expand Up @@ -308,9 +307,39 @@ function EditorCanvas( {

const localRef = useRef();
const typewriterRef = useTypewriter();
const paddingAppenderRef = useRefEffect( ( node ) => {
function onMouseDown( event ) {
if ( event.target !== node ) {
return;
}

// only handle clicks under the last child
const lastChild = node.lastElementChild;
if ( ! lastChild ) {
return;
}

const lastChildRect = lastChild.getBoundingClientRect();
if ( event.clientY < lastChildRect.bottom ) {
return;
}

const { insertDefaultBlock } =
registry.dispatch( blockEditorStore );

insertDefaultBlock();

event.preventDefault();
}
node.addEventListener( 'mousedown', onMouseDown );
return () => {
node.removeEventListener( 'mousedown', onMouseDown );
};
}, [] );
const contentRef = useMergeRefs( [
localRef,
renderingMode === 'post-only' ? typewriterRef : noop,
renderingMode === 'post-only' ? typewriterRef : null,
renderingMode === 'post-only' ? paddingAppenderRef : null,
useFlashEditableBlocks( {
isEnabled: renderingMode === 'template-locked',
} ),
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/specs/editor/plugins/custom-post-types.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ test.describe( 'Test Custom Post Types', () => {
page,
} ) => {
await admin.createNewPost( { postType: 'leg_block_in_tpl' } );
await editor.canvas
.locator( 'role=button[name="Add default block"i]' )
.click();
await editor.insertBlock( { name: 'core/paragraph' } );
await page.keyboard.type( 'Hello there' );

await expect.poll( editor.getBlocks ).toMatchObject( [
Expand Down
8 changes: 2 additions & 6 deletions test/e2e/specs/editor/various/copy-cut-paste.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ test.describe( 'Copy/cut/paste', () => {
await page.evaluate( () => {
window.wp.data.dispatch( 'core/block-editor' ).clearSelectedBlock();
} );
await editor.canvas
.locator( 'role=button[name="Add default block"i]' )
.click();
await editor.insertBlock( { name: 'core/paragraph' } );
await pageUtils.pressKeys( 'primary+v' );
expect( await editor.getEditedPostContent() ).toMatchSnapshot();
} );
Expand All @@ -85,9 +83,7 @@ test.describe( 'Copy/cut/paste', () => {
await page.evaluate( () => {
window.wp.data.dispatch( 'core/block-editor' ).clearSelectedBlock();
} );
await editor.canvas
.locator( 'role=button[name="Add default block"i]' )
.click();
await editor.insertBlock( { name: 'core/paragraph' } );
await pageUtils.pressKeys( 'primary+v' );
expect( await editor.getEditedPostContent() ).toMatchSnapshot();
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,6 @@ test.describe( 'Order of block keyboard navigation', () => {
.focus();
} );

await pageUtils.pressKeys( 'shift+Tab' );
await KeyboardNavigableBlocks.expectLabelToHaveFocus( 'Add block' );

await pageUtils.pressKeys( 'shift+Tab' );
await KeyboardNavigableBlocks.expectLabelToHaveFocus(
'Add default block'
);

await pageUtils.pressKeys( 'shift+Tab' );
await KeyboardNavigableBlocks.expectLabelToHaveFocus(
'Paragraph Block. Row 2. 1'
Expand Down