Skip to content

UndoHistoryController does not function properly in languages like Japanese where characters are confirmed when typed. #134398

Open

Description

@hatano0x06

Is there an existing issue for this?

Steps to reproduce

  1. Input "あ"
  2. Confirm text
  3. Input "い"
  4. Confirm text
  5. Press undo
  6. Press undo again

Expected results

textformfield is empty

Actual results

"あ" remains in textformfield and "い" blinks when the undo button is pressed.

Code sample

Code sample
class SamplePage extends StatefulWidget {

  SamplePage(): super();

  @override
  SamplePageState createState() => SamplePageState();
}

class SamplePageState extends State<SamplePage> with WidgetsBindingObserver {

  final UndoHistoryController _undoController = UndoHistoryController();

  @override
  void initState() {
    super.initState();  
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          const SizedBox(height: 150,),
          TextFormField(
            maxLines:null, 
            undoController: _undoController,
          ),
          ElevatedButton(
            onPressed: (){
              _undoController.undo();
              setState(() { });
            }, 
            child: const Text("undo")
          )
        ]
      ),
    );

  }

}

Screenshots or Video

Screenshots / Video demonstration

untitled

Logs

Logs
It's too long to post, so if you need it, please leave a comment.

Flutter Doctor output

Doctor output
[√] Flutter (Channel master, 3.14.0-14.0.pre.210, on Microsoft Windows [Version 10.0.22621.2215], locale ja-JP)
    • Flutter version 3.14.0-14.0.pre.210 on channel master at C:\Users\81708\Desktop\develop\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 0d9ea62756 (7 hours ago), 2023-09-10 18:34:24 -0400
    • Engine revision 04d836f695
    • Dart version 3.2.0 (build 3.2.0-134.0.dev)
    • DevTools version 2.27.0

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\Users\81708\AppData\Local\Android\sdk
    • Platform android-33, build-tools 31.0.0
    • Java binary at: C:\Program Files\Android\Android Studio1\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2021.3)
    • Android Studio at C:\Program Files\Android\Android Studio1
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[√] VS Code (version 1.82.0)
    • VS Code at C:\Users\81708\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.72.0

