Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions apps/desktop/src/shared/hotkeys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,32 @@ describe("isTerminalReservedEvent", () => {
}),
).toBe(true);
});

// Regression: superset-sh/superset#3365 — ctrl+c/d/z fail under non-Latin IME
// (Turkish, Korean, Russian) because event.key reflects IME-transformed char.
it("detects ctrl+c via event.code when IME mangles event.key (Turkish)", () => {
expect(
isTerminalReservedEvent({
key: "ç", // Turkish IME emits 'ç' instead of 'c'
code: "KeyC",
ctrlKey: true,
shiftKey: false,
altKey: false,
metaKey: false,
}),
).toBe(true);
});

it("detects ctrl+d via event.code when IME mangles event.key (Korean)", () => {
expect(
isTerminalReservedEvent({
key: "ㅇ", // Korean 2-Set IME emits Hangul jamo for 'd'
code: "KeyD",
ctrlKey: true,
shiftKey: false,
altKey: false,
metaKey: false,
}),
).toBe(true);
});
});
9 changes: 9 additions & 0 deletions apps/desktop/src/shared/hotkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ export function matchesHotkeyEvent(
// Use event.code to match digit keys when alt is pressed
if (/^[1-9]$/.test(key) && eventCode === `digit${key}`) return true;

// IME / non-Latin keyboard layout fallback (e.g. Turkish, Korean, Russian):
// `event.key` reflects the IME-transformed character (e.g. Turkish dead keys
// or Korean 2-Set), while `event.code` always reports the physical key.
// Without this, Ctrl+C, Ctrl+V, Ctrl+D, Ctrl+Z etc. fail to match when a
// non-Latin layout is active. Fixes superset-sh/superset#3365.
if (key.length === 1 && /^[a-z]$/.test(key) && eventCode === `key${key}`) {
return true;
}
Comment on lines +279 to +281
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.

P2 Redundant key.length === 1 guard

The leading key.length === 1 check is already implied by /^[a-z]$/.test(key) — the anchored single-character regex can only ever match a string of length 1. Dropping it makes the condition a little cleaner and avoids the reader wondering whether the two predicates cover different cases.

Suggested change
if (key.length === 1 && /^[a-z]$/.test(key) && eventCode === `key${key}`) {
return true;
}
if (/^[a-z]$/.test(key) && eventCode === `key${key}`) {

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


return eventKey === key;
}

Expand Down