Skip to content

Editor: Let Cmd+K open Add Link in a block - #1007

Merged
epeicher merged 1 commit into
trunkfrom
opensta-257-fix-k-opening-command-palette-instead-of-add-link
Oct 13, 2026
Merged

epeicher merged 1 commit into
trunkfrom
opensta-257-fix-k-opening-command-palette-instead-of-add-link

Conversation

@epeicher

@epeicher epeicher commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

What

In a block editor window, pressing ⌘K (Ctrl+K) on text opened the shell's command palette instead of the editor's Add Link popover. Now ⌘K in a block opens Add Link, and ⌘K anywhere else (sidebar, toolbar, other admin pages) still opens the shell palette.

Before After
screenshot-1791911583500-1 screenshot-1791911574679-0

Why

The chromeless bridge claims ⌘K in capture phase and forwards it to the shell as os-palette-cycle. In WP 7.1 the editor canvas is always a nested iframe. Its rich-text Add Link shortcut handles ⌘K inside the canvas, then Gutenberg re-dispatches a clone of the keydown to the admin document, targeted at the IFRAME, with defaultPrevented already set. Core's own command palette bails on that flag ("avoid obscuring the effect of the preceding handler"). The bridge ignored it and claimed the key anyway.

Fix

  • src/chromeless-bridge.js: the ⌘K forwarder returns early when the keydown is already defaultPrevented, the same rule Core's palette follows.
  • docs/bridge-protocol.md: the keyboard-forwarders section documents that exception.

Testing

  • tests/vitest/chromeless-bridge-links.test.ts: two new cases. An unclaimed ⌘K still posts os-palette-cycle; one the canvas already claimed does not. The second fails without the fix.
  • Full suite: 536 files / 6,710 tests pass; tsc --noEmit clean; eslint clean (only the existing file-length warnings).
  • Manual, on a local site with real key presses: open a post in an editor window, select a word in a paragraph, press ⌘K. Before: the shell palette opens. After: the Add Link popover opens. Click into the editor sidebar and press ⌘K: the shell palette still opens.
Open WordPress Playground Preview

The chromeless bridge claimed every Cmd+K in capture phase and sent it
to the shell palette. In the block editor the canvas is a nested
iframe: its rich-text Add Link shortcut handles Cmd+K in there, then
Gutenberg re-dispatches the keydown to the admin document with
defaultPrevented already set. Core's own palette bails on that flag;
the bridge now does too, so Cmd+K in a block opens the link popover
and Cmd+K anywhere else still opens the shell palette.
@epeicher
epeicher enabled auto-merge (squash) October 13, 2026 17:17
@epeicher
epeicher merged commit 796cb9e into trunk Oct 13, 2026
7 checks passed
@epeicher
epeicher deleted the opensta-257-fix-k-opening-command-palette-instead-of-add-link branch October 13, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant