Repository navigation
UndoHistoryController does not function properly in languages like Japanese where characters are confirmed when typed. #134398
Copy link
Copy link
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: internationalizationSupporting other languages or locales. (aka i18n)Supporting other languages or locales. (aka i18n)a: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsfound in release: 3.13Found to occur in 3.13Found to occur in 3.13found in release: 3.14Found to occur in 3.14Found to occur in 3.14has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesteam-text-inputOwned by Text Input teamOwned by Text Input teamtriaged-text-inputTriaged by Text Input teamTriaged by Text Input team
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Steps to reproduce
- Input "あ"
- Confirm text
- Input "い"
- Confirm text
- Press undo
- 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
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.Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: internationalizationSupporting other languages or locales. (aka i18n)Supporting other languages or locales. (aka i18n)a: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsfound in release: 3.13Found to occur in 3.13Found to occur in 3.13found in release: 3.14Found to occur in 3.14Found to occur in 3.14has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesteam-text-inputOwned by Text Input teamOwned by Text Input teamtriaged-text-inputTriaged by Text Input teamTriaged by Text Input team

Activity
dam-ease commentedon Sep 11, 2023
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?
hatano0x06 commentedon Sep 11, 2023
@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.
dam-ease commentedon Sep 12, 2023
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
english.webm
Simulator.Screen.Recording.-.iPhone.13.Pro.-.2023-09-11.at.21.12.43.mp4
With Chinese Keyboard
chinese.webm
Simulator.Screen.Recording.-.iPhone.13.Pro.-.2023-09-11.at.21.12.02.mp4
With Japanese Keyboard
japanese.webm
Simulator.Screen.Recording.-.iPhone.13.Pro.-.2023-09-11.at.21.10.52.mp4
stable, master flutter doctor -v
hatano0x06 commentedon Sep 12, 2023
Thank you.
I would love to include the redo feature so, I'm waiting for it to be improved.
2 remaining items
Renzo-Olivares commentedon Sep 28, 2023
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
undowhile 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
undois pressed the composition is still active as indicated by the solid underline which is whyundodoes nothing. Though thinking about this some more I think it is expected thatundoin this case would result in an empty field. What may be happening here is that the initial state of theTextFieldis 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 ablink. If weconfirmthe text in between edits then that will result in unexpected behaviors.The
blinkhappens because when the text is confirmed a new history entry is pushed to the stack that does not have an active composing region. When weundoand move the history back to the previous entry with the active composing region this causes a visualblink.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
UndoHistoryso I will keep this issue in mind.hatano0x06 commentedon Sep 29, 2023
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
Add `undoStackModifier` to `UndoHistory` (#138674)
Add `undoStackModifier` to `UndoHistory` (flutter#138674)
flutter-triage-bot commentedon Feb 8, 2024
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!
flutter-triage-bot commentedon May 10, 2024
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.
justinmc commentedon Sep 25, 2025
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.