✏️ Editar/reenviar mensagens do usuário
This commit is contained in:
+52
-1
@@ -520,7 +520,16 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
<span>Regenerar</span>
|
||||
</button>
|
||||
</div>
|
||||
` : '';
|
||||
` : `
|
||||
<div class="message-actions">
|
||||
<button class="msg-action-btn btn-edit" title="Editar e reenviar" data-content="${escapeHtml(content).replace(/"/g, '"')}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10" />
|
||||
</svg>
|
||||
<span>Editar</span>
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
row.innerHTML = `
|
||||
<div class="message-icon">${avatarHtml}</div>
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user