@@ -131,11 +131,27 @@ class RawEditorState extends EditorState
131
131
bool _didAutoFocus = false ;
132
132
bool _keyboardVisible = false ;
133
133
DefaultStyles _styles;
134
- final ClipboardStatusNotifier _clipboardStatus = ClipboardStatusNotifier ();
134
+ final ClipboardStatusNotifier _clipboardStatus =
135
+ kIsWeb ? null : ClipboardStatusNotifier ();
135
136
final LayerLink _toolbarLayerLink = LayerLink ();
136
137
final LayerLink _startHandleLayerLink = LayerLink ();
137
138
final LayerLink _endHandleLayerLink = LayerLink ();
138
139
140
+ /// Whether to create an input connection with the platform for text editing
141
+ /// or not.
142
+ ///
143
+ /// Read-only input fields do not need a connection with the platform since
144
+ /// there's no need for text editing capabilities (e.g. virtual keyboard).
145
+ ///
146
+ /// On the web, we always need a connection because we want some browser
147
+ /// functionalities to continue to work on read-only input fields like:
148
+ ///
149
+ /// - Relevant context menu.
150
+ /// - cmd/ctrl+c shortcut to copy.
151
+ /// - cmd/ctrl+a to select all.
152
+ /// - Changing the selection using a physical keyboard.
153
+ bool get shouldCreateInputConnection => kIsWeb || ! widget.readOnly;
154
+
139
155
bool get _hasFocus => widget.focusNode.hasFocus;
140
156
141
157
TextDirection get _textDirection {
@@ -371,7 +387,7 @@ class RawEditorState extends EditorState
371
387
_textInputConnection != null && _textInputConnection.attached;
372
388
373
389
openConnectionIfNeeded () {
374
- if (widget.readOnly ) {
390
+ if (! shouldCreateInputConnection ) {
375
391
return ;
376
392
}
377
393
@@ -437,7 +453,7 @@ class RawEditorState extends EditorState
437
453
438
454
@override
439
455
void updateEditingValue (TextEditingValue value) {
440
- if (widget.readOnly ) {
456
+ if (! shouldCreateInputConnection ) {
441
457
return ;
442
458
}
443
459
@@ -773,7 +789,7 @@ class RawEditorState extends EditorState
773
789
}
774
790
775
791
_selectionOverlay? .handlesVisible = _shouldShowSelectionHandles ();
776
- if (widget.readOnly ) {
792
+ if (! shouldCreateInputConnection ) {
777
793
closeConnectionIfNeeded ();
778
794
} else {
779
795
if (oldWidget.readOnly && _hasFocus) {
@@ -1101,6 +1117,14 @@ class RawEditorState extends EditorState
1101
1117
1102
1118
@override
1103
1119
bool showToolbar () {
1120
+ // Web is using native dom elements to enable clipboard functionality of the
1121
+ // toolbar: copy, paste, select, cut. It might also provide additional
1122
+ // functionality depending on the browser (such as translate). Due to this
1123
+ // we should not show a Flutter toolbar for the editable text elements.
1124
+ if (kIsWeb) {
1125
+ return false ;
1126
+ }
1127
+
1104
1128
if (_selectionOverlay == null || _selectionOverlay.toolbar != null ) {
1105
1129
return false ;
1106
1130
}
0 commit comments