Skip to content

Scroll to selected block when switching viewport preview #74550

@sunmorgn

Description

@sunmorgn

What problem does this address?

When using the viewport preview feature (Mobile/Tablet/Desktop buttons in the editor toolbar), the editor canvas resizes but does not maintain scroll position relative to the currently selected block.

I'm always frustrated when switching between viewport sizes because I lose my place in the document. On longer pages, I have to manually scroll to find the block I was working on after each viewport switch. This significantly slows down the responsive design workflow.

Steps to reproduce:

  1. Create a page with multiple blocks (enough to require scrolling)
  2. Select a block that's not at the top of the page
  3. Click the viewport preview button (e.g., switch from Desktop to Mobile)
  4. Observe that the selected block is no longer visible in the viewport

What is your proposed solution?

Automatically scroll to the currently selected block after switching viewport preview modes.

The implementation would:

  1. Subscribe to device type changes in the editor store
  2. Track the currently selected block
  3. After the viewport transition animation completes (~500ms), scroll the selected block into view (centered)

I have an elegent working solution and am happy to submit a PR if this approach is acceptable - would love to see this improvement in 7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions