Merge pull request #4077 from SillyTavern/fix-mes0-right-swipe

Allow swipe right to generate first message in non-pristine chats
This commit is contained in:
Cohee
2025-05-31 21:27:21 +03:00
committed by GitHub

View File

@@ -9377,13 +9377,13 @@ export function swipe_left(_event, { source, repeated } = {}) {
/**
* Handles the swipe to the right event.
* @param {JQuery.Event} _event Event.
* @param {JQuery.Event} [_event] Event.
* @param {object} params Additional parameters.
* @param {string} [params.source] The source of the swipe event.
* @param {boolean} [params.repeated] Is the swipe event repeated.
*/
//MARK: swipe_right
export function swipe_right(_event, { source, repeated } = {}) {
export function swipe_right(_event = null, { source, repeated } = {}) {
if (chat.length - 1 === Number(this_edit_mes_id)) {
closeMessageEditor();
}
@@ -9395,6 +9395,7 @@ export function swipe_right(_event, { source, repeated } = {}) {
// Make sure ad-hoc changes to extras are saved before swiping away
syncMesToSwipe();
const isPristine = !chat_metadata?.tainted;
const swipe_duration = 200;
const swipe_range = 700;
//console.log(swipe_range);
@@ -9413,14 +9414,16 @@ export function swipe_right(_event, { source, repeated } = {}) {
};
//assign swipe info array with last message from chat
}
if (chat.length === 1 && chat[0]['swipe_id'] !== undefined && chat[0]['swipe_id'] === chat[0]['swipes'].length - 1) { // if swipe_right is called on the last alternate greeting, loop back around
// if swipe_right is called on the last alternate greeting in pristine chats, loop back around
if (chat.length === 1 && chat[0]['swipe_id'] !== undefined && chat[0]['swipe_id'] === chat[0]['swipes'].length - 1 && isPristine) {
chat[0]['swipe_id'] = 0;
} else {
// If the user is holding down the key and we're at the last swipe, don't do anything
if (source === 'keyboard' && repeated && chat[chat.length - 1].swipe_id === chat[chat.length - 1].swipes.length - 1) {
return;
}
chat[chat.length - 1]['swipe_id']++; // make new slot in array
// make new slot in array
chat[chat.length - 1]['swipe_id']++;
}
if (chat[chat.length - 1].extra) {
// if message has memory attached - remove it to allow regen
@@ -9435,8 +9438,8 @@ export function swipe_right(_event, { source, repeated } = {}) {
if (!Array.isArray(chat[chat.length - 1]['swipe_info'])) {
chat[chat.length - 1]['swipe_info'] = [];
}
//console.log(chat[chat.length-1]['swipes']);
if (parseInt(chat[chat.length - 1]['swipe_id']) === chat[chat.length - 1]['swipes'].length && chat.length !== 1) { //if swipe id of last message is the same as the length of the 'swipes' array and not the greeting
//if swipe id of last message is the same as the length of the 'swipes' array and not the greeting
if (parseInt(chat[chat.length - 1]['swipe_id']) === chat[chat.length - 1]['swipes'].length && (chat.length !== 1 || !isPristine)) {
delete chat[chat.length - 1].gen_started;
delete chat[chat.length - 1].gen_finished;
run_generate = true;