-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SuperTextField] Fix horizontal aligment (Resolves #668) #716
[SuperTextField] Fix horizontal aligment (Resolves #668) #716
Conversation
@angelosilvestre I didn't quite follow the explanation in the PR. Specifically, I'm wondering why alignment used to work, but it doesn't any more. My guess is that the |
@matthew-carroll The main problem is that, to be able to respect the text alignment, Because of this, the text is aligned only within The alignment stopped working in b2e0dc7, although The text was being displayed inside a In b2e0dc7, the text was wrapped with a I can try to avoid using the |
Let's bring back |
@matthew-carroll I implemented I checked it again, and the text alignment was working with I think we still need to use We also can't position the text inside the scrollview. |
super_editor/lib/src/infrastructure/super_textfield/android/android_textfield.dart
Outdated
Show resolved
Hide resolved
super_editor/lib/src/infrastructure/super_textfield/desktop/desktop_textfield.dart
Outdated
Show resolved
Hide resolved
super_editor/lib/src/infrastructure/super_textfield/desktop/desktop_textfield.dart
Outdated
Show resolved
Hide resolved
@angelosilvestre it looks like this PR has conflicts |
df061f1
to
2ee53e8
Compare
@matthew-carroll I resolved the conflits. |
markNeedsLayout(); | ||
} | ||
|
||
double? _viewportWidth = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason that this property is given an initial value of 0
? It looks like the constructor always assigns an initial value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This initialization isn't needed. I removed it.
double? viewportWidth, | ||
}) : _viewportWidth = viewportWidth; | ||
|
||
set viewportWidth(double? value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a dart doc that explains what viewport this is, and why we care.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also changed the property name to make it more clear.
maxWidth: constraints.maxWidth, | ||
maxHeight: constraints.maxHeight, | ||
); | ||
} else if (_viewportWidth != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we care whether the viewport scrolls vertically vs horizontally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only care about horizontal scrollables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
[SuperTextField] Fix horizontal aligment. Resolves #668
Horizontal alignment was not working, as shown in #509
There are two different situations:
Multiline text fields: The
RenderParagraph
has amaxWidth
constraint. In FlutterTextPainter
, whenmaxWidth
differs fromminWidth
, it layouts the paragraph again usingmaxIntrinsicWidth
asmaxWidth
, so theRenderParagraph
doesn't use all the available width and the alignment doesn't work as expected. As a result, the scrollbar is displayed next to the text instead of being displayed at the right edge of the text field.The relevant lines are here:
https://github.com/flutter/flutter/blob/ca6cecf034d9c18fcb6ea70309cc855e353aa0f8/packages/flutter/lib/src/painting/text_painter.dart#L630-L652
I wrapped
SuperText
with aSizedBox
with infinitymaxWidth
, so it forces theRenderParagraph
to use all available width.Singleline text fields: The text field has a horizontal scrollview, which gives an infinity
maxWidth
toRenderParagraph
. In this case, wrapping with theSizedBox
won't help.I wrapped the
SingleChildScrollView
with anAlign
widget, with an alignment based on the text alignment.