Refactor TextSelectionOverlay#98153
Conversation
chunhtai
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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.
Should _selectionOverlay._handles and _selectionOverlay._toolbar have public getters? I thought a leading underscore signified private.
There was a problem hiding this comment.
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.
Nit: trailing commas
justinmc
left a comment
There was a problem hiding this comment.
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.
Nit: Just out of curiosity, could this be done in an initializer?
There was a problem hiding this comment.
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.
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.
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.
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.
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.