---
title: "Wait for text composition to end before · Agent Wranglers"
url: https://agentwranglers.se/playbook/localization/layout-and-scripts/input-composition
id: LOC-52
level: Recommended
updated: 2026-10-22
build: a2a6bdfed830
tokens: 784
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Wait for text composition to end before acting on Enter

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Layout and scripts](https://agentwranglers.se/playbook/localization/layout-and-scripts.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-22.

- ID: LOC-52
- Level: Recommended
- Chapter: [Layout and scripts](https://agentwranglers.se/playbook/localization/layout-and-scripts.md)
- Rule: Ignore Enter and other shortcut keys while an input method is composing text. Send a message or run a search only after composition ends.
- Check: A browser test dispatches `keydown` Enter with `isComposing: true` in the message field, and no message is sent. The same key with `isComposing: false` sends it.
- How: People typing Japanese, Chinese or Korean build each word in an input method editor, and many phone keyboards work the same way. Enter there confirms the word. Code that sends on every Enter sends half-typed text. In a browser, skip key events whose `isComposing` is true, or whose `keyCode` is 229. On iOS, act only when `markedTextRange` is empty. Run these tests in the same suite as [Test with a pseudo-locale](https://agentwranglers.se/playbook/localization/layout-and-scripts/pseudo-localisation.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript example

```js
const IME_PROCESSING_KEY_CODE = 229;
input.addEventListener('keydown', event => {
  if (event.isComposing || event.keyCode === IME_PROCESSING_KEY_CODE) return;
  if (event.key === 'Enter') sendMessage(input.value);
});
```

### Plain text example

```swift
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
    guard text == "\n", textView.markedTextRange == nil else { return true }
    sendMessage(textView.text)
    return false
}
```

## Sources

- [W3C UI Events (Key events during composition)](https://www.w3.org/TR/uievents/#keys-IME)

## Related rules

- LOC-14 [Test with a pseudo-locale](https://agentwranglers.se/playbook/localization/layout-and-scripts/pseudo-localisation.md) in Localization

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/localization/layout-and-scripts/input-composition">Agent Wranglers localization playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Support vertical and CJK text](https://agentwranglers.se/playbook/localization/layout-and-scripts/writing-modes.md)
- Next: [Cover every script with fonts and break words with a segmenter](https://agentwranglers.se/playbook/localization/layout-and-scripts/scripts-fonts-and-line-breaks.md)
- [Layout and scripts](https://agentwranglers.se/playbook/localization/layout-and-scripts.md)
