Skip to content

[macOS] TextField lost input event after composing text deleted #100272

Closed

Description

@boyan01

Noticed that #78061 has been fixed, but there seems to be a small problem here.

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. type Chinese by PinYin input method.
    for example: type nihao

image

  1. press backspace to delete all composing text in floating view.
  2. when all composing text be deleted, this TextField can not input number, character any more.

Expected results:

Actual results:

2022-03-17.10.38.28.mov
Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue
      ),
      home: const _HomePage(),
    );
  }
}


class _HomePage extends StatelessWidget {
  const _HomePage({ Key? key }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body:  Center(
        child: TextField(),
      ),
    );
  }
}
Logs
➜  my_app flutter --version
Flutter 2.13.0-0.0.pre.114 • channel master •
https://github.com/flutter/flutter.git
Framework • revision b4040c867b (15 minutes ago) • 2022-03-17 10:15:13 +0800
Engine • revision 46c2ccae24
Tools • Dart 2.17.0 (build 2.17.0-202.0.dev) • DevTools 2.11.4

Activity

  1. added
    a: text inputEntering text in a text field or keyboard related problems
    engineflutter/engine related. See also e: labels.
    platform-macosBuilding on or for macOS specifically
    P2Important issues not at the top of the work list
    on Mar 17, 2022
  2. cbracken commented on Mar 17, 2022

    @cbracken
    Member

    /cc @LongCatIsLooong (and myself)

  3. added
    P1High-priority issues at the top of the work list
    and removed
    P2Important issues not at the top of the work list
    on Mar 17, 2022
  4. cbracken commented on Mar 17, 2022

    @cbracken
    Member

    This also reproduces with macOS Japanese - Romaji input method.

    To be very slightly more specific with the repro steps:

    1. Input and commit some text into a textfield. A simple option would be the text 'hello'.
    2. Switch the system input method to Pinyin or Japanese.
    3. Begin typing some composing text but do not commit. e.g. 'nihao'
    4. Press backspace until the composing region is empty.
    5. While remaining in Pinyin or Japanese mode, type a character such as 'n'. Note that backspace works as expected here; input characters do not.

    Expected behaviour: composing region now contains the character typed (e.g. 'n')

    Actual behaviour: composing region contains nothing, IME candidate menu pops up at screen position (0,0), but contains the correct composing text.

    I haven't tried debugging this, but I suspect that we've got an off-by-one error in how we set the composing state. In other words, we're leaving TextInputModel in composing mode after the last character is deleted, or we're failing to begin composing and activate the IME once the first new character is typed after deleting all text in the composing range.

    A couple more hints at what's going on here:

    • the IME candidates menu position is the combination of two inputs. I'm going from memory here, so we'll want to double-check this, but one is the composing rect in window co-ordinates, the other is a coordinate transform matrix. I suspect we only apply/update the position in screen co-ordinates when we're composing, which would be further evidence that we're not in composing mode when we type that first character after deleting all text in the composing range.
    • the IME candidates popup contains the correct composing text but it's clear that we're not sending this from the engine to the framework and possibly (probably?) not updating the composing text in TextInputModel.
  5. LongCatIsLooong commented on Mar 18, 2022

    @LongCatIsLooong
    Contributor

    The NSTextInputContext we use in the text input plugin seems to be deactivating itself whenever the composing region is deleted, without even calling NSTextInputContext.deactive. There's a NSTextInputContext.isActive private method that can be used to confirm this.

    The right fix seems to be properly incorporate FlutterTextInputPlugin into the responder chain (or view hierarchy), and make it the primary focus when it's supposed to be taking input. But I think the change is going to be substantial. Calling [_textInputContext activate] before [_textInputContext handleEvent:] also seems to work but it's quite hacky.

  6. cbracken commented on Mar 22, 2022

    @cbracken
    Member

    This was resolved in flutter-team-archive/engine#32117.

  7. LongCatIsLooong commented on Mar 22, 2022

    @LongCatIsLooong
    Contributor

    @cbracken I was planning to repurpose this issue for properly setting up the responder chain on macOS for text input. Should I create a new issue instead?

  8. LongCatIsLooong commented on Mar 22, 2022

    @LongCatIsLooong
    Contributor

    Created #100590

  9. cbracken commented on Mar 23, 2022

    @cbracken
    Member

    Ah thanks; this was listed on the stable blockers dashboard and had moved it to done. Thanks for creating a new issue for the proper strategic fix for this!

  10. github-actions commented on Apr 6, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  11. locked as resolved and limited conversation to collaborators on Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P1High-priority issues at the top of the work lista: desktopRunning on desktopa: text inputEntering text in a text field or keyboard related problemsengineflutter/engine related. See also e: labels.platform-macosBuilding on or for macOS specifically

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions