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
Signed| @@ -8746,11 +8746,17 @@ function formatSwipeCounter(current, total) { | |||
| 8746 | return `${current}\u200b/\u200b${total}`; | 8746 | return `${current}\u200b/\u200b${total}`; |
| 8747 | } | 8747 | } |
| 8748 | 8748 | ||
| 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 } = {}) { | ||
| 8750 | if (chat.length - 1 === Number(this_edit_mes_id)) { | 8757 | if (chat.length - 1 === Number(this_edit_mes_id)) { |
| 8751 | closeMessageEditor(); | 8758 | closeMessageEditor(); |
| 8752 | } | 8759 | } |
| 8753 | |||
| 8754 | if (isStreamingEnabled() && streamingProcessor) { | 8760 | if (isStreamingEnabled() && streamingProcessor) { |
| 8755 | streamingProcessor.onStopStreaming(); | 8761 | streamingProcessor.onStopStreaming(); |
| 8756 | } | 8762 | } |
| @@ -8758,6 +8764,11 @@ function swipe_left() { // when we swipe left..but no generation. | |||
| 8758 | // Make sure ad-hoc changes to extras are saved before swiping away | 8764 | // Make sure ad-hoc changes to extras are saved before swiping away |
| 8759 | syncMesToSwipe(); | 8765 | syncMesToSwipe(); |
| 8760 | 8766 | ||
| 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 | |||
| 8761 | const swipe_duration = 120; | 8772 | const swipe_duration = 120; |
| 8762 | const swipe_range = '700px'; | 8773 | const swipe_range = '700px'; |
| 8763 | chat[chat.length - 1]['swipe_id']--; | 8774 | chat[chat.length - 1]['swipe_id']--; |
| @@ -8883,8 +8894,14 @@ function swipe_left() { // when we swipe left..but no generation. | |||
| 8883 | } | 8894 | } |
| 8884 | } | 8895 | } |
| 8885 | 8896 | ||
| 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 } = {}) { | ||
| 8888 | if (chat.length - 1 === Number(this_edit_mes_id)) { | 8905 | if (chat.length - 1 === Number(this_edit_mes_id)) { |
| 8889 | closeMessageEditor(); | 8906 | closeMessageEditor(); |
| 8890 | } | 8907 | } |
| @@ -8917,6 +8934,10 @@ const swipe_right = () => { | |||
| 8917 | 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 | 8934 | 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 |
| 8918 | chat[0]['swipe_id'] = 0; | 8935 | chat[0]['swipe_id'] = 0; |
| 8919 | } else { | 8936 | } 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 | } | ||
| 8920 | chat[chat.length - 1]['swipe_id']++; // make new slot in array | 8941 | chat[chat.length - 1]['swipe_id']++; // make new slot in array |
| 8921 | } | 8942 | } |
| 8922 | if (chat[chat.length - 1].extra) { | 8943 | if (chat[chat.length - 1].extra) { |
| @@ -9065,7 +9086,7 @@ const swipe_right = () => { | |||
| 9065 | }, | 9086 | }, |
| 9066 | }); | 9087 | }); |
| 9067 | } | 9088 | } |
| 9068 | }; | 9089 | } |
| 9069 | 9090 | ||
| 9070 | export const CONNECT_API_MAP = { | 9091 | export const CONNECT_API_MAP = { |
| 9071 | // Default APIs not contined inside text gen / chat gen | 9092 | // Default APIs not contined inside text gen / chat gen |
| @@ -1143,7 +1143,7 @@ export function initRossMods() { | |||
| 1143 | $('#shadow_select_chat_popup').css('display') === 'none' && | 1143 | $('#shadow_select_chat_popup').css('display') === 'none' && |
| 1144 | !isInputElementInFocus() | 1144 | !isInputElementInFocus() |
| 1145 | ) { | 1145 | ) { |
| 1146 | $('.swipe_left:last').click(); | 1146 | $('.swipe_left:last').trigger('click', { source: 'keyboard', repeated: event.repeat }); |
| 1147 | return; | 1147 | return; |
| 1148 | } | 1148 | } |
| 1149 | } | 1149 | } |
| @@ -1156,7 +1156,7 @@ export function initRossMods() { | |||
| 1156 | $('#shadow_select_chat_popup').css('display') === 'none' && | 1156 | $('#shadow_select_chat_popup').css('display') === 'none' && |
| 1157 | !isInputElementInFocus() | 1157 | !isInputElementInFocus() |
| 1158 | ) { | 1158 | ) { |
| 1159 | $('.swipe_right:last').click(); | 1159 | $('.swipe_right:last').trigger('click', { source: 'keyboard', repeated: event.repeat }); |
| 1160 | return; | 1160 | return; |
| 1161 | } | 1161 | } |
| 1162 | } | 1162 | } |