Skip to content

[macOS] Setting composing range to TextRange.collapsed(0) breaks text input #64741

Closed

Description

@pulyaevskiy

Steps to Reproduce

  1. Clone https://github.com/memspace/zefyr.git
  2. Go to packages/zefyr/example and run with flutter run -d macOS
  3. Click on "Embedded in a form" example
  4. In the middle multiple field (that's ZefyrEditor) type in abc and press Enter

Expected results:

Enter should've added a new line

Actual results:

No new line appears.
While debugging I noticed that in my TextInputClient.updateEditingValue I get unexpected control characters when pressing Enter (13 (\r) instead of 10 (\n)), Delete (adds 8 code unit to the text) and arrow keys also modify the text itself instead of changing selection.

I scanned through the standard EditableTextState implementation and couldn't find anything that would indicate any issues in the way I set up input connection or handle updates.

When I use regular multiline TextField everything looks correct there and no special characters are present.

In the attached logs at the very end I have some printed statements for the raw text code units I receive from the platform side.

Logs

Logs were too big for a Github comment, so here is Gist:
https://gist.github.com/pulyaevskiy/5a1b28545994f0dae73185ba476c5929

$ flutter analyze
Analyzing example...
No issues found! (ran in 3.2s)
[✓] Flutter (Channel master, 1.22.0-2.0.pre.93, on Mac OS X 10.15.6 19G73, locale en-US)
    • Flutter version 1.22.0-2.0.pre.93 at /Users/anatoly/Projects/flutter
    • Framework revision f35a8b7470 (14 hours ago), 2020-08-26 21:33:03 -0700
    • Engine revision 388193a67b
    • Dart version 2.10.0 (build 2.10.0-62.0.dev)

[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/anatoly/Library/Android/sdk
    ✗ Flutter requires Android SDK 29 and the Android BuildTools 28.0.3
      To update using sdkmanager, run:
        "/Users/anatoly/Library/Android/sdk/tools/bin/sdkmanager" "platforms;android-29" "build-tools;28.0.3"
      or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions.
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.6, Build version 11E708
    • CocoaPods version 1.9.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio
    • Android Studio at /Applications/Android Studio 3.2 Preview.app/Contents
    • Flutter plugin version 28.0.2
    • Dart plugin version 181.5616
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 48.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] IntelliJ IDEA Community Edition (version 2018.1.6)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 26.0.2
    • Dart plugin version 181.4892.1

[✓] VS Code (version 1.39.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.6.0

[✓] Connected device (3 available)
    • macOS (desktop)  • macos      • darwin-x64     • Mac OS X 10.15.6 19G73
    • Web Server (web) • web-server • web-javascript • Flutter Tools
    • Chrome (web)     • chrome     • web-javascript • Google Chrome 84.0.4147.135

! Doctor found issues in 1 category.

Activity

  1. pulyaevskiy commented on Aug 28, 2020

    @pulyaevskiy
    ContributorAuthor

    I found a fix for my issue - I had hardcoded initial value for composing range as 0 which was causing this weird behavior in the text input plugin. After setting it to -1 everything works as expected.

    Even though my issue is resolved it still seems like something can be improved on the Flutter side of things so I'll keep this open. At least adding validation for composing range to prevent this from happening. I'm still not sure why would this have such a weird impact on the plugin's behavior.

  2. markusaksli-nc commented on Aug 28, 2020

    @markusaksli-nc
    Contributor

    Hi @pulyaevskiy
    Can you please provide a minimal complete reproducible code sample to demonstrate this issue? The example contains a lot of ancillary code from this third-party package.
    Thank you

  3. added
    in triagePresently being triaged by the triage team
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Aug 28, 2020
  4. pulyaevskiy commented on Aug 28, 2020

    @pulyaevskiy
    ContributorAuthor

    Sure, I was able to reproduce this with standard TextField.

    Steps:

    1. Create a new app with flutter create
    2. Replace contents of main.dart with the below snippet
    3. Run the app in macOS
    4. Press "Set composing to 0" button
    5. Type something in the input. Try pressing Enter and Delete keys.

    Expected result: Enter adds a new line. Delete removes a character.
    Actual result: Enter adds a \r and Delete adds some other special character to the text value.

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
            visualDensity: VisualDensity.adaptivePlatformDensity,
          ),
          home: MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      MyHomePage({Key key, this.title}) : super(key: key);
      final String title;
    
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      final TextEditingController _controller = TextEditingController();
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: Text(widget.title)),
          body: Center(
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  TextField(
                    controller: _controller,
                    maxLines: 4,
                  ),
                  SizedBox(height: 16),
                  RaisedButton(
                    child: Text('Set composing to 0'),
                    onPressed: () {
                      _controller.value = _controller.value
                          .copyWith(composing: TextRange.collapsed(0));
                    },
                  ),
                ],
              ),
            ),
          ),
        );
      }
    }
  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Aug 28, 2020
  6. changed the title [-]Custom TextInputClient on macOS gets unexpected control characters in edited text[/-] [+]Setting composing range to TextRange.collapsed(0) on macOS breaks text input[/+] on Aug 28, 2020
  7. TahaTesser commented on Aug 31, 2020

    @TahaTesser
    Contributor

    Hi @pulyaevskiy
    Thanks for providing a code sample and steps to reproduce the issue

    I can reproduce the issue but there are no special characters when the Delete key is pressed, it just doesn't delete and Enter doesn't add a new line

    flutter doctor -v
    [✓] Flutter (Channel dev, 1.22.0-1.0.pre, on Mac OS X 10.15.6 19G2021, locale
        en-GB)
        • Flutter version 1.22.0-1.0.pre at /Users/tahatesser/Code/flutter_dev
        • Framework revision ce40de69b7 (11 days ago), 2020-08-20 07:31:50 -0700
        • Engine revision 81027ab0cc
        • Dart version 2.10.0 (build 2.10.0-45.0.dev)
    
     
    [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
        • Android SDK at /Users/tahatesser/Code/sdk
        • Platform android-29, build-tools 29.0.2
        • ANDROID_HOME = /Users/tahatesser/Code/sdk
        • Java binary at: /Applications/Android
          Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build
          1.8.0_242-release-1644-b3-6222593)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 11.6)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 11.6, Build version 11E708
        • CocoaPods version 1.9.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.0)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin version 48.1.2
        • Dart plugin version 193.7547
        • Java version OpenJDK Runtime Environment (build
          1.8.0_242-release-1644-b3-6222593)
    
    [✓] VS Code (version 1.48.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.13.2
    
    [✓] Connected device (5 available)
        • Taha’s iPhone (mobile) • 00008020-001059882212002E            • ios
          • iOS 13.6.1
        • iPhone 11 (mobile)     • A63D6F51-59F3-4A75-961F-3769709F3A92 • ios
          • com.apple.CoreSimulator.SimRuntime.iOS-13-6 (simulator)
        • macOS (desktop)        • macos                                • darwin-x64
          • Mac OS X 10.15.6 19G2021
        • Web Server (web)       • web-server                           •
          web-javascript • Flutter Tools
        • Chrome (web)           • chrome                               •
          web-javascript • Google Chrome 84.0.4147.135
    
    • No issues found!
    
    flutter doctor -v
    [✓] Flutter (Channel master, 1.22.0-2.0.pre.139, on Microsoft Windows [Version 10.0.19041.450], locale en-US)
        • Flutter version 1.22.0-2.0.pre.139 at C:\Code\flutter_master
        • Framework revision c0ea00ed3f (3 hours ago), 2020-08-30 22:20:16 -0700
        • Engine revision bada9fc5f3
        • Dart version 2.10.0 (build 2.10.0-76.0.dev)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
        • Android SDK at C:\Code\sdk
        • Platform android-30, build-tools 30.0.2
        • ANDROID_HOME = C:\Code\sdk
        • Java binary at: C:\Code\android-studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
        • All Android licenses accepted.
    
    [✓] Chrome - develop for the web
        • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
    
    [✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.2)
        • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
        • Visual Studio Community 2019 version 16.7.30413.136
        • Windows 10 SDK version 10.0.18362.0
    
    [✓] Android Studio (version 4.0)
        • Android Studio at C:\Code\android-studio
        • Flutter plugin version 48.1.2
        • Dart plugin version 193.7547
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    
    [✓] VS Code (version 1.48.2)
        • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.13.2
    
    [✓] Connected device (3 available)
        • Windows (desktop) • windows    • windows-x64    • Microsoft Windows [Version 10.0.19041.450]
        • Web Server (web)  • web-server • web-javascript • Flutter Tools
        • Chrome (web)      • chrome     • web-javascript • Google Chrome 84.0.4147.135
    
    • No issues found!
    
  8. added
    engineflutter/engine related. See also e: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    platform-macosBuilding on or for macOS specifically
    a: text inputEntering text in a text field or keyboard related problems
    and removed
    in triagePresently being triaged by the triage team
    on Aug 31, 2020
  9. 15 remaining items

  10. eseidelGoogle commented on Oct 19, 2021

    @eseidelGoogle
    Contributor

    @cbracken believes this is an uncommon flow and this should not be a blocker, but should be an easy-ish fix once we have time.

  11. justinmc commented on Oct 19, 2021

    @justinmc
    Contributor

    Unassigning myself while I look at #91859, but will come back to this once we've got that sorted.

  12. removed their assignment
    on Oct 19, 2021
  13. self-assigned this
    on Aug 5, 2022
  14. a-wallen commented on Aug 5, 2022

    @a-wallen
    Contributor
  15. a-wallen commented on Aug 5, 2022

    @a-wallen
    Contributor
  16. a-wallen commented on Aug 6, 2022

    @a-wallen
    Contributor
    • @cbracken the steps provided are no longer able to reproduce the behavior that you mentioned. It must have been fixed by a PR that I can't find.
  17. Repository owner moved this from Todo to Done in Flutter Desktopon Aug 6, 2022
  18. changed the title [-]Setting composing range to TextRange.collapsed(0) on macOS breaks text input[/-] [+][macOS] Setting composing range to TextRange.collapsed(0) breaks text input[/+] on Aug 18, 2022
  19. github-actions commented on Sep 1, 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.

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

Metadata

Metadata

Assignees

Labels

P2Important issues not 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.found in release: 1.22Found to occur in 1.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-macosBuilding on or for macOS specifically

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions