mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Prevent ephemeral message extra changes vanish upon swiping
This commit is contained in:
@ -6074,6 +6074,19 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes,
|
||||
return { type, getMessage };
|
||||
}
|
||||
|
||||
export function syncCurrentSwipeInfoExtras() {
|
||||
if (!chat.length) {
|
||||
return;
|
||||
}
|
||||
const currentMessage = chat[chat.length - 1];
|
||||
if (currentMessage && Array.isArray(currentMessage.swipe_info) && typeof currentMessage.swipe_id === 'number') {
|
||||
const swipeInfo = currentMessage.swipe_info[currentMessage.swipe_id];
|
||||
if (swipeInfo && typeof swipeInfo === 'object') {
|
||||
swipeInfo.extra = structuredClone(currentMessage.extra);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function saveImageToMessage(img, mes) {
|
||||
if (mes && img.image) {
|
||||
if (!mes.extra || typeof mes.extra !== 'object') {
|
||||
@ -8501,6 +8514,9 @@ function swipe_left() { // when we swipe left..but no generation.
|
||||
streamingProcessor.onStopStreaming();
|
||||
}
|
||||
|
||||
// Make sure ad-hoc changes to extras are saved before swiping away
|
||||
syncCurrentSwipeInfoExtras();
|
||||
|
||||
const swipe_duration = 120;
|
||||
const swipe_range = '700px';
|
||||
chat[chat.length - 1]['swipe_id']--;
|
||||
@ -8636,6 +8652,9 @@ const swipe_right = () => {
|
||||
return unblockGeneration();
|
||||
}
|
||||
|
||||
// Make sure ad-hoc changes to extras are saved before swiping away
|
||||
syncCurrentSwipeInfoExtras();
|
||||
|
||||
const swipe_duration = 200;
|
||||
const swipe_range = 700;
|
||||
//console.log(swipe_range);
|
||||
|
@ -42,6 +42,7 @@ import {
|
||||
showMoreMessages,
|
||||
stopGeneration,
|
||||
substituteParams,
|
||||
syncCurrentSwipeInfoExtras,
|
||||
system_avatar,
|
||||
system_message_types,
|
||||
this_chid,
|
||||
@ -2814,8 +2815,11 @@ async function addSwipeCallback(args, value) {
|
||||
const newSwipeId = lastMessage.swipes.length - 1;
|
||||
|
||||
if (isTrueBoolean(args.switch)) {
|
||||
// Make sure ad-hoc changes to extras are saved before swiping away
|
||||
syncCurrentSwipeInfoExtras();
|
||||
lastMessage.swipe_id = newSwipeId;
|
||||
lastMessage.mes = lastMessage.swipes[newSwipeId];
|
||||
lastMessage.extra = structuredClone(lastMessage.swipe_info?.[newSwipeId]?.extra ?? lastMessage.extra ?? {});
|
||||
}
|
||||
|
||||
await saveChatConditional();
|
||||
|
Reference in New Issue
Block a user