Agent Wranglers

LOC-52Recommended

Wait for text composition to end before acting on Enter

Ignore Enter and other shortcut keys while an input method is composing text. Send a message or run a search only after composition ends.

How to do it

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.

Examples

JavaScript example

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

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
}

How to 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.

Sources

For agents: this playbook is free to use under CC 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.