fix: кнопка Копировать видна при стриминге (не затирается textContent)

Проблема: aiDiv.textContent = aiText перезаписывал весь контент включая
кнопку. Теперь обновляется только текстовая нода (firstChild).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
anor
2026-03-24 21:44:31 +10:00
co-authored by Claude Opus 4.6
parent 30f2869fb3
commit 398218b8dd
+7 -3
View File
@@ -160,7 +160,8 @@ function addMsg(type, text) {
btn.className = 'copy-btn';
btn.textContent = 'Копировать';
btn.onclick = () => {
navigator.clipboard.writeText(div.textContent.replace('Копировать', '').trim());
const text = div.firstChild ? div.firstChild.textContent.trim() : div.textContent.replace('Копировать', '').trim();
navigator.clipboard.writeText(text);
btn.textContent = 'Скопировано';
btn.classList.add('copied');
setTimeout(() => { btn.textContent = 'Копировать'; btn.classList.remove('copied'); }, 1500);
@@ -299,9 +300,12 @@ async function sendMessage() {
} else if (line.startsWith('data: ')) {
const data = JSON.parse(line.slice(6));
if (eventType === 'text') {
if (!aiDiv) aiDiv = addMsg('ai', '');
if (!aiDiv) {
aiDiv = addMsg('ai', '');
aiDiv._textNode = aiDiv.firstChild; // text node before copy button
}
aiText += data.text;
aiDiv.textContent = aiText;
if (aiDiv._textNode) aiDiv._textNode.textContent = aiText;
msgs.scrollTop = msgs.scrollHeight;
} else if (eventType === 'tool') {
// Show minimal status, not raw code