fix: кнопка Копировать видна при стриминге (не затирается textContent)
Проблема: aiDiv.textContent = aiText перезаписывал весь контент включая кнопку. Теперь обновляется только текстовая нода (firstChild). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+7
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user