Skip to content

Block API: Scope variation keyboard shortcuts to their own block type - #81624

Merged
youknowriad merged 1 commit into
claude/block-shortcuts-review-followupfrom
claude/block-shortcuts-scope-to-block-type
Aug 17, 2026
Merged

youknowriad merged 1 commit into
claude/block-shortcuts-review-followupfrom
claude/block-shortcuts-scope-to-block-type

Conversation

@youknowriad

Copy link
Copy Markdown
Contributor

What?

Follow-up to #81588. Stacked on #81621 — review that one first, and this base retargets to trunk once it lands.

A variation shortcut applied to any block with a transform to the variation's block type. core/group, core/quote, core/details and core/columns all have wildcard from transforms, so a shortcut on one of their variations would have fired on every selected block.

How?

Variation shortcuts now apply only where the selected block is already of that block type. Reaching a variation from another block type is a transform, and is declared as one: a type: 'block' transform takes a shortcuts list rather than a single shortcut, and each entry may name the variation it produces via variationName.

That last part is what keeps the block switcher untouched. Transforms are 1:1 with switcher entries, so six level-specific transforms would put six "Heading" rows in a paragraph's menu — BlockTransformationItem renders the block type's own title and never resolves the variation's. Hanging six shortcuts off one transform avoids that.

The heading level shortcuts are declared in both places under the same name: on the h1–h6 variations for a selected heading, and on the transform from paragraph for everything else. The two can never both apply to one selection. Registering a name more than once is therefore expected, and only declarations that disagree warn.

blockNames is now always populated, so the unrestricted case is gone structurally rather than by an opt-out authors have to remember.

No changelog entries: this refines the unreleased #81588 feature already described under ## Unreleased.

Testing Instructions

Behaviour should be unchanged.

  1. Select a paragraph, press Alt+Shift+2 (Ctrl+Alt+2 on macOS). It becomes an H2.
  2. Press Alt+Shift+4, then again. The level changes once; the post is not dirtied the second time.
  3. Press Alt+Shift+0 (or 7). It becomes a paragraph.
  4. Select a paragraph and open the block switcher. "Heading" appears once, as before.
  5. Open the keyboard shortcuts help modal (Alt+Shift+H). The seven shortcuts are listed once each under "Block shortcuts", with no console warnings.

Testing Instructions for Keyboard

The feature is keyboard-only; the steps above cover it.

Use of AI Tools

Authored with Claude Code (Opus 5).

A variation shortcut applied to any block with a transform to the
variation's block type, so a shortcut on a variation of a block with a
wildcard transform — group, quote, details, columns — would have fired on
every selected block.

It now applies only where the selected block is already of that type.
Reaching a variation from another block type is a transform, and is
declared as one: a `type: 'block'` transform takes a `shortcuts` list
rather than a single `shortcut`, and each entry may name the variation it
produces. One transform can therefore carry a shortcut per variation
without gaining an entry in the block switcher for each.

The heading level shortcuts are declared in both places under one name:
on the variations, for a heading, and on the transform from a paragraph.
Registering a name more than once is expected as long as the declarations
agree; only conflicting ones warn.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions

github-actions Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: mcsf <mcsf@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions github-actions Bot added [Package] Blocks /packages/blocks [Package] Block library /packages/block-library [Package] Block editor /packages/block-editor labels Aug 14, 2026
@github-actions

Copy link
Copy Markdown

Size Change: +68 B (0%)

Total Size: 7.73 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 461 kB +42 B (+0.01%)
build/scripts/block-library/index.min.js 358 kB +9 B (0%)
build/scripts/blocks/index.min.js 45.5 kB +17 B (+0.04%)

compressed-size-action

@mcsf mcsf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review disclaimer: I'm focusing on the final API. To everything else I only gave a cursory review, based on the more thorough review I had done of the precursor (#81588) and based on my trust in you. Proceed accordingly. :)

@youknowriad
youknowriad merged commit 7777e61 into claude/block-shortcuts-review-followup Aug 17, 2026
44 of 50 checks passed
@youknowriad
youknowriad deleted the claude/block-shortcuts-scope-to-block-type branch August 17, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor [Package] Block library /packages/block-library [Package] Blocks /packages/blocks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants