-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Refactor TextSelectionOverlay #98153
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
Conversation
chunhtai
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.
Tests will be added soon
| /// | ||
| /// The [context] must not be null and must have an [Overlay] as an ancestor. | ||
| TextSelectionOverlay({ | ||
| required TextEditingValue 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.
The changes remove the getter for these parameter because it now directly pass it in SelectionOverlay, not sure whether any customer depends on it
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.
It's worth it to make this change even if so. The migration shouldn't be too bad.
| _effectiveEndHandleVisibility.dispose(); | ||
| } | ||
|
|
||
| double _getStartGlyphHeight() { |
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.
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({ |
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.
Ideally selectionEndPoints and toolbarLocation should be removed once @justinmc refactor the TextSelectionControls.buildToolbar to not depends one these metrics
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.
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; |
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.
Should _selectionOverlay._handles and _selectionOverlay._toolbar have public getters? I thought a leading underscore signified private.
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.
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'), | ||
| ), | ||
| ], | ||
| ) |
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.
Nit: trailing commas
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.
_ ___ _____ __ __
| | / __|_ _| \/ |
| |_| (_ | | | | |\/| |
|____\___| |_| |_| |_|
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 👍
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( |
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.
Nit: Just out of curiosity, could this be done in an initializer?
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, the _handleSelectionStartHandleDragStart and other methods need to be static methods in order to be used in initializer, but they can't be static.
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.
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({ |
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.
That sounds good based on my work so far 👍 . Still trying to get you a WIP PR for that...
| } | ||
| } | ||
|
|
||
|
|
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.
Nit: Unnecessary newline here.
| /// | ||
| /// The [context] must not be null and must have an [Overlay] as an ancestor. | ||
| TextSelectionOverlay({ | ||
| required TextEditingValue 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.
It's worth it to make this change even if so. The migration shouldn't be too bad.
|
This pull request is not suitable for automatic merging in its current state.
|
* Refactor TextSelectionOverlay * fix test * remove print * fix more tests * update * added tests * fix comments * fmt * fix test * addressing comment * remove dispose * remove new line
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
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.