Skip to content

Conversation

@chunhtai
Copy link
Contributor

@chunhtai chunhtai commented Feb 9, 2022

Refactoring TextSelectionOverlay by pulling out dependencies on renderEditable.

This PR creates a base class SelectionOverlay that set up overlay without depending on renderEditable and makes the original TextSelectionOverlay to wrap around SelectionOverlay.

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 this 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 a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Feb 9, 2022
Copy link
Contributor Author

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

Tests will be added soon

///
/// The [context] must not be null and must have an [Overlay] as an ancestor.
TextSelectionOverlay({
required TextEditingValue value,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The changes remove the getter for these parameter because it now directly pass it in SelectionOverlay, not sure whether any customer depends on it

Copy link
Contributor

Choose a reason for hiding this comment

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

It's worth it to make this change even if so. The migration shouldn't be too bad.

_effectiveEndHandleVisibility.dispose();
}

double _getStartGlyphHeight() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these helper functions are directly copied from the old code

/// Creates an object that manages overlay entries for selection handles.
///
/// The [context] must not be null and must have an [Overlay] as an ancestor.
SelectionOverlay({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally selectionEndPoints and toolbarLocation should be removed once @justinmc refactor the TextSelectionControls.buildToolbar to not depends one these metrics

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds good based on my work so far 👍 . Still trying to get you a WIP PR for that...

void updateForScroll() => _updateSelectionOverlay();

/// Whether the handles are currently visible.
bool get handlesAreVisible => _selectionOverlay._handles != null && handlesVisible;
Copy link
Contributor

@Renzo-Olivares Renzo-Olivares Feb 10, 2022

Choose a reason for hiding this comment

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

Should _selectionOverlay._handles and _selectionOverlay._toolbar have public getters? I thought a leading underscore signified private.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

they could, but both handlesAreVisible and toolbarIsVisible feel unnecessary based on how they were currently used. I would probably remove it if we were to start over, so I decide to hide them in SelectionOverlay unless someone ask for it in the future.

child: const Text('toolbar'),
),
],
)
Copy link
Contributor

@Renzo-Olivares Renzo-Olivares Feb 11, 2022

Choose a reason for hiding this comment

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

Nit: trailing commas

Copy link
Contributor

@Renzo-Olivares Renzo-Olivares left a comment

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 👍

The TextSelectionOverlay / SelectionOverlay split makes sense, I think it's a good solution to this problem.

Looks like it shouldn't interfere much with my "context menu anywhere" work either.

renderObject.selectionStartInViewport.addListener(_updateHandleVisibilities);
renderObject.selectionEndInViewport.addListener(_updateHandleVisibilities);
_updateHandleVisibilities();
_selectionOverlay = SelectionOverlay(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Just out of curiosity, could this be done in an initializer?

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, the _handleSelectionStartHandleDragStart and other methods need to be static methods in order to be used in initializer, but they can't be static.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, I figured there was a reason 👍

/// Creates an object that manages overlay entries for selection handles.
///
/// The [context] must not be null and must have an [Overlay] as an ancestor.
SelectionOverlay({
Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds good based on my work so far 👍 . Still trying to get you a WIP PR for that...

}
}


Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Unnecessary newline here.

///
/// The [context] must not be null and must have an [Overlay] as an ancestor.
TextSelectionOverlay({
required TextEditingValue value,
Copy link
Contributor

Choose a reason for hiding this comment

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

It's worth it to make this change even if so. The migration shouldn't be too bad.

@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Mac framework_tests_libraries has failed. Please fix the issues identified (or deflake) before re-applying this label.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2022
clocksmith pushed a commit to clocksmith/flutter that referenced this pull request Mar 8, 2022
* Refactor TextSelectionOverlay

* fix test

* remove print

* fix more tests

* update

* added tests

* fix comments

* fmt

* fix test

* addressing comment

* remove dispose

* remove new line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants