@@ -123,23 +123,29 @@ export const FullscreenMessageModal: React.FC = ({ }, 1500) } - // Обработка обычного копирования (Ctrl+C / Cmd+C) + // Обработка копирования Ctrl+C только когда модалка открыта и выделение внутри неё useEffect(() => { + if (!open) return + const handleCopy = (e: ClipboardEvent) => { const selection = window.getSelection() if (!selection || !selection.toString()) return - + + const node = selection.anchorNode + if (!node || !markdownRef.current || !markdownRef.current.contains(node)) return + const range = selection.getRangeAt(0) const tempDiv = document.createElement('div') tempDiv.appendChild(range.cloneContents()) - + + e.clipboardData?.setData('text/plain', selection.toString()) e.clipboardData?.setData('text/html', createFormattedHtml(tempDiv.innerHTML)) e.preventDefault() } - + document.addEventListener('copy', handleCopy) return () => document.removeEventListener('copy', handleCopy) - }, [createFormattedHtml]) + }, [open, createFormattedHtml]) // Обработка копирования по клику на иконку const handleCopy = async (e?: React.MouseEvent) => {