Fix copy button in iframe and reduce line-height spacing

- Always try clipboard API first, fall through to execCommand fallback
  on failure (fixes iframe/SharePoint where clipboard API throws)
- Reduce line-height from 1.6 to 1.3 in components.css to fix large
  gaps between lines in bot responses

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
SamoilenkoVadym 2026-02-11 12:52:31 +00:00
parent 02bbf6012f
commit 462f1dab4c
2 changed files with 18 additions and 14 deletions

View file

@ -38,22 +38,26 @@ const ChatInterface: React.FC = () => {
}
}, [messageText]);
const copyToClipboardFallback = (text: string) => {
const textArea = document.createElement('textarea');
textArea.value = text;
textArea.style.position = 'fixed';
textArea.style.left = '-9999px';
textArea.style.top = '-9999px';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
};
const handleCopyMessage = async (messageId: string, content: string) => {
try {
if (navigator.clipboard && window.isSecureContext) {
try {
await navigator.clipboard.writeText(content);
} else {
// Fallback for iframe/non-secure contexts (SharePoint)
const textArea = document.createElement('textarea');
textArea.value = content;
textArea.style.position = 'fixed';
textArea.style.left = '-9999px';
textArea.style.top = '-9999px';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
} catch {
// Clipboard API failed (iframe/permissions) — use fallback
copyToClipboardFallback(content);
}
setCopiedMessageId(messageId);
setTimeout(() => setCopiedMessageId(null), 2000);

View file

@ -156,7 +156,7 @@
border-radius: var(--radius-md);
box-shadow: var(--shadow-sm);
font-size: var(--font-size-base);
line-height: 1.6;
line-height: 1.3;
color: var(--text-primary);
}