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