Skip to content

IME (CJK) commitment with Enter key causes unintended newline in multiline TextEdit #7876

@ClozedJP

Description

@ClozedJP

Describe the bug

In egui::TextEdit::multiline, when using an IME (Input Method Editor) for CJK languages (Chinese, Japanese, Korean), pressing the Enter key to commit the preedit string results in an unintended newline (\n) being inserted into the text buffer.

The Enter key should only be used to commit the composition, but egui (or the underlying winit) appears to process it as a physical "New Line" command simultaneously.

Minimal Reproducible Example

// This is the most basic code to reproduce the issue.
// No extra key handling or custom logic is involved.
ui.add(egui::TextEdit::multiline(&mut self.text));

// The problem:
// In CJK IME, one Enter key press results in:
// 1. ImeEvent::Commit (Correct)
// 2. Event::Key { key: Enter, .. } + Event::Text("\n") (Incorrect)

Steps to reproduce

  1. Use egui on Windows/macOS with a CJK IME enabled.
  2. Focus on a TextEdit::multiline field.
  3. Type characters to start an IME composition (Preedit state).
  4. Press Enter to commit the composition.
  5. Observed Behavior: The characters are committed, but a newline is added immediately after them.

Technical Findings

Based on event monitoring:

  • During the commitment frame, egui receives both the committed text and a Key::Enter press event.
  • Even when the IME is supposed to "consume" the Enter key for commitment, the event leaks through as a text input of \n.
  • This makes it impossible to implement a standard CJK writing experience where Enter only commits text without jumping to the next line.

Expected behavior

The Enter key event used for IME commitment should be suppressed or consumed, ensuring that \n is only inserted when the user explicitly intends to create a new line (i.e., when no composition is active or via a specific modifier).

Environment

  • egui version: 0.33.3
  • OS: Windows / macOS (IME issues are common across both)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions