@@ -2441,6 +2441,23 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
24412441 _selectionOverlay? .updateForScroll ();
24422442 }
24432443
2444+ void _createSelectionOverlay () {
2445+ _selectionOverlay = TextSelectionOverlay (
2446+ clipboardStatus: _clipboardStatus,
2447+ context: context,
2448+ value: _value,
2449+ debugRequiredFor: widget,
2450+ toolbarLayerLink: _toolbarLayerLink,
2451+ startHandleLayerLink: _startHandleLayerLink,
2452+ endHandleLayerLink: _endHandleLayerLink,
2453+ renderObject: renderEditable,
2454+ selectionControls: widget.selectionControls,
2455+ selectionDelegate: this ,
2456+ dragStartBehavior: widget.dragStartBehavior,
2457+ onSelectionHandleTapped: widget.onSelectionHandleTapped,
2458+ );
2459+ }
2460+
24442461 @pragma ('vm:notify-debugger-on-exception' )
24452462 void _handleSelectionChanged (TextSelection selection, SelectionChangedCause ? cause) {
24462463 // We return early if the selection is not valid. This can happen when the
@@ -2478,20 +2495,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
24782495 _selectionOverlay = null ;
24792496 } else {
24802497 if (_selectionOverlay == null ) {
2481- _selectionOverlay = TextSelectionOverlay (
2482- clipboardStatus: _clipboardStatus,
2483- context: context,
2484- value: _value,
2485- debugRequiredFor: widget,
2486- toolbarLayerLink: _toolbarLayerLink,
2487- startHandleLayerLink: _startHandleLayerLink,
2488- endHandleLayerLink: _endHandleLayerLink,
2489- renderObject: renderEditable,
2490- selectionControls: widget.selectionControls,
2491- selectionDelegate: this ,
2492- dragStartBehavior: widget.dragStartBehavior,
2493- onSelectionHandleTapped: widget.onSelectionHandleTapped,
2494- );
2498+ _createSelectionOverlay ();
24952499 } else {
24962500 _selectionOverlay! .update (_value);
24972501 }
@@ -2943,6 +2947,18 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
29432947 if (shouldShowCaret) {
29442948 _scheduleShowCaretOnScreen (withAnimation: true );
29452949 }
2950+
2951+ // Even if the value doesn't change, it may be necessary to focus and build
2952+ // the selection overlay. For example, this happens when right clicking an
2953+ // unfocused field that previously had a selection in the same spot.
2954+ if (value == textEditingValue) {
2955+ if (! widget.focusNode.hasFocus) {
2956+ widget.focusNode.requestFocus ();
2957+ _createSelectionOverlay ();
2958+ }
2959+ return ;
2960+ }
2961+
29462962 _formatAndSetValue (value, cause, userInteraction: true );
29472963 }
29482964
0 commit comments