Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(conversation): use native context menu when selection is within current ChatItem (#11400)

Innei9778dcea8ebf
diff --git a/src/features/Conversation/hooks/useChatItemContextMenu.tsx b/src/features/Conversation/hooks/useChatItemContextMenu.tsx
index abd8c6760f0..5643feb64e1 100644
--- a/src/features/Conversation/hooks/useChatItemContextMenu.tsx
+++ b/src/features/Conversation/hooks/useChatItemContextMenu.tsx
@@ -348,13 +348,22 @@ export const useChatItemContextMenu = ({
return;
}
+ const selection = window.getSelection();
+ const selectedText = selection?.toString().trim() || '';
+ selectedTextRef.current = selectedText;
+
+ // If there's selected text outside of current ChatItem, use native context menu
+ if (selectedText && selection?.anchorNode) {
+ const isSelectionInCurrentItem = target.contains(selection.anchorNode);
+
+ if (isSelectionInCurrentItem) {
+ return;
+ }
+ }
+
event.preventDefault();
event.stopPropagation();
- const selection = window.getSelection();
- selectedTextRef.current = selection?.toString().trim() || '';
-
- console.log(contextMenuItems);
showContextMenu(contextMenuItems);
},
[contextMenuItems, contextMenuMode, editing],