Prevent rollover on keyboard left swipe if repeating (#3644) * Prevent rollover on keyboard left swipe if repeating Closes #3636 * Ditto for right swipe * Remove goofy comment leftover

cabd6de85b5db765c3efba0371e45086f4d6e6f3

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

Signed
2 files changed, +28 -7Ignore whitespace
public/script.js+26 -5
@@ -8746,11 +8746,17 @@ function formatSwipeCounter(current, total) {
87468746 return `${current}\u200b/\u200b${total}`;
87478747}
87488748
8749-function swipe_left() { // when we swipe left..but no generation.
8749+/**
8750+ * Handles the swipe to the left event.
8751+ * @param {JQuery.Event} _event Event.
8752+ * @param {object} params Additional parameters.
8753+ * @param {string} [params.source] The source of the swipe event.
8754+ * @param {boolean} [params.repeated] Is the swipe event repeated.
8755+ */
8756+function swipe_left(_event, { source, repeated } = {}) {
87508757 if (chat.length - 1 === Number(this_edit_mes_id)) {
87518758 closeMessageEditor();
87528759 }
8753-
87548760 if (isStreamingEnabled() && streamingProcessor) {
87558761 streamingProcessor.onStopStreaming();
87568762 }
@@ -8758,6 +8764,11 @@ function swipe_left() { // when we swipe left..but no generation.
87588764 // Make sure ad-hoc changes to extras are saved before swiping away
87598765 syncMesToSwipe();
87608766
8767+ // If the user is holding down the key and we're at the first swipe, don't do anything
8768+ if (source === 'keyboard' && repeated && chat[chat.length - 1].swipe_id === 0) {
8769+ return;
8770+ }
8771+
87618772 const swipe_duration = 120;
87628773 const swipe_range = '700px';
87638774 chat[chat.length - 1]['swipe_id']--;
@@ -8883,8 +8894,14 @@ function swipe_left() { // when we swipe left..but no generation.
88838894 }
88848895}
88858896
8886-// when we click swipe right button
8897+/**
8887-const swipe_right = () => {
8898+ * Handles the swipe to the right event.
8899+ * @param {JQuery.Event} _event Event.
8900+ * @param {object} params Additional parameters.
8901+ * @param {string} [params.source] The source of the swipe event.
8902+ * @param {boolean} [params.repeated] Is the swipe event repeated.
8903+ */
8904+function swipe_right(_event, { source, repeated } = {}) {
88888905 if (chat.length - 1 === Number(this_edit_mes_id)) {
88898906 closeMessageEditor();
88908907 }
@@ -8917,6 +8934,10 @@ const swipe_right = () => {
89178934 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
89188935 chat[0]['swipe_id'] = 0;
89198936 } else {
8937+ // If the user is holding down the key and we're at the last swipe, don't do anything
8938+ if (source === 'keyboard' && repeated && chat[chat.length - 1].swipe_id === chat[chat.length - 1].swipes.length - 1) {
8939+ return;
8940+ }
89208941 chat[chat.length - 1]['swipe_id']++; // make new slot in array
89218942 }
89228943 if (chat[chat.length - 1].extra) {
@@ -9065,7 +9086,7 @@ const swipe_right = () => {
90659086 },
90669087 });
90679088 }
90689089};
90699090
90709091export const CONNECT_API_MAP = {
90719092 // Default APIs not contined inside text gen / chat gen
public/scripts/RossAscends-mods.js+2 -2
@@ -1143,7 +1143,7 @@ export function initRossMods() {
11431143 $('#shadow_select_chat_popup').css('display') === 'none' &&
11441144 !isInputElementInFocus()
11451145 ) {
11461146 $('.swipe_left:last').clicktrigger('click', { source: 'keyboard', repeated: event.repeat });
11471147 return;
11481148 }
11491149 }
@@ -1156,7 +1156,7 @@ export function initRossMods() {
11561156 $('#shadow_select_chat_popup').css('display') === 'none' &&
11571157 !isInputElementInFocus()
11581158 ) {
11591159 $('.swipe_right:last').clicktrigger('click', { source: 'keyboard', repeated: event.repeat });
11601160 return;
11611161 }
11621162 }