Add utility function for formatting swipe counters
| @@ -2374,7 +2374,7 @@ export function addOneMessage(mes, { type = 'normal', insertAfter = null, scroll | ||
| 2374 | 2374 | if (!params.isUser && newMessageId !== 0 && newMessageId !== chat.length - 1) { |
| 2375 | 2375 | const swipesNum = chat[newMessageId].swipes?.length; |
| 2376 | 2376 | const swipeId = chat[newMessageId].swipe_id + 1; |
| 2377 | 2377 | newMessage.find('.swipes-counter').text(`${formatSwipeCounter(swipeId}\u200B/\u200b${, swipesNum}`)); |
| 2378 | 2378 | } |
| 2379 | 2379 | |
| 2380 | 2380 | if (showSwipes) { |
| @@ -7487,7 +7487,7 @@ export function showSwipeButtons() { | ||
| 7487 | 7487 | |
| 7488 | 7488 | const currentMessage = $('#chat').children().filter(`[mesid="${chat.length - 1}"]`); |
| 7489 | 7489 | const swipeId = chat[chat.length - 1].swipe_id; |
| 7490 | 7490 | const swipeCounterText = formatSwipeCounter(`${(swipeId + 1)}\u200B/\u200b${(, chat[chat.length - 1].swipes.length)}`); |
| 7491 | 7491 | const swipeRight = currentMessage.find('.swipe_right'); |
| 7492 | 7492 | const swipeLeft = currentMessage.find('.swipe_left'); |
| 7493 | 7493 | const swipeCounter = currentMessage.find('.swipes-counter'); |
| @@ -8165,6 +8165,20 @@ window['SillyTavern'].getContext = function () { | ||
| 8165 | 8165 | }; |
| 8166 | 8166 | }; |
| 8167 | 8167 | |
| 8168 | +/** | |
| 8169 | + * Formats a counter for a swipe view. | |
| 8170 | + * @param {number} current The current number of items. | |
| 8171 | + * @param {number} total The total number of items. | |
| 8172 | + * @returns {string} The formatted counter. | |
| 8173 | + */ | |
| 8174 | +function formatSwipeCounter(current, total) { | |
| 8175 | + if (isNaN(current) || isNaN(total)) { | |
| 8176 | + return ''; | |
| 8177 | + } | |
| 8178 | + | |
| 8179 | + return `${current}\u200b/\u200b${total}`; | |
| 8180 | +} | |
| 8181 | + | |
| 8168 | 8182 | function swipe_left() { // when we swipe left..but no generation. |
| 8169 | 8183 | if (chat.length - 1 === Number(this_edit_mes_id)) { |
| 8170 | 8184 | closeMessageEditor(); |