[√] Connected device (4 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • Windows (desktop)       • windows       • windows-x64    • Microsoft Windows [Version 10.0.22621.2215]
    • Chrome (web)            • chrome        • web-javascript • Google Chrome 116.0.5845.180
    • Edge (web)              • edge          • web-javascript • Microsoft Edge 116.0.1938.76

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Activity

  1. dam-ease commented on Sep 11, 2023

    @dam-ease

    Hi @hatano0x06. Thanks for filing this! From my observations, clicking the undo button seems to first activate the character before clearing/deleting it.

    untitled.webm

    Although this seems very similar to #130881. Can you check these out?

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 11, 2023
  3. hatano0x06 commented on Sep 11, 2023

    @hatano0x06
    Author

    @dam-ease
    Thank you for your check!

    The issue you linked to is about not being able to redo, and this one is about not being able to undo, so I think they are different issues.
    The internal process may be the same, but the problem is different.

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 11, 2023
  5. dam-ease commented on Sep 12, 2023

    @dam-ease

    Thanks for your response. I can see different behaviours with different keyboard languages. The undo feature works fine with the English language but I see it works with the Japanese keyboard on Android but doesn't work on iOS. Also further testing with Chinese keyboard, I see the undo feature doesn't work both on Android and iOS.

    With English Keyboard

    Android iOS
    english.webm
    Simulator.Screen.Recording.-.iPhone.13.Pro.-.2023-09-11.at.21.12.43.mp4

    With Chinese Keyboard

    Android iOS
    chinese.webm
    Simulator.Screen.Recording.-.iPhone.13.Pro.-.2023-09-11.at.21.12.02.mp4

    With Japanese Keyboard

    Android iOS
    japanese.webm
    Simulator.Screen.Recording.-.iPhone.13.Pro.-.2023-09-11.at.21.10.52.mp4

    stable, master flutter doctor -v

    [✓] Flutter (Channel stable, 3.13.3, on macOS 13.0 22A380 darwin-arm64, locale
        en-NG)
        • Flutter version 3.13.3 on channel stable at
          /Users/damilolaalimi/sdks/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 2524052335 (5 days ago), 2023-09-06 14:32:31 -0700
        • Engine revision b8d35810e9
        • Dart version 3.1.1
        • DevTools version 2.25.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/damilolaalimi/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/damilolaalimi/Library/Android/sdk
        • Java binary at: /Applications/Android
          Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build
          17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14E300c
        • CocoaPods version 1.12.1
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build
          17.0.6+0-17.0.6b802.4-9586694)
    
    [✓] VS Code (version 1.81.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.50.0
    
    [✓] Connected device (6 available)
        • sdk gphone64 arm64 (mobile) • emulator-5554                        •
          android-arm64  • Android 14 (API 34) (emulator)
        • iPhone 13 Pro (mobile)      • 14B6FEE4-2F1C-401F-8804-A5115D7A6DA2 • ios
          • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
        • iPhone 14 (mobile)          • 1A122DE2-0CAB-4C3E-A395-691BF27D626F • ios
          • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
        • iPhone 14 Pro (mobile)      • 6548B0D1-7674-4306-9852-198C465F1104 • ios
          • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
        • macOS (desktop)             • macos                                •
          darwin-arm64   • macOS 13.0 22A380 darwin-arm64
        • Chrome (web)                • chrome                               •
          web-javascript • Google Chrome 116.0.5845.179
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    
    [✓] Flutter (Channel master, 3.14.0-14.0.pre.211, on macOS 13.0 22A380 darwin-arm64, locale en-NG)
        • Flutter version 3.14.0-14.0.pre.211 on channel master at /Users/damilolaalimi/fvm/versions/master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 69f6e7d15d (16 hours ago), 2023-09-11 00:50:38 -0400
        • Engine revision 7e41b064eb
        • Dart version 3.2.0 (build 3.2.0-134.0.dev)
        • DevTools version 2.27.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/damilolaalimi/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/damilolaalimi/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14E300c
        • CocoaPods version 1.12.1
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    
    [✓] VS Code (version 1.81.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.50.0
    
    [✓] Connected device (6 available)
        • sdk gphone64 arm64 (mobile) • emulator-5554                        • android-arm64  • Android 14 (API 34) (emulator)
        • iPhone 13 Pro (mobile)      • 14B6FEE4-2F1C-401F-8804-A5115D7A6DA2 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
        • iPhone 14 (mobile)          • 1A122DE2-0CAB-4C3E-A395-691BF27D626F • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
        • iPhone 14 Pro (mobile)      • 6548B0D1-7674-4306-9852-198C465F1104 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
        • macOS (desktop)             • macos                                • darwin-arm64   • macOS 13.0 22A380 darwin-arm64
        • Chrome (web)                • chrome                               • web-javascript • Google Chrome 116.0.5845.187
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    

  6. added
    a: text inputEntering text in a text field or keyboard related problems
    p: material_uimaterial_ui package in flutter/packages
    a: internationalizationSupporting other languages or locales. (aka i18n)
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-designOwned by Design Languages team
    and removed
    in triagePresently being triaged by the triage team
    on Sep 12, 2023
  7. hatano0x06 commented on Sep 12, 2023

    @hatano0x06
    Author

    Thank you.
    I would love to include the redo feature so, I'm waiting for it to be improved.

  8. 2 remaining items

  9. added
    P2Important issues not at the top of the work list
    on Sep 15, 2023
  10. Renzo-Olivares commented on Sep 28, 2023

    @Renzo-Olivares
    Contributor

    Hi @hatano0x06 thanks for reporting this issue! I will try to clear up some of the behavior observed above.

    For all platforms except Android, we prevent coalescing during CJK composition. This behavior seems to be consistent with native platform behavior, see #106473 and #108765 for more context on the motivation behind this implementation. This means that doing undo while composing will result in the state being returned to what it was before the composing began.

    In the video above for the Japanese language on iOS you can see that when undo is pressed the composition is still active as indicated by the solid underline which is why undo does nothing. Though thinking about this some more I think it is expected that undo in this case would result in an empty field. What may be happening here is that the initial state of the TextField is actively composing since the language is initially CJK, and therefore the initial state is not being saved to the history stack. The same explanation holds true for the Chinese language video on iOS.

    For Android we choose to coalesce every edit because Gboard has an active composing region even when composing english text. If we didn't then Undo/Redo would not work at all on Android.

    In the Android-English language video, it appears to work correctly because the text is never confirmed (as indicated by the solid underline), so all the states saved to the history stack include an active composing region so the user never experiences a blink. If we confirm the text in between edits then that will result in unexpected behaviors.

    The blink happens because when the text is confirmed a new history entry is pushed to the stack that does not have an active composing region. When we undo and move the history back to the previous entry with the active composing region this causes a visual blink.

    What happens in the Android-Japanese/Chinese language videos is the same issue described for the english language above plus the Android embedder seems to be resetting the composing region to (-1, -1) after our undo action adding another unexpected entry to the history stack which causes the blinking between undos. The embedder does this when the framework has changed the composing region, which happens we execute our undo action.

    I am currently working on some improvements to UndoHistory so I will keep this issue in mind.

  11. hatano0x06 commented on Sep 29, 2023

    @hatano0x06
    Author

    Thank you for your detailed explanation.
    The explanation about flashing was easy to understand and I was satisfied!

    I look forward to future improvements.
    Thank you

  12. flutter-triage-bot commented on Feb 8, 2024

    @flutter-triage-bot

    This issue is assigned to @Renzo-Olivares but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

  13. added
    ⏳Bot is counting down the days until it unassigns the issue
    on Feb 8, 2024
  14. flutter-triage-bot commented on May 10, 2024

    @flutter-triage-bot

    This issue was assigned to @Renzo-Olivares but has had no status updates in a long time. To remove any ambiguity about whether the issue is being worked on, the assignee was removed.

  15. removed
    ⏳Bot is counting down the days until it unassigns the issue
    on May 10, 2024
  16. added and removed
    team-designOwned by Design Languages team
    on May 15, 2024
  17. justinmc commented on Sep 25, 2025

    @justinmc
    Contributor

    From @Renzo-Olivares, he investigated it awhile ago, had a proof of concept, but caused other breakages. Seems like it should be possible to fix with more time.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: internationalizationSupporting other languages or locales. (aka i18n)a: text inputEntering text in a text field or keyboard related problemsfound in release: 3.13Found to occur in 3.13found in release: 3.14Found to occur in 3.14has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesteam-text-inputOwned by Text Input teamtriaged-text-inputTriaged by Text Input team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions