From c8411b6dfbba2e10aa954d79f6252a2e35594464 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Wed, 26 Jun 2024 03:36:06 +0200 Subject: [PATCH] Update delete message to new popup --- public/css/popup.css | 8 +++----- public/script.js | 34 ++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/public/css/popup.css b/public/css/popup.css index bdd530a66..045bfc2e5 100644 --- a/public/css/popup.css +++ b/public/css/popup.css @@ -115,12 +115,10 @@ dialog { background-color: var(--crimson-hover); } -.menu_button.popup-button-custom { - /* Custom buttons should not scale to smallest size, otherwise they will always break to multiline */ - width: unset; -} - .popup-controls .menu_button { + /* Popup buttons should not scale to smallest size, otherwise they will always break to multiline if multiple words */ + width: unset; + /* Fix weird animation issue with fonts on brightness filter */ backface-visibility: hidden; transform: translateZ(0); diff --git a/public/script.js b/public/script.js index 6fd8a8697..a596ebcee 100644 --- a/public/script.js +++ b/public/script.js @@ -228,7 +228,7 @@ import { appendFileContent, hasPendingFileAttachment, populateFileAttachment, de import { initPresetManager } from './scripts/preset-manager.js'; import { evaluateMacros } from './scripts/macros.js'; import { currentUser, setUserControls } from './scripts/user.js'; -import { POPUP_TYPE, Popup, callGenericPopup, fixToastrForDialogs } from './scripts/popup.js'; +import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup, fixToastrForDialogs } from './scripts/popup.js'; import { renderTemplate, renderTemplateAsync } from './scripts/templates.js'; import { ScraperManager } from './scripts/scrapers.js'; import { SlashCommandParser } from './scripts/slash-commands/SlashCommandParser.js'; @@ -10085,26 +10085,32 @@ jQuery(async function () { $(document).on('click', '.mes_edit_delete', async function (event, customData) { const fromSlashCommand = customData?.fromSlashCommand || false; - const swipeExists = (!Array.isArray(chat[this_edit_mes_id].swipes) || chat[this_edit_mes_id].swipes.length <= 1 || chat[this_edit_mes_id].is_user || parseInt(this_edit_mes_id) !== chat.length - 1); + const canDeleteSwipe = (Array.isArray(chat[this_edit_mes_id].swipes) && chat[this_edit_mes_id].swipes.length > 1 && !chat[this_edit_mes_id].is_user && parseInt(this_edit_mes_id) === chat.length - 1); + + let deleteOnlySwipe = false; if (power_user.confirm_message_delete && fromSlashCommand !== true) { - const confirmation = swipeExists ? await callPopup('Are you sure you want to delete this message?', 'confirm') - : await callPopup('

Delete this...

', 'confirm'); - if (!confirmation) { + const result = await callGenericPopup('Are you sure you want to delete this?', POPUP_TYPE.CONFIRM, null, { + okButton: canDeleteSwipe ? 'Delete Swipe' : 'Delete Message', + cancelButton: 'Cancel', + customButtons: canDeleteSwipe ? ['Delete Message'] : null, + }); + if (!result) { return; } + deleteOnlySwipe = canDeleteSwipe && result === 1; // Default button, not the custom one } - const mes = $(this).closest('.mes'); - - if (!mes) { + const messageElement = $(this).closest('.mes'); + if (!messageElement) { return; } - if ($('#del_type').val() === 'swipe') { - const swipe_id = chat[this_edit_mes_id]['swipe_id']; - chat[this_edit_mes_id]['swipes'].splice(swipe_id, 1); - if (Array.isArray(chat[this_edit_mes_id]['swipe_info']) && chat[this_edit_mes_id]['swipe_info'].length) { - chat[this_edit_mes_id].swipe_info.splice(swipe_id, 1); + if (deleteOnlySwipe) { + const message = chat[this_edit_mes_id]; + const swipe_id = message.swipe_id; + message.swipes.splice(swipe_id, 1); + if (Array.isArray(message.swipe_info) && message.swipe_info.length) { + message.swipe_info.splice(swipe_id, 1); } if (swipe_id > 0) { $('.swipe_left:last').click(); @@ -10113,7 +10119,7 @@ jQuery(async function () { } } else { chat.splice(this_edit_mes_id, 1); - mes.remove(); + messageElement.remove(); } let startFromZero = Number(this_edit_mes_id) === 0;