Merge pull request #4077 from SillyTavern/fix-mes0-right-swipe Allow swipe right to generate first message in non-pristine chats

a17d0c2293f46a1690670a5d6f39f96a05b2ff5a

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
1 files changed, +9 -6Ignore whitespace
public/script.js+9 -6
@@ -9377,13 +9377,13 @@ export function swipe_left(_event, { source, repeated } = {}) {
93779377
93789378/**
93799379 * Handles the swipe to the right event.
93809380 * @param {JQuery.Event} [_event] Event.
93819381 * @param {object} params Additional parameters.
93829382 * @param {string} [params.source] The source of the swipe event.
93839383 * @param {boolean} [params.repeated] Is the swipe event repeated.
93849384 */
93859385//MARK: swipe_right
93869386export function swipe_right(_event = null, { source, repeated } = {}) {
93879387 if (chat.length - 1 === Number(this_edit_mes_id)) {
93889388 closeMessageEditor();
93899389 }
@@ -9395,6 +9395,7 @@ export function swipe_right(_event, { source, repeated } = {}) {
93959395 // Make sure ad-hoc changes to extras are saved before swiping away
93969396 syncMesToSwipe();
93979397
9398+ const isPristine = !chat_metadata?.tainted;
93989399 const swipe_duration = 200;
93999400 const swipe_range = 700;
94009401 //console.log(swipe_range);
@@ -9413,14 +9414,16 @@ export function swipe_right(_event, { source, repeated } = {}) {
94139414 };
94149415 //assign swipe info array with last message from chat
94159416 }
9416- 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
9417+ // if swipe_right is called on the last alternate greeting in pristine chats, loop back around
9418+ if (chat.length === 1 && chat[0]['swipe_id'] !== undefined && chat[0]['swipe_id'] === chat[0]['swipes'].length - 1 && isPristine) {
94179419 chat[0]['swipe_id'] = 0;
94189420 } else {
94199421 // If the user is holding down the key and we're at the last swipe, don't do anything
94209422 if (source === 'keyboard' && repeated && chat[chat.length - 1].swipe_id === chat[chat.length - 1].swipes.length - 1) {
94219423 return;
94229424 }
94239425 chat[chat.length - 1]['swipe_id']++; // make new slot in array
9426+ chat[chat.length - 1]['swipe_id']++;
94249427 }
94259428 if (chat[chat.length - 1].extra) {
94269429 // if message has memory attached - remove it to allow regen
@@ -9435,8 +9438,8 @@ export function swipe_right(_event, { source, repeated } = {}) {
94359438 if (!Array.isArray(chat[chat.length - 1]['swipe_info'])) {
94369439 chat[chat.length - 1]['swipe_info'] = [];
94379440 }
9438- //console.log(chat[chat.length-1]['swipes']);
9441+ //if swipe id of last message is the same as the length of the 'swipes' array and not the greeting
94399442 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!isPristine)) greeting{
94409443 delete chat[chat.length - 1].gen_started;
94419444 delete chat[chat.length - 1].gen_finished;
94429445 run_generate = true;