Skip to content

fix(defineShortcuts): ignore key events during IME composition#6659

Open
greymoth-jp wants to merge 1 commit into
nuxt:v4from
greymoth-jp:fix/define-shortcuts-ime-composition
Open

fix(defineShortcuts): ignore key events during IME composition#6659
greymoth-jp wants to merge 1 commit into
nuxt:v4from
greymoth-jp:fix/define-shortcuts-ime-composition

Conversation

@greymoth-jp

Copy link
Copy Markdown

defineShortcuts attaches a keydown listener to window and matches every event against the registered shortcuts. It does not check whether an IME composition is in progress, so the keystrokes used to compose CJK text are treated as shortcut input.

While composing (Japanese, Chinese, and so on):

  • A shortcut registered with usingInput stays active while an input is focused, so it fires on the keys that build up a candidate, including the Enter that confirms it.
  • Each composition keydown is also pushed into chainedInputs, so composing romaji such as "gi" can match a chained shortcut like g-i.

The repo already handles this in useIMEGuard (used by ChatPrompt), which bails on event.isComposing || event.keyCode === 229. This change applies the same condition at the top of the keydown handler, so shortcuts are skipped during composition and work normally once it ends. The keyCode === 229 fallback is kept to match useIMEGuard, since isComposing is not reliable during composition in every browser.

Tests in test/composables/defineShortcuts.spec.ts cover a single-key shortcut and a chained shortcut staying quiet while isComposing is set, plus a normal press still firing after composition ends. Removing the guard makes the first two fail.

@github-actions github-actions Bot added the v4 #4488 label Jun 29, 2026
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The onKeyDown handler in defineShortcuts now returns early when a keyboard event is part of IME composition, detected via e.isComposing === true or e.keyCode === 229. This prevents composed keystrokes from matching or accumulating for chained shortcuts. A new IME composition test suite verifies that shortcuts do not fire during composition, chained sequences do not build up, and the shortcut fires once after composition ends.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: ignoring key events during IME composition in defineShortcuts.
Description check ✅ Passed The description is directly related to the change and accurately explains the IME guard and its test coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/runtime/composables/defineShortcuts.ts`:
- Around line 111-117: `defineShortcuts` currently only skips keydowns while
`e.isComposing` or `e.keyCode === 229`, which still allows the first keydown
immediately after `compositionend` to trigger shortcuts. Update the IME handling
in `defineShortcuts` to mirror the cooldown logic used by `useIMEGuard`, so the
post-composition confirmation keydown is also suppressed. Use the existing
shortcut keydown handler in `defineShortcuts` and align its guard behavior with
`useIMEGuard`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4eb44e22-a380-41e1-9f3d-a6cc68c5aabc

📥 Commits

Reviewing files that changed from the base of the PR and between a84de85 and 5cc3616.

📒 Files selected for processing (2)
  • src/runtime/composables/defineShortcuts.ts
  • test/composables/defineShortcuts.spec.ts

Comment on lines +111 to +117
// Ignore keydowns dispatched during IME composition (for example picking a
// Japanese or Chinese candidate), otherwise the composed keystrokes can match
// and fire a shortcut. Same condition as the useIMEGuard composable.
if (e.isComposing || e.keyCode === 229) {
return
}

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== useIMEGuard IME handling =="
sed -n '1,60p' src/runtime/composables/useIMEGuard.ts

echo
echo "== defineShortcuts IME handling =="
sed -n '96,140p' src/runtime/composables/defineShortcuts.ts

echo
echo "== composition-related coverage =="
rg -n "compositionend|isComposing|keyCode === 229|IME composition" src/runtime test

Repository: nuxt/ui

Length of output: 4856


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== defineShortcuts IME tests =="
sed -n '440,540p' test/composables/defineShortcuts.spec.ts

echo
echo "== defineShortcuts implementation context =="
sed -n '1,220p' src/runtime/composables/defineShortcuts.ts

echo
echo "== useIMEGuard tests =="
sed -n '1,180p' test/composables/useIMEGuard.spec.ts 2>/dev/null || true

echo
echo "== shortcut event wiring =="
rg -n "defineShortcuts\\(|onKeyDown|keydown|compositionend|useIMEGuard" src/runtime test

Repository: nuxt/ui

Length of output: 12305


Mirror the IME cooldown here too. e.isComposing || e.keyCode === 229 still lets the first keydown after compositionend through, so Safari IME-confirmation keys can trigger shortcuts. defineShortcuts should match useIMEGuard and suppress that post-composition keydown as well.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/runtime/composables/defineShortcuts.ts` around lines 111 - 117,
`defineShortcuts` currently only skips keydowns while `e.isComposing` or
`e.keyCode === 229`, which still allows the first keydown immediately after
`compositionend` to trigger shortcuts. Update the IME handling in
`defineShortcuts` to mirror the cooldown logic used by `useIMEGuard`, so the
post-composition confirmation keydown is also suppressed. Use the existing
shortcut keydown handler in `defineShortcuts` and align its guard behavior with
`useIMEGuard`.

@pkg-pr-new

pkg-pr-new Bot commented Jun 29, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxt/ui@6659

commit: 5cc3616

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

Labels

v4 #4488

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant