fix: /cut of the first displayed message
| @@ -1474,7 +1474,8 @@ export async function deleteLastMessage() { | ||
| 1474 | 1474 | * @param {boolean} [askConfirmation=false] Whether to ask for confirmation before deleting. |
| 1475 | 1475 | */ |
| 1476 | 1476 | export async function deleteMessage(id, swipeDeletionIndex = undefined, askConfirmation = false) { |
| 1477 | 1477 | ifconst (canDeleteSwipe = swipeDeletionIndex !== undefined) {&& swipeDeletionIndex !== null; |
| 1478 | + if (canDeleteSwipe) { | |
| 1478 | 1479 | if (swipeDeletionIndex < 0) { |
| 1479 | 1480 | throw new Error('Swipe index cannot be negative'); |
| 1480 | 1481 | } |
| @@ -1486,12 +1487,12 @@ export async function deleteMessage(id, swipeDeletionIndex = undefined, askConfi | ||
| 1486 | 1487 | } |
| 1487 | 1488 | } |
| 1488 | 1489 | |
| 1490 | + const minId = getFirstDisplayedMessageId(); | |
| 1489 | 1491 | const messageElement = chatElement.find(`.mes[mesid="${id}"]`); |
| 1490 | 1492 | if (messageElement.length === 0) { |
| 1491 | 1493 | return; |
| 1492 | 1494 | } |
| 1493 | 1495 | |
| 1494 | - const canDeleteSwipe = swipeDeletionIndex !== undefined; | |
| 1495 | 1496 | let deleteOnlySwipe = canDeleteSwipe; |
| 1496 | 1497 | if (askConfirmation) { |
| 1497 | 1498 | const result = await callGenericPopup(t`Are you sure you want to delete this message?`, POPUP_TYPE.CONFIRM, null, { |
| @@ -1515,8 +1516,8 @@ export async function deleteMessage(id, swipeDeletionIndex = undefined, askConfi | ||
| 1515 | 1516 | |
| 1516 | 1517 | chat_metadata['tainted'] = true; |
| 1517 | 1518 | |
| 1518 | - const startFromZero = id === 0; | |
| 1519 | + const startIndex = [0, minId].includes(id) ? id : null; | |
| 1519 | 1520 | updateViewMessageIds(startFromZerostartIndex); |
| 1520 | 1521 | await saveChatConditional(); |
| 1521 | 1522 | |
| 1522 | 1523 | if (this_edit_mes_id === id) { |
| @@ -8258,8 +8259,8 @@ async function importCharacterChat(formData, { refresh = true } = {}) { | ||
| 8258 | 8259 | return []; |
| 8259 | 8260 | } |
| 8260 | 8261 | |
| 8261 | 8262 | function updateViewMessageIds(startFromZerostartIndex = falsenull) { |
| 8262 | 8263 | const minId = startFromZerostartIndex ? 0 :? getFirstDisplayedMessageId(); |
| 8263 | 8264 | |
| 8264 | 8265 | chatElement.find('.mes').each(function (index, element) { |
| 8265 | 8266 | $(element).attr('mesid', minId + index); |
| @@ -29,6 +29,7 @@ import { | ||
| 29 | 29 | messageFormatting, |
| 30 | 30 | extension_prompt_types, |
| 31 | 31 | extension_prompt_roles, |
| 32 | + deleteMessage, | |
| 32 | 33 | } from '../script.js'; |
| 33 | 34 | import { isMobile, initMovingUI, favsToHotswap } from './RossAscends-mods.js'; |
| 34 | 35 | import { |
| @@ -2766,7 +2767,6 @@ async function doMesCut(_, text) { | ||
| 2766 | 2767 | |
| 2767 | 2768 | for (let i = 0; i < totalMesToCut; i++) { |
| 2768 | 2769 | cutText += (chat[mesIDToCut]?.mes || '') + '\n'; |
| 2769 | - let done = false; | |
| 2770 | 2770 | let mesToCut = $('#chat').find(`.mes[mesid=${mesIDToCut}]`); |
| 2771 | 2771 | |
| 2772 | 2772 | if (!mesToCut.length) { |
| @@ -2778,13 +2778,7 @@ async function doMesCut(_, text) { | ||
| 2778 | 2778 | } |
| 2779 | 2779 | |
| 2780 | 2780 | setEditedMessageId(mesIDToCut); |
| 2781 | - eventSource.once(event_types.MESSAGE_DELETED, () => { | |
| 2781 | + await deleteMessage(mesIDToCut, null, false); | |
| 2782 | - done = true; | |
| 2783 | - }); | |
| 2784 | - mesToCut.find('.mes_edit_delete').trigger('click', { fromSlashCommand: true }); | |
| 2785 | - while (!done) { | |
| 2786 | - await delay(1); | |
| 2787 | - } | |
| 2788 | 2782 | } |
| 2789 | 2783 | |
| 2790 | 2784 | return cutText; |