-
Notifications
You must be signed in to change notification settings - Fork 29.7k
[TextInput] minor fixes #87973
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
[TextInput] minor fixes #87973
Conversation
e2d30bc to
edcf3a8
Compare
- Make the invalid `TextSelection` a singleton - Equality check does not account for text affinity unless it's collapsed and valid (which makes more sense according to its documentation). - Fix `EditableText.scrollController`'s lifecycle. - Dispose animation controllers
edcf3a8 to
4696d1e
Compare
| return other.baseOffset == baseOffset | ||
| && other.extentOffset == extentOffset | ||
| && other.affinity == affinity | ||
| && (!isCollapsed || other.affinity == affinity) |
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.
If the text range is collapsed and has more than one visual location (e.g., occurs at a line break), which of the two locations to use when painting the caret.
So it appears we don't have separate text affinities for each endpoint (I wonder why?) and the affinity is only meaningful when the selection is collapsed.
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 just noticed this same thing! I'm worried it may be an oversight. I'm pretty sure we have code that does check the affinity when it's not collapsed, too. I'm going to create an issue for this.
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.
78d4058 to
26baedc
Compare
justinmc
left a comment
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 👍
Lots of good improvements here, thanks for taking the time to do this! I think the only thing that needs to change is the Scorll typo.
| return other.baseOffset == baseOffset | ||
| && other.extentOffset == extentOffset | ||
| && other.affinity == affinity | ||
| && (!isCollapsed || other.affinity == affinity) |
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 just noticed this same thing! I'm worried it may be an oversight. I'm pretty sure we have code that does check the affinity when it's not collapsed, too. I'm going to create an issue for this.
| return other.baseOffset == baseOffset | ||
| && other.extentOffset == extentOffset | ||
| && other.affinity == affinity | ||
| && (!isCollapsed || other.affinity == affinity) |
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.
|
|
||
| @override | ||
| String toString() { | ||
| return '${objectRuntimeType(this, 'TextSelection')}(baseOffset: $baseOffset, extentOffset: $extentOffset, affinity: $affinity, isDirectional: $isDirectional)'; |
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.
👍 Yours is easier to read in my opinion.
| if (other is! TextSelection) | ||
| return false; | ||
| if (!isValid) { | ||
| return !other.isValid; |
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 like this, I think it helps alleviate the confusion of -1,-1 selection.
| TextInputConnection? _textInputConnection; | ||
| TextSelectionOverlay? _selectionOverlay; | ||
|
|
||
| ScrollController? _internalScorllController; |
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.
Typo: Scorll => Scroll
| static const Duration _floatingCursorResetTime = Duration(milliseconds: 125); | ||
|
|
||
| late AnimationController _floatingCursorResetController; | ||
| late final AnimationController _floatingCursorResetController = AnimationController( |
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 this late unnecessary now since it's immediately assigned?
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.
Yeah since the animation controller needs to reference this it has to be lazy.
| expect(scrollController2.attached, isFalse); | ||
|
|
||
| // Change scrollController to controller 2. | ||
| await tester.pumpWidget( |
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.
Making sure I understand what's happening in this test. By pumping a new app, the old EditableText has its dispose called and the new one gets instantiated. didUpdateWidget is not called. Is that right?
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.
No it's just replacing scrollController1 with scrollController2 so didUpdateWidget is called. Currently we're not properly removing/adding listeners when the scroll controller changes
adb5189 to
7fb1b6b
Compare
TextSelectiona singletoncollapsed and valid (which makes more sense according to its documentation).
EditableText.scrollController's lifecycle.Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.
List which issues are fixed by this PR. You must list at least one issue.
If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.