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.className = 'copy-btn';
|
||||||
btn.textContent = 'Копировать';
|
btn.textContent = 'Копировать';
|
||||||
btn.onclick = () => {
|
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.textContent = 'Скопировано';
|
||||||
btn.classList.add('copied');
|
btn.classList.add('copied');
|
||||||
setTimeout(() => { btn.textContent = 'Копировать'; btn.classList.remove('copied'); }, 1500);
|
setTimeout(() => { btn.textContent = 'Копировать'; btn.classList.remove('copied'); }, 1500);
|
||||||
@@ -299,9 +300,12 @@ async function sendMessage() {
|
|||||||
} else if (line.startsWith('data: ')) {
|
} else if (line.startsWith('data: ')) {
|
||||||
const data = JSON.parse(line.slice(6));
|
const data = JSON.parse(line.slice(6));
|
||||||
if (eventType === 'text') {
|
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;
|
aiText += data.text;
|
||||||
aiDiv.textContent = aiText;
|
if (aiDiv._textNode) aiDiv._textNode.textContent = aiText;
|
||||||
msgs.scrollTop = msgs.scrollHeight;
|
msgs.scrollTop = msgs.scrollHeight;
|
||||||
} else if (eventType === 'tool') {
|
} else if (eventType === 'tool') {
|
||||||
// Show minimal status, not raw code
|
// Show minimal status, not raw code
|
||||||
|
|||||||
Reference in New Issue
Block a user