mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-27 13:29:15 +07:00
✨ feat(conversation): use native context menu when selection is within current ChatItem (#11400)
Show custom context menu only when there's no selection or selection is from outside the current ChatItem. This allows users to use native browser context menu for copy/search when selecting text within the current message.
This commit is contained in:
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user