fix: prevent Cmd+Shift+U escape sequence leak in kitty protocol mode

Closed
AN
8mo ago
+16-14

Fixes #2198

When no unread notifications exist, pressing Cmd+Shift+U would output the escape sequence [12629;10u into the terminal. This happened because the kitty keyboard protocol encodes key events differently, causing matchShortcut to fail character matching and letting the event pass through to the terminal.

Root Cause

In matchShortcut, the layout-character match (shortcutLayoutCharacterProvider, which uses keyCode → keyboard layout translation) was placed after an early-return guard that blocked further matching for letter shortcuts when charactersIgnoringModifiers was non-empty ASCII but didn't match the shortcut key. In kitty protocol mode, charactersIgnoringModifiers carries a synthetic value, so the guard fired before the reliable keyCode-based translation had a chance to run.

Fix

Move the shortcutLayoutCharacterProvider match before the guard. The keyCode → layout translation reliably identifies the physical key (e.g. keyCode 32 → "u") regardless of keyboard protocol mode. The guard is preserved after both character sources have been tried, so cross-layout collision protection for letter shortcuts remains intact.

Test plan

  • Press Cmd+Shift+U with no unread notifications → should do nothing (no escape sequence output)
  • Press Cmd+Shift+U with unread notifications → should jump to latest unread
  • Test with kitty keyboard protocol enabled (echo -e '\e[>1u')
  • Verify other letter shortcuts (Cmd+Shift+P, Cmd+N, etc.) still work correctly on non-US keyboard layouts

Summary by cubic

Fixes #2198. Stops Cmd+Shift+U from printing a kitty keyboard protocol escape sequence when there are no unread notifications by matching the keyCode→layout character before the early guard.

  • Bug Fixes
    • Move layout-character match ahead of the ASCII guard so letter shortcuts are recognized in kitty protocol mode; Cmd+Shift+U no longer passes through.
    • Keep the guard after both character sources to avoid cross-layout collisions; other shortcuts still work on non‑US layouts.

Summary by CodeRabbit

  • Bug Fixes
    • Improved keyboard shortcut matching for Cmd-based letter shortcuts to enhance character recognition and behavior across different keyboard layouts.