fix: capture this ref in user copy icon onclick

This commit is contained in:
gramps
2026-07-13 16:10:30 -07:00
parent f07025a4e8
commit 92e8608ac7
+1 -1
View File
@@ -1447,7 +1447,7 @@ function appendMessage(role, content, animate, isSearch = false, afterEl = null)
const ms = now.getMilliseconds(); const ms = now.getMilliseconds();
const timeStr = months[now.getMonth()] + ' ' + String(now.getDate()).padStart(2,'0') + ', ' + now.getFullYear() + ' ' + String(now.getHours()).padStart(2,'0') + ':' + String(now.getMinutes()).padStart(2,'0') + ':' + String(now.getSeconds()).padStart(2,'0') + '.' + String(Math.floor(ms / 10)).padStart(2,'0'); const timeStr = months[now.getMonth()] + ' ' + String(now.getDate()).padStart(2,'0') + ', ' + now.getFullYear() + ' ' + String(now.getHours()).padStart(2,'0') + ':' + String(now.getMinutes()).padStart(2,'0') + ':' + String(now.getSeconds()).padStart(2,'0') + '.' + String(Math.floor(ms / 10)).padStart(2,'0');
const textHtml = content ? renderMarkdown(content) : ''; const textHtml = content ? renderMarkdown(content) : '';
const copyIcon = role === 'user' && content ? `<span class="user-copy-btn" onclick="event.stopPropagation();navigator.clipboard.writeText(${JSON.stringify(content)}).then(()=>{this.textContent='✓';showToast('Copied');setTimeout(()=>this.innerHTML='📋',1500)})">📋</span>` : ''; const copyIcon = role === 'user' && content ? `<span class="user-copy-btn" onclick="var el=this;event.stopPropagation();navigator.clipboard.writeText(${JSON.stringify(content)}).then(()=>{el.textContent='✓';showToast('Copied');setTimeout(()=>el.innerHTML='📋',1500)})">📋</span>` : '';
div.innerHTML = `<div class="avatar">${role === 'user' ? 'YOU' : 'AI'}</div><div class="content"><div class="role-label">${role}${role === 'user' ? ' <span class="msg-time">' + timeStr + '</span>' : ''}</div><div class="text">${textHtml}${copyIcon}</div>${role === 'assistant' ? '<div class="msg-toolbar"></div>' : ''}</div>`; div.innerHTML = `<div class="avatar">${role === 'user' ? 'YOU' : 'AI'}</div><div class="content"><div class="role-label">${role}${role === 'user' ? ' <span class="msg-time">' + timeStr + '</span>' : ''}</div><div class="text">${textHtml}${copyIcon}</div>${role === 'assistant' ? '<div class="msg-toolbar"></div>' : ''}</div>`;
if (role === 'user') { if (role === 'user') {
const pair = document.createElement('div'); const pair = document.createElement('div');