Skip to content

Commit

Permalink
Fix: Global inserter never appears if inserting at the root level is …
Browse files Browse the repository at this point in the history
…not possible
  • Loading branch information
jorgefilipecosta committed May 5, 2020
1 parent 464026a commit 4c2bc98
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/e2e-tests/plugins/cpt-locking.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function gutenberg_test_cpt_locking() {
),
),
array( 'core/quote' ),
array( 'core/columns' ),
);
register_post_type(
'locked-all-post',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ exports[`cpt locking template_lock all should not error when deleting the cotent
<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p></p></blockquote>
<!-- /wp:quote -->"
<!-- /wp:quote -->
<!-- wp:columns -->
<div class=\\"wp-block-columns\\"></div>
<!-- /wp:columns -->"
`;
exports[`cpt locking template_lock false should allow blocks to be inserted 1`] = `
Expand All @@ -27,6 +31,10 @@ exports[`cpt locking template_lock false should allow blocks to be inserted 1`]
<blockquote class=\\"wp-block-quote\\"><p></p></blockquote>
<!-- /wp:quote -->
<!-- wp:columns -->
<div class=\\"wp-block-columns\\"></div>
<!-- /wp:columns -->
<!-- wp:list -->
<ul><li>List content</li></ul>
<!-- /wp:list -->"
Expand All @@ -43,7 +51,11 @@ exports[`cpt locking template_lock false should allow blocks to be moved 1`] = `
<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p></p></blockquote>
<!-- /wp:quote -->"
<!-- /wp:quote -->
<!-- wp:columns -->
<div class=\\"wp-block-columns\\"></div>
<!-- /wp:columns -->"
`;
exports[`cpt locking template_lock false should allow blocks to be removed 1`] = `
Expand All @@ -53,7 +65,11 @@ exports[`cpt locking template_lock false should allow blocks to be removed 1`] =
<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p></p></blockquote>
<!-- /wp:quote -->"
<!-- /wp:quote -->
<!-- wp:columns -->
<div class=\\"wp-block-columns\\"></div>
<!-- /wp:columns -->"
`;
exports[`cpt locking template_lock insert should allow blocks to be moved 1`] = `
Expand All @@ -67,5 +83,9 @@ exports[`cpt locking template_lock insert should allow blocks to be moved 1`] =
<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p></p></blockquote>
<!-- /wp:quote -->"
<!-- /wp:quote -->
<!-- wp:columns -->
<div class=\\"wp-block-columns\\"></div>
<!-- /wp:columns -->"
`;
18 changes: 18 additions & 0 deletions packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@ describe( 'cpt locking', () => {
'The content of your post doesn’t match the template assigned to your post type.'
);
} );

it( 'can use the global inserter in inner blocks', async () => {
await page.click( 'button[aria-label="Two columns; equal split"]' );
await page.click(
'.wp-block-column .block-editor-button-block-appender'
);
await page.type( '.block-editor-inserter__search-input', 'image' );
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Enter' );
await page.click( '.edit-post-header-toolbar__inserter-toggle' );
await page.type(
'.block-editor-inserter__search-input',
'gallery'
);
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Enter' );
expect( await page.$( '.wp-block-gallery' ) ).not.toBeNull();
} );
} );

describe( 'template_lock insert', () => {
Expand Down
18 changes: 12 additions & 6 deletions packages/edit-post/src/components/header/header-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,30 @@ function HeaderToolbar( { onToggleInserter, isInserterOpen } ) {
isInserterVisible,
isTextModeEnabled,
previewDeviceType,
} = useSelect(
( select ) => ( {
} = useSelect( ( select ) => {
const {
hasInserterItems,
getBlockRootClientId,
getBlockSelectionEnd,
} = select( 'core/block-editor' );
return {
hasFixedToolbar: select( 'core/edit-post' ).isFeatureActive(
'fixedToolbar'
),
// This setting (richEditingEnabled) should not live in the block editor's setting.
isInserterEnabled:
select( 'core/edit-post' ).getEditorMode() === 'visual' &&
select( 'core/editor' ).getEditorSettings().richEditingEnabled,
isInserterVisible: select( 'core/block-editor' ).hasInserterItems(),
isInserterVisible: hasInserterItems(
getBlockRootClientId( getBlockSelectionEnd() )
),
isTextModeEnabled:
select( 'core/edit-post' ).getEditorMode() === 'text',
previewDeviceType: select(
'core/edit-post'
).__experimentalGetPreviewDeviceType(),
} ),
[]
);
};
}, [] );
const isLargeViewport = useViewportMatch( 'medium' );

const displayBlockToolbar =
Expand Down

0 comments on commit 4c2bc98

Please sign in to comment.