Fixing copy behavior

This commit is contained in:
jacob-buster 2025-09-22 17:07:48 -06:00
parent ddde4343d0
commit 3e3a30f510
1 changed files with 13 additions and 2 deletions

View File

@ -36,8 +36,19 @@ export const ChatUserMessage: React.FC<{
const handleCopy = useCallback( const handleCopy = useCallback(
(e?: React.ClipboardEvent) => { (e?: React.ClipboardEvent) => {
// Prevent default copy behavior // Check if user has selected text
//I do not know why this is needed, but it is... const selection = window.getSelection();
const hasSelection = selection && selection.toString().length > 0;
// If user has selected text, let browser handle it naturally
if (hasSelection && e?.clipboardData) {
// Don't prevent default - let browser copy the selected text
return;
}
// Only override copy behavior when no text is selected
// This handles the case where user presses Ctrl+C without selection
// or when the copy button is clicked
if (e?.clipboardData) { if (e?.clipboardData) {
e.preventDefault(); e.preventDefault();
e.clipboardData.setData('text/plain', request || ''); e.clipboardData.setData('text/plain', request || '');