Repository navigation
Multiline TextField does't render trailing spaces on prev lines: Affinity bug. #40095
Copy link
Copy link
Closed
Closed
Copy link
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsa: typographyText rendering, possibly libtxtText rendering, possibly libtxtc: regressionIt was better in the past than it is nowIt was better in the past than it is nowframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packages
Description
Empty spaces are not showing when I attempt to add them to a previous line in a multi-line text field. If I enter 5 spaces, for example, nothing happens. But when I then enter a character, the cursor will jump the 5 spaces and then insert the character.
Here's a video showing what happens:
I can reproduce this with Material TextField and CupertinoTextField.
Possibly(?) related issues:
#26658
#39293
Flutter doctor logs
[✓] Flutter (Channel beta, v1.9.1+hotfix.2, on Mac OS X 10.14.6 18G87, locale en-CA)
• Flutter version 1.9.1+hotfix.2 at /Users/jeffreybunn/flutter
• Framework revision 2d2a1ffec9 (3 days ago), 2019-09-06 18:39:49 -0700
• Engine revision b863200c37
• Dart version 2.5.0
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/jeffreybunn/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = /Users/jeffreybunn/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.3, Build version 10G8
• CocoaPods version 1.7.5
[✓] Android Studio (version 3.4)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 35.2.1
• Dart plugin version 183.6270
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
[✓] VS Code (version 1.38.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.4.1
[!] Connected device
! No devices available
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: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsa: typographyText rendering, possibly libtxtText rendering, possibly libtxtc: regressionIt was better in the past than it is nowIt was better in the past than it is nowframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packages

Activity
Jethro87 commentedon Oct 7, 2019
@BondarenkoStas @HansMuller
I'd like to reiterate the severity of this issue for my application (and I assume many others). Text editing feels extremely janky when spaces don't appear until a character is typed, at which point all of the spaces appear (shown in the gif above).
In applications where users edit large text blocks, or where they need to type within a template of text, this is particularly bad.
Can you provide a timeline as to when this will be fixed? Or escalate it in some way?
Thanks very much.
HansMuller commentedon Oct 8, 2019
CC @justinmc @GaryQian - are we intentionally buffering trailing space (that would fit on the line without a line break) for insertions?
justinmc commentedon Oct 8, 2019
We intentionally buffer the spaces but only at the very end of the line on the far right edge, like native Android. I'm guessing that this is a bug related to when I implemented that in #30525. I'm taking a closer look now.
justinmc commentedon Oct 8, 2019
This isn't going to be as easy as I thought, since that linked PR is related but not the cause. It looks to me like
_paragraph.getBoxesForRangereturns the wrong value for the position between a space and a newline character.Considering the cursor represented by "|" in a TextField like this:
When
getBoxesForRangeis asked for the right edge of the space to the left of the cursor, it gives the correct position, but when asked for the left edge of the newline character, it incorrectly gives a position just after "c".Where the call happens in the framework: https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/painting/text_painter.dart#L679
Where the call is handled in the engine: https://github.com/flutter/engine/blob/master/third_party/txt/src/txt/paragraph_txt.cc#L1606
@GaryQian did anything change recently in
GetRectsForRangein libtxt off the top of your head that might cause this?Jethro87 commentedon Nov 6, 2019
@justinmc @GaryQian
Any updates on this? My application is heavy on text editing and this bug continues to make it feel extremely janky and almost unusable. If this could be prioritized in any way that would be greatly appreciated. Thanks.
GaryQian commentedon Nov 6, 2019
It could be that we are only tracking "ghost" runs consisting of only whitespace for final lines in a paragraph. Let me look at the source to verify and see if that is the case.
GaryQian commentedon Nov 6, 2019
Ok, so we are tracking the trailing whitespace, but it seems like there may be a bug where we are just not retrieving/indexing into the metrics properly when the trailing whitespace is not the final line.
GaryQian commentedon Nov 8, 2019
Update on this,
I have narrowed this down to text affinity (upstrea/downstream) problems when dealing with line breaks. This manifests itself differently in left vs center/right/justified alignments due to the existence of the ghost runs.
[-]When TextField is multiline spaces don't render on previous lines[/-][+]Multiline TextField does't render trailing spaces on prev lines: Affinity bug.[/+]GaryQian commentedon Nov 9, 2019
It seems that the TextEditState in the Android embedder does not actually support affinity yet. This is causing it to always default to the downstream affinity, which is invalid for end-of-line TextPositions.
(for my reference
shell/platform/android/io/flutter/embedding/systemchannels/TextInputChannel.java)GaryQian commentedon Nov 12, 2019
#44622 is a PR that should fix this.
15 remaining items
craigomac commentedon May 4, 2020
Is there any known workaround for this issue? For example, by creating my own variant of
TextFieldand modifying it?droidery commentedon May 5, 2020
@craigomac There is no known workaround for this issue, as there is a bug in the text painting.
darshankawar commentedon Jul 10, 2020
Hi @Jethro87,
I tested this issue on latest dev channel and couldn't replicate it. The spaces are rendered properly for previous lines, as expected.
I used Android 8.1 device and iOS simulator (13.5).
40095.mp4.zip
code sample
flutter doctor -v
Can you please confirm if you still experience this issue on latest Flutter version (eg: dev, master) ?
Jethro87 commentedon Jul 13, 2020
@darshankawar Thanks for looking at this issue!
I generally work in stable, and before upgrading to dev I double checked the issue. It's still occurring on my iPhone 7.
After upgrading to dev channel, however, the issue is gone 👍 Really happy about this. Thanks again for digging in.
For reference, here's my flutter doctor on stable, where the issue is still occurring:
darshankawar commentedon Jul 13, 2020
Hi @Jethro87, thanks for confirming that it's working for you.
I'd suggest to use beta or dev channel or wait until the fix reaches stable. If you can't use these channels, I would also suggest to find the PR that has fixed the issue and cherry-pick the commit into your local stable branch.
I am going ahead and closing this issue since it seems to be fixed, so there is no need to track the issue.
If you disagree, please write in the comment and I'll reopen.
Thanks.
mertcanbs commentedon Mar 6, 2021
@darshankawar I can reproduce this on 1.22.4 when textAlign is set to
TextAlign.rightgithub-actions commentedon Aug 4, 2021
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 -vand a minimal reproduction of the issue.