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
7 changes: 7 additions & 0 deletions src/runtime/composables/defineShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ export function defineShortcuts(config: MaybeRef<ShortcutsConfig>, options: Shor
const shiftableCodes = shiftableKeys.map(k => convertKeyToCode(k))

const onKeyDown = (e: KeyboardEvent) => {
// 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
}

Comment on lines +111 to +117

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`.

// Input autocomplete triggers a keydown event
if (!e.key) {
return
Expand Down
28 changes: 28 additions & 0 deletions test/composables/defineShortcuts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,32 @@ describe('defineShortcuts', () => {
expect(handler).not.toHaveBeenCalled()
})
})

describe('IME composition', () => {
it('does NOT trigger a shortcut while composing', async () => {
const handler = vi.fn()
await registerShortcuts({ a: handler })

fireKeydown('a', { isComposing: true })
expect(handler).not.toHaveBeenCalled()
})

it('does NOT accumulate chained input while composing', async () => {
const handler = vi.fn()
await registerShortcuts({ 'g-i': handler })

fireKeydown('g', { isComposing: true })
fireKeydown('i', { isComposing: true })
expect(handler).not.toHaveBeenCalled()
})

it('triggers once composition has ended', async () => {
const handler = vi.fn()
await registerShortcuts({ a: handler })

fireKeydown('a', { isComposing: true })
fireKeydown('a')
expect(handler).toHaveBeenCalledOnce()
})
})
})
Loading