Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@justinmc
Copy link
Contributor

Closes flutter/flutter#30173

Entering tab characters into a text field is causing some glitchiness. It may suddenly cause a single line input to wrap, or the text to flash, etc. at random moments. Here is a gif from the issue:

It seems like this happens because mTabWidth is unassigned and never set, so it contains random values from memory, sometimes zero and sometimes in the billions. It looks to me like the code that is supposed to set this variable is never called.

My proposed solution in this PR is to hardcode the tab width to 2 and delete the code that's never called. This fixes the problem for me and seems to give some reasonable behavior for tab characters. Does anyone else know what the intention of the original code was? Or any opinions on the width of tabs or what should happen when a tab is entered?

For the record, here is the original commit that added this code in 2015: 01f5266144

@justinmc justinmc added Work in progress (WIP) Not ready (yet) for review! and removed cla: yes labels Apr 16, 2019
@jason-simmons
Copy link
Member

This library was originally built to support Android text layout APIs. Android would call LineBreaker::setTabStops and pass a default or user-provided tab stop configuration:
https://android.googlesource.com/platform/frameworks/base/+/android-6.0.1_r25/core/jni/android_text_StaticLayout.cpp#62

I'd recommend having the Paragraph constructor call breaker_.setTabStops(nullptr, 0, defaultTabStop). Not sure what the default tab stop should be, but 2 seems fine.

@justinmc
Copy link
Contributor Author

Thanks for explaining that @jason-simmons! I've updated the PR to use your approach and it seems to work just as well. I'm seeing a tangentially related crash when putting the cursor between tabs that I'm going to investigate before I finalize this PR.

@justinmc justinmc self-assigned this Apr 16, 2019
@justinmc justinmc changed the title WIP Glitchiness with Tab Characters Glitchiness with Tab Characters Apr 16, 2019
@justinmc justinmc removed the Work in progress (WIP) Not ready (yet) for review! label Apr 16, 2019
@justinmc justinmc requested a review from jason-simmons April 16, 2019 21:29
@justinmc
Copy link
Contributor Author

Unfortunately I'm having trouble tracking down the tab crash. I created a separate issue for it because it existed before this PR and isn't strictly related: flutter/flutter#31154

I'm happy to take a deeper look at it though if someone points me in the right direction. I'm unfamiliar with what could be causing it and unable to get a full stack trace for now.

@jason-simmons
Copy link
Member

After taking a look at flutter/flutter#31158, I'm now thinking that it might be better to disable the tab handling logic in the Minikin LineBreaker:
https://github.com/flutter/engine/blob/master/third_party/txt/src/minikin/LineBreaker.cpp#L162

Flutter doesn't provide the Android StaticLayout tab stop behavior that Minikin's logic appears to be implementing. Removing the special handling of tabs in LineBreaker results in tabs acting like spaces for the purposes of line breaking and layout.

@justinmc
Copy link
Contributor Author

@jason-simmons Ready for re-review. I removed the tab code altogether and it does seem to work fine.

postSpaceCount = mSpaceCount;
afterWord = i + 1;
}
if (isWordSpace(c))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a "libtxt:" comment here saying that tab handling has been removed.

(This is intended to keep track of how our version of Minikin differs from the original)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks for the review.

jason-simmons added a commit to jason-simmons/flutter_engine that referenced this pull request Apr 17, 2019
currentLineWidth is the width passed into Paragraph layout, which comes
from the maxIntrinsicWidth returned by a previous call to Paragraph layout.
That width is calculated by Layout::measureText.

postBreak is calculated from the character widths in the LineBreaker.

A slight mismatch between these two widths may unnecessarily cause the
insertion of desperate breaks in addWordBreak.  Adding some slack to
currentLineWidth works around this.

Fixes flutter#8591
@justinmc justinmc merged commit 06fea14 into flutter:master Apr 18, 2019
@justinmc justinmc deleted the tab-line-glitch branch April 18, 2019 15:16
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 18, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Apr 18, 2019
flutter/engine@b678709...06fea14

git log b678709..06fea14 --no-merges --oneline
06fea14 Glitchiness with Tab Characters (flutter/engine#8591)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff (cbracken@google.com), and stop
the roller if necessary.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextFormField flashes when using tabs

3 participants