Skip to content

Conversation

@LongCatIsLooong
Copy link
Contributor

  • 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.
  • Fix EditableTextState animation controller never disposed #83885. Dispose animation controllers

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

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Aug 10, 2021
@google-cla google-cla bot added the cla: yes label Aug 10, 2021
@LongCatIsLooong LongCatIsLooong force-pushed the editable-text-minor-fixes branch from e2d30bc to edcf3a8 Compare August 10, 2021 01:47
- 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
@LongCatIsLooong LongCatIsLooong force-pushed the editable-text-minor-fixes branch from edcf3a8 to 4696d1e Compare August 10, 2021 01:48
return other.baseOffset == baseOffset
&& other.extentOffset == extentOffset
&& other.affinity == affinity
&& (!isCollapsed || other.affinity == affinity)
Copy link
Contributor Author

@LongCatIsLooong LongCatIsLooong Aug 10, 2021

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@justinmc justinmc left a 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)
Copy link
Contributor

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)
Copy link
Contributor

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)';
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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(
Copy link
Contributor

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?

Copy link
Contributor Author

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(
Copy link
Contributor

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?

Copy link
Contributor Author

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

@LongCatIsLooong LongCatIsLooong force-pushed the editable-text-minor-fixes branch from adb5189 to 7fb1b6b Compare August 16, 2021 16:41
@fluttergithubbot fluttergithubbot merged commit c49eba6 into flutter:master Aug 16, 2021
@LongCatIsLooong LongCatIsLooong deleted the editable-text-minor-fixes branch August 16, 2021 19:12
blasten pushed a commit to blasten/flutter that referenced this pull request Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EditableTextState animation controller never disposed

3 participants