diff --git a/public/app.js b/public/app.js index 4384f97..5f0783a 100644 --- a/public/app.js +++ b/public/app.js @@ -520,7 +520,16 @@ document.addEventListener('DOMContentLoaded', () => { Regenerar - ` : ''; + ` : ` +
+ +
+ `; row.innerHTML = `
${avatarHtml}
@@ -551,6 +560,48 @@ document.addEventListener('DOMContentLoaded', () => { }); } + // Event listener para editar/reenviar mensagem + const editBtn = row.querySelector('.btn-edit'); + if (editBtn) { + editBtn.addEventListener('click', () => { + const text = editBtn.dataset.content; + const chat = chats.find(c => c.id === currentChatId); + if (!chat) return; + + // Encontrar índice desta mensagem no chat + const rows = conversationList.querySelectorAll('.message-row.user'); + let msgRow = null; + for (const r of rows) { + const btn = r.querySelector('.btn-edit'); + if (btn && btn.dataset.content === text) { + msgRow = r; + break; + } + } + + // Remover esta mensagem e todas as subsequentes (do user e do bot) + if (msgRow) { + const allRows = Array.from(conversationList.querySelectorAll('.message-row')); + const idx = allRows.indexOf(msgRow); + for (let i = allRows.length - 1; i >= idx; i--) { + allRows[i].remove(); + } + // Remover do estado também + const msgIndex = chat.messages.findIndex(m => m.role === 'user' && m.content === text); + if (msgIndex >= 0) { + chat.messages = chat.messages.slice(0, msgIndex); + } + saveChats(); + } + + // Colocar texto no input e focar + userInput.value = text; + userInput.focus(); + userInput.dispatchEvent(new Event('input')); + btnSend.disabled = false; + }); + } + // Event listener para regenerar resposta const regenBtn = row.querySelector('.btn-regenerate'); if (regenBtn) { diff --git a/public/style.css b/public/style.css index cc21c46..f1909db 100644 --- a/public/style.css +++ b/public/style.css @@ -1242,6 +1242,19 @@ code { transition: transform 0.3s ease; } +/* Botão editar */ +.msg-action-btn.btn-edit:hover { + color: #8b5cf6 !important; +} + +.msg-action-btn.btn-edit:hover svg { + transform: scale(1.1); +} + +.msg-action-btn.btn-edit svg { + transition: transform 0.2s ease; +} + .disclaimer { font-size: 11px; color: var(--text-muted);