From 5b6585f1b3a5f135ca7a279b99389434fbc56a7f Mon Sep 17 00:00:00 2001 From: admtracksteel Date: Mon, 25 May 2026 23:34:37 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Editar/reenviar=20mensagen?= =?UTF-8?q?s=20do=20usu=C3=A1rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/app.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++- public/style.css | 13 ++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) 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);