Unverified Commit f1eeda74 authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Update TextSelectionOverlay (#142463)

Fixes a bug where changing parameters in EditableText that affect the selection overlay didn't update the overlay.
parent 102f6394
...@@ -23,8 +23,8 @@ const double _kSelectionHandleRadius = 6; ...@@ -23,8 +23,8 @@ const double _kSelectionHandleRadius = 6;
const double _kArrowScreenPadding = 26.0; const double _kArrowScreenPadding = 26.0;
/// Draws a single text selection handle with a bar and a ball. /// Draws a single text selection handle with a bar and a ball.
class _TextSelectionHandlePainter extends CustomPainter { class _CupertinoTextSelectionHandlePainter extends CustomPainter {
const _TextSelectionHandlePainter(this.color); const _CupertinoTextSelectionHandlePainter(this.color);
final Color color; final Color color;
...@@ -51,7 +51,7 @@ class _TextSelectionHandlePainter extends CustomPainter { ...@@ -51,7 +51,7 @@ class _TextSelectionHandlePainter extends CustomPainter {
} }
@override @override
bool shouldRepaint(_TextSelectionHandlePainter oldPainter) => color != oldPainter.color; bool shouldRepaint(_CupertinoTextSelectionHandlePainter oldPainter) => color != oldPainter.color;
} }
/// iOS Cupertino styled text selection handle controls. /// iOS Cupertino styled text selection handle controls.
...@@ -116,7 +116,7 @@ class CupertinoTextSelectionControls extends TextSelectionControls { ...@@ -116,7 +116,7 @@ class CupertinoTextSelectionControls extends TextSelectionControls {
final Widget handle; final Widget handle;
final Widget customPaint = CustomPaint( final Widget customPaint = CustomPaint(
painter: _TextSelectionHandlePainter(CupertinoTheme.of(context).primaryColor), painter: _CupertinoTextSelectionHandlePainter(CupertinoTheme.of(context).primaryColor),
); );
// [buildHandle]'s widget is positioned at the selection cursor's bottom // [buildHandle]'s widget is positioned at the selection cursor's bottom
......
...@@ -2928,7 +2928,28 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien ...@@ -2928,7 +2928,28 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
widget.controller.addListener(_didChangeTextEditingValue); widget.controller.addListener(_didChangeTextEditingValue);
_updateRemoteEditingValueIfNeeded(); _updateRemoteEditingValueIfNeeded();
} }
if (widget.controller.selection != oldWidget.controller.selection) {
if (_selectionOverlay != null
&& (widget.contextMenuBuilder != oldWidget.contextMenuBuilder ||
widget.selectionControls != oldWidget.selectionControls ||
widget.onSelectionHandleTapped != oldWidget.onSelectionHandleTapped ||
widget.dragStartBehavior != oldWidget.dragStartBehavior ||
widget.magnifierConfiguration != oldWidget.magnifierConfiguration)) {
final bool shouldShowToolbar = _selectionOverlay!.toolbarIsVisible;
final bool shouldShowHandles = _selectionOverlay!.handlesVisible;
_selectionOverlay!.dispose();
_selectionOverlay = _createSelectionOverlay();
if (shouldShowToolbar || shouldShowHandles) {
SchedulerBinding.instance.addPostFrameCallback((Duration _) {
if (shouldShowToolbar) {
_selectionOverlay!.showToolbar();
}
if (shouldShowHandles) {
_selectionOverlay!.showHandles();
}
});
}
} else if (widget.controller.selection != oldWidget.controller.selection) {
_selectionOverlay?.update(_value); _selectionOverlay?.update(_value);
} }
_selectionOverlay?.handlesVisible = widget.showSelectionHandles; _selectionOverlay?.handlesVisible = widget.showSelectionHandles;
...@@ -4266,7 +4287,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien ...@@ -4266,7 +4287,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
if (!widget.focusNode.hasFocus) { if (!widget.focusNode.hasFocus) {
_flagInternalFocus(); _flagInternalFocus();
widget.focusNode.requestFocus(); widget.focusNode.requestFocus();
_selectionOverlay = _createSelectionOverlay(); _selectionOverlay ??= _createSelectionOverlay();
} }
return; return;
} }
......
...@@ -1509,13 +1509,7 @@ class SelectionOverlay { ...@@ -1509,13 +1509,7 @@ class SelectionOverlay {
/// {@endtemplate} /// {@endtemplate}
void hide() { void hide() {
_magnifierController.hide(); _magnifierController.hide();
if (_handles != null) { hideHandles();
_handles!.start.remove();
_handles!.start.dispose();
_handles!.end.remove();
_handles!.end.dispose();
_handles = null;
}
if (_toolbar != null || _contextMenuController.isShown || _spellCheckToolbarController.isShown) { if (_toolbar != null || _contextMenuController.isShown || _spellCheckToolbarController.isShown) {
hideToolbar(); hideToolbar();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment