Skip to content

fix: don't submit on Enter while an IME is composing in TextField - #7128

Open
cqxbj wants to merge 1 commit into
flet-dev:mainfrom
cqxbj:fix/ime-enter-composing
Open

cqxbj wants to merge 1 commit into
flet-dev:mainfrom
cqxbj:fix/ime-enter-composing

Conversation

@cqxbj

@cqxbj cqxbj commented Nov 23, 2026 •

Copy link
Copy Markdown

Problem

Note: reported and fixed directly in this PR — no separate issue was filed.

With shift_enter=True, when typing with an IME (Chinese / Japanese / Korean), the composing text (e.g. pinyin nihao) is shown in the input field. Pressing Enter sends this raw composing text immediately, instead of first committing it into the field.

Expected: the first Enter commits the composing letters (e.g. nihao) directly into the field as plain text; a second Enter, when no longer composing, sends it.

Root cause

_handleTextFieldKeyEvent in packages/flet/lib/src/controls/textfield.dart (and the Cupertino variant) fires submit on Enter whenever Shift is not pressed, and returns KeyEventResult.handled. It never checks the IME composing state, so the Enter that should commit the text is consumed as a submit and the IME never gets to commit. This affects both desktop and web (same Dart code).

Fix

Skip the submit branch while the IME is composing, so Enter reaches the input method and commits the text into the field:

if (submitOnEnter &&
    event is KeyDownEvent &&
    !HardwareKeyboard.instance.isShiftPressed &&
    !_controller.value.composing.isValid &&   // skip while an IME is composing
    (event.logicalKey == LogicalKeyboardKey.enter ||
        event.logicalKey == LogicalKeyboardKey.numpadEnter)) {
  widget.control.triggerEvent("submit");
  return KeyEventResult.handled;
}

TextEditingValue.composing is a valid TextRange only during active composition; when not composing it is TextRange.empty (isValid == false), so normal Enter-to-submit is unchanged. Applied to both TextField and CupertinoTextField.

Summary by Sourcery

Bug Fixes:

  • Prevent Enter from submitting TextField and CupertinoTextField input while an IME composition is active, allowing the composing text to be committed first.

With shift_enter=True, the Enter key handler fired on_submit and returned
KeyEventResult.handled even while an IME was composing, stealing the Enter
that confirms a candidate and sending the raw composing text (e.g. pinyin).

Skip the submit branch while TextEditingValue.composing is valid so the
Enter reaches the input method and commits the candidate instead. Applies
to both TextField and CupertinoTextField.
@CLAassistant

CLAassistant commented Nov 23, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants