Skip to content

Make key filters work on non-latin keyboard layouts#869

Open
psd-coder wants to merge 1 commit intohotwired:mainfrom
psd-coder:fix-non-ascii-keypress-handling
Open

Make key filters work on non-latin keyboard layouts#869
psd-coder wants to merge 1 commit intohotwired:mainfrom
psd-coder:fix-non-ascii-keypress-handling

Conversation

@psd-coder
Copy link

Overview

Fixes key filter matching in Stimulus actions so that keyboard shortcuts defined with ASCII characters (e.g., keydown.j) work correctly when the user's active keyboard layout produces non-ASCII characters (Cyrillic, Greek, Hebrew, etc.).

Problem Statement

When users have a non-latin keyboard layout active (e.g., Russian phonetic, Greek, Hebrew), event.key contains the non-ASCII character produced by their layout rather than the Latin letter on the physical key. This caused key filters like keydown.j->controller#action to never match, making keyboard shortcuts unusable for non-latin keyboard users.

Solution Approach

  • Added normalizedKeyboardEventKey() that falls back to deriving the key from event.code when the mapped filter key is a printable ASCII character but event.key is not
  • The fallback extracts the Latin letter or digit from event.code (e.g., KeyJj, Digit33) so physical key position is used instead of the produced character
  • Fallback is skipped during IME composition (event.isComposing) to avoid interfering with input method editors
  • Added tests for Cyrillic (Bulgarian phonetic), Greek, and Hebrew layouts

Breaking Changes

None.

Testing

  • Three new test cases covering Cyrillic (й/KeyJ), Greek (ξ/KeyJ), and Hebrew (ח/KeyJ) keyboard layouts verifying the fallback works correctly

Key filters matched event.key only, so keydown.j failed on non-latin layouts.
Fallback to event.code for non-ASCII keys and add regression tests.
@ai
Copy link

ai commented Mar 10, 2026

I want to bring more attention to this issue.

Right now, hotkeys are not working in 50% cases for all US-speaking users. For instance, in Fizzy it means that user can’t trust hotkey and stop using them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants