From 6aaa533410f1f50e0483302fcb13aa82ecdb9882 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 9 Mar 2025 13:42:30 +0200 Subject: [PATCH 1/3] Prevent rollover on keyboard left swipe if repeating Closes #3636 --- public/script.js | 16 ++++++++++++++-- public/scripts/RossAscends-mods.js | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/public/script.js b/public/script.js index 3cd162c30..ee4d738b9 100644 --- a/public/script.js +++ b/public/script.js @@ -8746,11 +8746,18 @@ function formatSwipeCounter(current, total) { return `${current}\u200b/\u200b${total}`; } -function swipe_left() { // when we swipe left..but no generation. +/** + * Handles the swipe to the left 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. + * @returns + */ +function swipe_left(_event, { source, repeated } = {}) { // when we swipe left..but no generation. if (chat.length - 1 === Number(this_edit_mes_id)) { closeMessageEditor(); } - if (isStreamingEnabled() && streamingProcessor) { streamingProcessor.onStopStreaming(); } @@ -8758,6 +8765,11 @@ function swipe_left() { // when we swipe left..but no generation. // Make sure ad-hoc changes to extras are saved before swiping away syncMesToSwipe(); + if (source === 'keyboard' && repeated && chat[chat.length - 1].swipe_id === 0) { + // If the user is holding down the key and we're at the first swipe, don't do anything + return; + } + const swipe_duration = 120; const swipe_range = '700px'; chat[chat.length - 1]['swipe_id']--; diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index 0a2581e5f..374e5fdef 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -1143,7 +1143,7 @@ export function initRossMods() { $('#shadow_select_chat_popup').css('display') === 'none' && !isInputElementInFocus() ) { - $('.swipe_left:last').click(); + $('.swipe_left:last').trigger('click', { source: 'keyboard', repeated: event.repeat }); return; } } From 19b7deaed0e3ae1feb5dc4c5362fe0ffe5346300 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 9 Mar 2025 14:08:24 +0200 Subject: [PATCH 2/3] Ditto for right swipe --- public/script.js | 19 ++++++++++++++----- public/scripts/RossAscends-mods.js | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/public/script.js b/public/script.js index ee4d738b9..47b142071 100644 --- a/public/script.js +++ b/public/script.js @@ -8752,7 +8752,6 @@ function formatSwipeCounter(current, total) { * @param {object} params Additional parameters. * @param {string} [params.source] The source of the swipe event. * @param {boolean} [params.repeated] Is the swipe event repeated. - * @returns */ function swipe_left(_event, { source, repeated } = {}) { // when we swipe left..but no generation. if (chat.length - 1 === Number(this_edit_mes_id)) { @@ -8765,8 +8764,8 @@ function swipe_left(_event, { source, repeated } = {}) { // when we swipe l // Make sure ad-hoc changes to extras are saved before swiping away syncMesToSwipe(); + // If the user is holding down the key and we're at the first swipe, don't do anything if (source === 'keyboard' && repeated && chat[chat.length - 1].swipe_id === 0) { - // If the user is holding down the key and we're at the first swipe, don't do anything return; } @@ -8895,8 +8894,14 @@ function swipe_left(_event, { source, repeated } = {}) { // when we swipe l } } -// when we click swipe right button -const swipe_right = () => { +/** + * Handles the swipe to the right 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. + */ +function swipe_right(_event, { source, repeated } = {}) { if (chat.length - 1 === Number(this_edit_mes_id)) { closeMessageEditor(); } @@ -8929,6 +8934,10 @@ const swipe_right = () => { 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 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 } if (chat[chat.length - 1].extra) { @@ -9077,7 +9086,7 @@ const swipe_right = () => { }, }); } -}; +} export const CONNECT_API_MAP = { // Default APIs not contined inside text gen / chat gen diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index 374e5fdef..769d87d15 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -1156,7 +1156,7 @@ export function initRossMods() { $('#shadow_select_chat_popup').css('display') === 'none' && !isInputElementInFocus() ) { - $('.swipe_right:last').click(); + $('.swipe_right:last').trigger('click', { source: 'keyboard', repeated: event.repeat }); return; } } From 5d74507e507c8fab77fa66e880fb751ad8808f0f Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 9 Mar 2025 14:09:39 +0200 Subject: [PATCH 3/3] Remove goofy comment leftover --- public/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/script.js b/public/script.js index 47b142071..36c5cef98 100644 --- a/public/script.js +++ b/public/script.js @@ -8753,7 +8753,7 @@ function formatSwipeCounter(current, total) { * @param {string} [params.source] The source of the swipe event. * @param {boolean} [params.repeated] Is the swipe event repeated. */ -function swipe_left(_event, { source, repeated } = {}) { // when we swipe left..but no generation. +function swipe_left(_event, { source, repeated } = {}) { if (chat.length - 1 === Number(this_edit_mes_id)) { closeMessageEditor(); }