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
1 change: 1 addition & 0 deletions packages/editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- `PostPanelRow`: Wrap long unbroken values (such as an author name or email) inside the row instead of overflowing the Post sidebar ([#84165](https://github.com/WordPress/gutenberg/pull/84165)).
- Visual History: Render the inline removed-text diff (`<del>`) at the theme's body color over a red-tinted background instead of recoloring it with a translucent color-matrix filter, so it keeps the theme's WCAG AA contrast on any background ([#82258](https://github.com/WordPress/gutenberg/pull/82258)).
- Notes: Stop announcing the "Add note" block menu item as opening a dialog ([#84818](https://github.com/WordPress/gutenberg/pull/84818)).
- `EditorProvider`: Keep a preview canvas from restoring a block selection written to the entity by another editor, such as the site editor's navigation sidebar ([#84832](https://github.com/WordPress/gutenberg/pull/84832)).

### Internal

Expand Down
8 changes: 6 additions & 2 deletions packages/editor/src/components/provider/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,10 @@ export const ExperimentalEditorProvider = withRegistryProvider(
return null;
}

// Selections should not be synced when in revision or preview modes.
const shouldSyncSelection =
! isInRevisionsMode && ! settings.isPreviewMode;
Comment on lines +428 to +429

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Revisions mode already forces blockEditorSettings.isPreviewMode = true (see use-block-editor-settings.js L469–471), so both cases could collapse into one check:

Suggested change
const shouldSyncSelection =
! isInRevisionsMode && ! settings.isPreviewMode;
const shouldSyncSelection = ! blockEditorSettings.isPreviewMode;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh interesting! I think I like the expanded check for both here, just in case that changes in the future.


return (
<EntityProvider kind="root" type="site">
<EntityProvider
Expand All @@ -438,10 +442,10 @@ export const ExperimentalEditorProvider = withRegistryProvider(
onChange={ onChange }
onInput={ onInput }
selection={
isInRevisionsMode ? undefined : selection
shouldSyncSelection ? selection : undefined
}
onChangeSelection={
isInRevisionsMode ? noop : onChangeSelection
shouldSyncSelection ? onChangeSelection : noop
}
settings={ blockEditorSettings }
useSubRegistry={ false }
Expand Down
45 changes: 45 additions & 0 deletions test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,51 @@ test.describe( 'Navigation sidebar - list view editing', () => {
).toBeVisible();
} );
} );

test( 'does not select blocks in the canvas preview when editing from the sidebar', async ( {
admin,
page,
requestUtils,
linkControl,
} ) => {
const createdMenu =
await requestUtils.createNavigationMenu( navMenuFixture );

await admin.visitSiteEditor( {
postId: createdMenu?.id,
postType: 'wp_navigation',
} );

const listView = page.getByRole( 'treegrid', {
name: 'Block navigation structure',
} );
const canvas = page.frameLocator( 'iframe[name="editor-canvas"]' );
const blockToolbar = page.getByRole( 'toolbar', {
name: 'Block tools',
} );

await expect( canvas.getByText( 'Existing Item' ) ).toBeVisible();

// Select an item, then add a new one from the appender. The edit is
// what carries the sidebar's selection over to the entity.
await listView.getByRole( 'link', { name: 'Existing Item' } ).click();
await listView.getByRole( 'button', { name: 'Add page' } ).click();
await linkControl.useLinkControlSearch( 'Test Page 2' );
await expect(
listView.getByRole( 'link', { name: 'Test Page 2' } )
).toBeVisible();

// The preview picks up the change without adopting the selection.
await expect( canvas.getByText( 'Test Page 2' ) ).toBeVisible();
await expect( blockToolbar ).toBeHidden();
expect(
await page.evaluate( () =>
window.wp.data
.select( 'core/block-editor' )
.getSelectedBlockClientId()
)
).toBeNull();
} );
} );

class LinkControl {
Expand Down
Loading