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:
Innei
2026-01-11 01:25:10 +08:00
committed by GitHub
parent b1b5d72a8b
commit 9778dcea8e

View File

@@ -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],