[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.
https://master-api.flutter.dev/flutter/services/TextSelection/affinity.html:
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.
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.
78d4058 to
26baedc
Compare
justinmc
left a comment
There was a problem hiding this comment.
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.
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) |
|
|
||
| @override | ||
| String toString() { | ||
| return '${objectRuntimeType(this, 'TextSelection')}(baseOffset: $baseOffset, extentOffset: $extentOffset, affinity: $affinity, isDirectional: $isDirectional)'; |
There was a problem hiding this comment.
👍 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.
I like this, I think it helps alleviate the confusion of -1,-1 selection.
| TextInputConnection? _textInputConnection; | ||
| TextSelectionOverlay? _selectionOverlay; | ||
|
|
||
| ScrollController? _internalScorllController; |
| static const Duration _floatingCursorResetTime = Duration(milliseconds: 125); | ||
|
|
||
| late AnimationController _floatingCursorResetController; | ||
| late final AnimationController _floatingCursorResetController = AnimationController( |
There was a problem hiding this comment.
Is this late unnecessary now since it's immediately assigned?
There was a problem hiding this comment.
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.
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.
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.