From eb60e27f37f37fd0359f1422d4235ecf731d3797 Mon Sep 17 00:00:00 2001
From: n7484443 <n7484443@naver.com>
Date: Sat, 6 Jul 2024 02:44:11 +0900
Subject: [PATCH] Fix: make mouse right click to open context menu (#1976)

---
 lib/src/widgets/others/delegate.dart | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lib/src/widgets/others/delegate.dart b/lib/src/widgets/others/delegate.dart
index f22074ab..4b3441ba 100644
--- a/lib/src/widgets/others/delegate.dart
+++ b/lib/src/widgets/others/delegate.dart
@@ -85,6 +85,7 @@ class EditorTextSelectionGestureDetectorBuilder {
   /// will return true if current [onTapDown] event is triggered by a touch or
   /// a stylus.
   bool shouldShowSelectionToolbar = true;
+  bool requiresAdditionalActionForToolbar = false;
 
   bool detectWordBoundary = true;
 
@@ -122,6 +123,7 @@ class EditorTextSelectionGestureDetectorBuilder {
                 .mouse || // Enable word selection by mouse double tap
         kind == PointerDeviceKind.touch ||
         kind == PointerDeviceKind.stylus;
+    requiresAdditionalActionForToolbar = kind == PointerDeviceKind.mouse;
   }
 
   /// Handler for [EditorTextSelectionGestureDetector.onForcePressStart].
@@ -167,7 +169,7 @@ class EditorTextSelectionGestureDetectorBuilder {
       null,
       SelectionChangedCause.forcePress,
     );
-    if (shouldShowSelectionToolbar) {
+    if (shouldShowSelectionToolbar && !requiresAdditionalActionForToolbar) {
       editor!.showToolbar();
     }
   }
@@ -257,7 +259,7 @@ class EditorTextSelectionGestureDetectorBuilder {
   ///  which triggers this callback.
   @protected
   void onSingleLongTapEnd(LongPressEndDetails details) {
-    if (shouldShowSelectionToolbar) {
+    if (shouldShowSelectionToolbar && !requiresAdditionalActionForToolbar) {
       editor!.showToolbar();
     }
   }
@@ -282,7 +284,7 @@ class EditorTextSelectionGestureDetectorBuilder {
       // have focus, selection hasn't been set when the toolbars
       // get added
       SchedulerBinding.instance.addPostFrameCallback((_) {
-        if (shouldShowSelectionToolbar) {
+        if (shouldShowSelectionToolbar && !requiresAdditionalActionForToolbar) {
           editor!.showToolbar();
         }
       });
@@ -334,7 +336,8 @@ class EditorTextSelectionGestureDetectorBuilder {
     renderEditor!.handleDragEnd(details);
     if (isDesktop(supportWeb: true) &&
         delegate.selectionEnabled &&
-        shouldShowSelectionToolbar) {
+        shouldShowSelectionToolbar &&
+        !requiresAdditionalActionForToolbar) {
       // added to show selection copy/paste toolbar after drag to select
       editor!.showToolbar();
     }