修复输入框的输入法兼容问题
检查输入事件、输入法组合状态与快捷键冲突,输出代码修复建议和跨语言手动测试清单。
完整提示词
<context>
Chinese, Japanese and Korean users type through an input method editor (IME): keystrokes build a composition that is only committed when they choose a candidate, usually with Enter or Space. Code that listens to `keydown` for Enter sends the message mid-composition; code that runs on every `input` event (search-as-you-type, validation, auto-formatting, controlled React inputs that reset the value) fights the IME and duplicates or drops characters. The browser marks composition with `compositionstart`/`compositionend` and `event.isComposing` (and a legacy `keyCode` 229 in some browsers). Keyboard shortcuts break separately: `event.key` is the produced character and `event.code` the physical key, so a shortcut bound to `code === "KeyZ"` fires on the key labelled W on AZERTY and Y on German QWERTZ, while `/` or `[` need Shift or AltGr on many layouts. `event.key` suits letter mnemonics and `event.code` suits games and position-based controls; on non-Latin layouts such as Russian, `event.key` gives a Cyrillic letter, so mnemonic shortcuts need a fallback to `code`. AltGr arrives as Ctrl+Alt on Windows, so a Ctrl+Alt shortcut can block typing "@" or "€".
</context>
<task>
Check and fix text input in:
{{code}}
{{#symptoms}}Reported symptoms: {{symptoms}}{{/symptoms}}
1. List every handler on text inputs and editors: `keydown`, `keypress`, `input`, `beforeinput`, `change`, framework `onChange`, and global shortcut listeners.
2. For each, check composition safety: ignore Enter and other commit keys while `isComposing` is true (or between `compositionstart` and `compositionend`); defer search, validation, masking and auto-formatting until composition ends; make sure controlled inputs do not overwrite the value during composition.
3. Fix each issue with the smallest change for the framework in use, and keep a shared helper if several components need the same guard.
4. Shortcuts: decide per shortcut whether it means a character (use `event.key`) or a physical position (use `event.code`); avoid Ctrl+Alt combinations that collide with AltGr; make sure single-key shortcuts do not fire while the focus is in a text field or during composition; show shortcut labels that match the user's layout where the platform allows.
5. Other input: allow pasted and IME-produced full-width characters where valid (normalize full-width digits for numeric fields instead of rejecting them), and do not block input with `maxlength` counting mid-composition.
6. Tests: add automated tests that dispatch composition events where the test tool supports it, and write a manual test plan with Japanese (Romaji input), Chinese (Pinyin), Korean (Hangul, which composes syllables character by character) and a German or French layout, on at least two browsers and OSes.
</task>
<constraints>
- Do not disable or work around the IME (for example by forcing `ime-mode` or stripping composition text).
- Keep current behaviour for users without an IME.
- Note browser differences you rely on as things to confirm in the manual test, not as settled facts.
{{> output/uncertainty}}
</constraints>
<output_format>
## Findings
| Location | Handler | Problem | Who it affects |
## Fixes
Diff per file.
## Shortcut handling
Each shortcut with key versus code decision and conflicts removed.
## Manual test plan
A checklist by language, layout, browser and OS.
</output_format>可替换内容
- {{code}}
- {{#symptoms}}
- {{symptoms}}
- {{/symptoms}}
- {{> output/uncertainty}}
分类与标签
编程开发、输入法兼容、前端表单、键盘快捷键