@@ -85,7 +85,18 @@ class EditorTextSelectionGestureDetectorBuilder {
85
85
/// will return true if current [onTapDown] event is triggered by a touch or
86
86
/// a stylus.
87
87
bool shouldShowSelectionToolbar = true ;
88
- bool requiresAdditionalActionForToolbar = false ;
88
+ PointerDeviceKind ? kind;
89
+
90
+ /// Check if the selection toolbar should show.
91
+ ///
92
+ /// If mouse is used, the toolbar should only show when right click.
93
+ /// Else, it should show when the selection is enabled.
94
+ bool checkSelectionToolbarShouldShow ({required bool isAdditionalAction}) {
95
+ if (kind != PointerDeviceKind .mouse) {
96
+ return shouldShowSelectionToolbar;
97
+ }
98
+ return shouldShowSelectionToolbar && isAdditionalAction;
99
+ }
89
100
90
101
bool detectWordBoundary = true ;
91
102
@@ -116,14 +127,13 @@ class EditorTextSelectionGestureDetectorBuilder {
116
127
// through a touch screen (via either a finger or a stylus).
117
128
// A mouse shouldn't trigger the selection overlay.
118
129
// For backwards-compatibility, we treat a null kind the same as touch.
119
- final kind = details.kind;
130
+ kind = details.kind;
120
131
shouldShowSelectionToolbar = kind == null ||
121
132
kind ==
122
133
PointerDeviceKind
123
134
.mouse || // Enable word selection by mouse double tap
124
135
kind == PointerDeviceKind .touch ||
125
136
kind == PointerDeviceKind .stylus;
126
- requiresAdditionalActionForToolbar = kind == PointerDeviceKind .mouse;
127
137
}
128
138
129
139
/// Handler for [EditorTextSelectionGestureDetector.onForcePressStart] .
@@ -169,7 +179,7 @@ class EditorTextSelectionGestureDetectorBuilder {
169
179
null ,
170
180
SelectionChangedCause .forcePress,
171
181
);
172
- if (shouldShowSelectionToolbar && ! requiresAdditionalActionForToolbar ) {
182
+ if (checkSelectionToolbarShouldShow (isAdditionalAction : false ) ) {
173
183
editor! .showToolbar ();
174
184
}
175
185
}
@@ -193,7 +203,7 @@ class EditorTextSelectionGestureDetectorBuilder {
193
203
@protected
194
204
void onSecondarySingleTapUp (TapUpDetails details) {
195
205
// added to show toolbar by right click
196
- if (shouldShowSelectionToolbar ) {
206
+ if (checkSelectionToolbarShouldShow (isAdditionalAction : true ) ) {
197
207
editor! .showToolbar ();
198
208
}
199
209
}
@@ -259,7 +269,7 @@ class EditorTextSelectionGestureDetectorBuilder {
259
269
/// which triggers this callback.
260
270
@protected
261
271
void onSingleLongTapEnd (LongPressEndDetails details) {
262
- if (shouldShowSelectionToolbar && ! requiresAdditionalActionForToolbar ) {
272
+ if (checkSelectionToolbarShouldShow (isAdditionalAction : false ) ) {
263
273
editor! .showToolbar ();
264
274
}
265
275
}
@@ -284,7 +294,7 @@ class EditorTextSelectionGestureDetectorBuilder {
284
294
// have focus, selection hasn't been set when the toolbars
285
295
// get added
286
296
SchedulerBinding .instance.addPostFrameCallback ((_) {
287
- if (shouldShowSelectionToolbar && ! requiresAdditionalActionForToolbar ) {
297
+ if (checkSelectionToolbarShouldShow (isAdditionalAction : false ) ) {
288
298
editor! .showToolbar ();
289
299
}
290
300
});
@@ -336,8 +346,7 @@ class EditorTextSelectionGestureDetectorBuilder {
336
346
renderEditor! .handleDragEnd (details);
337
347
if (isDesktop (supportWeb: true ) &&
338
348
delegate.selectionEnabled &&
339
- shouldShowSelectionToolbar &&
340
- ! requiresAdditionalActionForToolbar) {
349
+ checkSelectionToolbarShouldShow (isAdditionalAction: false )) {
341
350
// added to show selection copy/paste toolbar after drag to select
342
351
editor! .showToolbar ();
343
352
}
0 commit comments