deleteSwipe now emits the deleted message Id. (#4609) * deleteSwipe now emits the deleted message Id. * Fixed: this_edit_mes_id can be a string (don't ask). Either wrap it in parseInt or Number function https://github.com/SillyTavern/SillyTavern/pull/4609#discussion_r2405534766 I think it's better to use messageId in naming. Most of weirdly abbreviated params and variables come way back from TavernAI code. https://github.com/SillyTavern/SillyTavern/pull/4609#discussion_r2405537550 * Revert outside number conversions --------- Co-authored-by: user <user@exmaple.com> Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>

befb2ffb78612198ca1bf95b10f84e55ba027e15

DeclineThyself <FallenHaze@tutamail.com>

Signed
1 files changed, +15 -14Ignore whitespace
public/script.js+15 -14
@@ -7942,44 +7942,45 @@ export function hideSwipeButtons() {
79427942/**
79437943 * Deletes a swipe from the chat.
79447944 *
79457945 * @param {number?} [swipeId = null] - The ID of the swipe to delete. If not provided, the current swipe will be deleted.
7946+ * @param {number?} [messageId = chat.length - 1] - The ID of the message to delete from. If not provided, the last message will be targeted.
79467947 * @returns {Promise<number>|undefined} - The ID of the new swipe after deletion.
79477948 */
79487949export async function deleteSwipe(swipeId = null, messageId = chat.length - 1) {
79497950 if (swipeId && (isNaN(swipeId) || swipeId < 0)) {
79507951 toastr.warning(t`Invalid swipe ID: ${swipeId + 1}`);
79517952 return;
79527953 }
79537954
79547955 const lastMessagemessage = chat[chat.length - 1messageId];
79557956 if (!lastMessagemessage || !Array.isArray(lastMessagemessage.swipes) || !lastMessagemessage.swipes.length) {
79567957 toastr.warning(t`No messages to delete swipes from.`);
79577958 return;
79587959 }
79597960
79607961 if (lastMessagemessage.swipes.length <= 1) {
79617962 toastr.warning(t`Can't delete the last swipe.`);
79627963 return;
79637964 }
79647965
79657966 swipeId = swipeId ?? lastMessagemessage.swipe_id;
79667967
79677968 if (swipeId < 0 || swipeId >= lastMessagemessage.swipes.length) {
79687969 toastr.warning(t`Invalid swipe ID: ${swipeId + 1}`);
79697970 return;
79707971 }
79717972
79727973 lastMessagemessage.swipes.splice(swipeId, 1);
79737974
79747975 if (Array.isArray(lastMessagemessage.swipe_info) && lastMessagemessage.swipe_info.length) {
79757976 lastMessagemessage.swipe_info.splice(swipeId, 1);
79767977 }
79777978
79787979 // Select the next swipe, or the one before if it was the last one
79797980 const newSwipeId = Math.min(swipeId, lastMessagemessage.swipes.length - 1);
79807981 syncSwipeToMes(nullmessageId, newSwipeId);
79817982
79827983 await eventSource.emit(event_types.MESSAGE_SWIPE_DELETED, { messageId, swipeId, newSwipeId });
79837984
79847985 await saveChatConditional();
79857986 await reloadCurrentChat();
@@ -10486,7 +10487,7 @@ jQuery(async function () {
1048610487 if (deleteOnlySwipe) {
1048710488 const message = chat[this_edit_mes_id];
1048810489 const swipe_id = message.swipe_id;
1048910490 await deleteSwipe(swipe_id, Number(this_edit_mes_id));
1049010491 return;
1049110492 }
1049210493