Merge pull request #2919 from SillyTavern/swipe-nums-for-all-mes add swipe counter to all messages (needs debug)
Signed| @@ -4010,6 +4010,10 @@ | |||
| 4010 | <input id="compact_input_area" type="checkbox" /> | 4010 | <input id="compact_input_area" type="checkbox" /> |
| 4011 | <small data-i18n="Compact Input Area (Mobile)">Compact Input Area</small><i class="fa-solid fa-mobile-screen-button"></i> | 4011 | <small data-i18n="Compact Input Area (Mobile)">Compact Input Area</small><i class="fa-solid fa-mobile-screen-button"></i> |
| 4012 | </label> | 4012 | </label> |
| 4013 | <label for="show_swipe_num_all_messages" class="checkbox_label" title="Display swipe numbers for all messages, not just the last." data-i18n="[title]Display swipe numbers for all messages, not just the last."> | ||
| 4014 | <input id="show_swipe_num_all_messages" type="checkbox" /> | ||
| 4015 | <small data-i18n="Swipe # for All Messages">Swipe # for All Messages</small><i class="fa-solid fa-mobile-screen-button"></i> | ||
| 4016 | </label> | ||
| 4013 | <label for="hotswapEnabled" class="checkbox_label" title="In the Character Management panel, show quick selection buttons for favorited characters." data-i18n="[title]In the Character Management panel, show quick selection buttons for favorited characters"> | 4017 | <label for="hotswapEnabled" class="checkbox_label" title="In the Character Management panel, show quick selection buttons for favorited characters." data-i18n="[title]In the Character Management panel, show quick selection buttons for favorited characters"> |
| 4014 | <input id="hotswapEnabled" type="checkbox" /> | 4018 | <input id="hotswapEnabled" type="checkbox" /> |
| 4015 | <small data-i18n="Characters Hotswap">Characters Hotswap</small> | 4019 | <small data-i18n="Characters Hotswap">Characters Hotswap</small> |
| @@ -5938,9 +5942,10 @@ | |||
| 5938 | </div> | 5942 | </div> |
| 5939 | <div class="mes_bias"></div> | 5943 | <div class="mes_bias"></div> |
| 5940 | </div> | 5944 | </div> |
| 5941 | <div class="swipe_right fa-solid fa-chevron-right" style="display: none;"> | 5945 | <div class="flex-container swipeRightBlock flexFlowColumn flexNoGap"> |
| 5942 | <div class="swipes-counter"></div> | 5946 | <div class="swipe_right fa-solid fa-chevron-right" style="display: none;"></div> |
| 5943 | </div> | 5947 | <div class="swipes-counter"></div> |
| 5948 | </div> | ||
| 5944 | </div> | 5949 | </div> |
| 5945 | </div> | 5950 | </div> |
| 5946 | <div id="group_avatars_template" class="template_element"> | 5951 | <div id="group_avatars_template" class="template_element"> |
| @@ -83,6 +83,7 @@ import { | |||
| 83 | resetMovableStyles, | 83 | resetMovableStyles, |
| 84 | forceCharacterEditorTokenize, | 84 | forceCharacterEditorTokenize, |
| 85 | applyPowerUserSettings, | 85 | applyPowerUserSettings, |
| 86 | switchSwipeNumAllMessages, | ||
| 86 | } from './scripts/power-user.js'; | 87 | } from './scripts/power-user.js'; |
| 87 | 88 | ||
| 88 | import { | 89 | import { |
| @@ -2369,6 +2370,13 @@ export function addOneMessage(mes, { type = 'normal', insertAfter = null, scroll | |||
| 2369 | 2370 | ||
| 2370 | addCopyToCodeBlocks(newMessage); | 2371 | addCopyToCodeBlocks(newMessage); |
| 2371 | 2372 | ||
| 2373 | // Set the swipes counter for past messages, only visible if 'Show Swipes on All Message' is enabled | ||
| 2374 | if (!params.isUser && newMessageId !== 0 && newMessageId !== chat.length - 1) { | ||
| 2375 | const swipesNum = chat[newMessageId].swipes?.length; | ||
| 2376 | const swipeId = chat[newMessageId].swipe_id + 1; | ||
| 2377 | newMessage.find('.swipes-counter').text(`${swipeId}\u200B/\u200b${swipesNum}`); | ||
| 2378 | } | ||
| 2379 | |||
| 2372 | if (showSwipes) { | 2380 | if (showSwipes) { |
| 2373 | $('#chat .mes').last().addClass('last_mes'); | 2381 | $('#chat .mes').last().addClass('last_mes'); |
| 2374 | $('#chat .mes').eq(-2).removeClass('last_mes'); | 2382 | $('#chat .mes').eq(-2).removeClass('last_mes'); |
| @@ -7471,7 +7479,6 @@ export function showSwipeButtons() { | |||
| 7471 | //had to add this to make the swipe counter work | 7479 | //had to add this to make the swipe counter work |
| 7472 | //(copied from the onclick functions for swipe buttons.. | 7480 | //(copied from the onclick functions for swipe buttons.. |
| 7473 | //don't know why the array isn't set for non-swipe messsages in Generate or addOneMessage..) | 7481 | //don't know why the array isn't set for non-swipe messsages in Generate or addOneMessage..) |
| 7474 | |||
| 7475 | if (chat[chat.length - 1]['swipe_id'] === undefined) { // if there is no swipe-message in the last spot of the chat array | 7482 | if (chat[chat.length - 1]['swipe_id'] === undefined) { // if there is no swipe-message in the last spot of the chat array |
| 7476 | chat[chat.length - 1]['swipe_id'] = 0; // set it to id 0 | 7483 | chat[chat.length - 1]['swipe_id'] = 0; // set it to id 0 |
| 7477 | chat[chat.length - 1]['swipes'] = []; // empty the array | 7484 | chat[chat.length - 1]['swipes'] = []; // empty the array |
| @@ -7481,32 +7488,36 @@ export function showSwipeButtons() { | |||
| 7481 | const currentMessage = $('#chat').children().filter(`[mesid="${chat.length - 1}"]`); | 7488 | const currentMessage = $('#chat').children().filter(`[mesid="${chat.length - 1}"]`); |
| 7482 | const swipeId = chat[chat.length - 1].swipe_id; | 7489 | const swipeId = chat[chat.length - 1].swipe_id; |
| 7483 | const swipeCounterText = (`${(swipeId + 1)}\u200B/\u200b${(chat[chat.length - 1].swipes.length)}`); | 7490 | const swipeCounterText = (`${(swipeId + 1)}\u200B/\u200b${(chat[chat.length - 1].swipes.length)}`); |
| 7491 | const swipeRight = currentMessage.find('.swipe_right'); | ||
| 7492 | const swipeLeft = currentMessage.find('.swipe_left'); | ||
| 7493 | const swipeCounter = currentMessage.find('.swipes-counter'); | ||
| 7484 | 7494 | ||
| 7485 | if (swipeId !== undefined && (chat[chat.length - 1].swipes.length > 1 || swipeId > 0)) { | 7495 | if (swipeId !== undefined && (chat[chat.length - 1].swipes.length > 1 || swipeId > 0)) { |
| 7486 | currentMessage.children('.swipe_left').css('display', 'flex'); | 7496 | swipeLeft.css('display', 'flex'); |
| 7487 | } | 7497 | } |
| 7488 | //only show right when generate is off, or when next right swipe would not make a generate happen | 7498 | //only show right when generate is off, or when next right swipe would not make a generate happen |
| 7489 | if (is_send_press === false || chat[chat.length - 1].swipes.length >= swipeId) { | 7499 | if (is_send_press === false || chat[chat.length - 1].swipes.length >= swipeId) { |
| 7490 | currentMessage.children('.swipe_right').css('display', 'flex'); | 7500 | swipeRight.css('display', 'flex').css('opacity', '0.3'); |
| 7491 | currentMessage.children('.swipe_right').css('opacity', '0.3'); | 7501 | swipeCounter.css('opacity', '0.3'); |
| 7492 | } | 7502 | } |
| 7493 | //console.log((chat[chat.length - 1])); | ||
| 7494 | if ((chat[chat.length - 1].swipes.length - swipeId) === 1) { | 7503 | if ((chat[chat.length - 1].swipes.length - swipeId) === 1) { |
| 7495 | //console.log('highlighting R swipe'); | 7504 | //chevron was moved out of hardcode in HTML to class toggle dependent on last_mes or not |
| 7496 | currentMessage.children('.swipe_right').css('opacity', '0.7'); | 7505 | //necessary for 'swipe_right' div in past messages to have no chevron if 'show swipes for all messages' is turned on |
| 7506 | swipeRight.css('opacity', '0.7'); | ||
| 7507 | swipeCounter.css('opacity', '0.7'); | ||
| 7497 | } | 7508 | } |
| 7498 | //console.log(swipesCounterHTML); | ||
| 7499 | 7509 | ||
| 7500 | $('.swipes-counter').text(swipeCounterText); | 7510 | //allows for writing individual swipe counters for past messages |
| 7511 | const lastSwipeCounter = $('.last_mes .swipes-counter'); | ||
| 7512 | lastSwipeCounter.text(swipeCounterText).show(); | ||
| 7501 | 7513 | ||
| 7502 | //console.log(swipeId); | 7514 | switchSwipeNumAllMessages(); |
| 7503 | //console.log(chat[chat.length - 1].swipes.length); | ||
| 7504 | } | 7515 | } |
| 7505 | 7516 | ||
| 7506 | export function hideSwipeButtons() { | 7517 | export function hideSwipeButtons() { |
| 7507 | //console.log('hideswipebuttons entered'); | 7518 | $('#chat').find('.swipe_right').hide(); |
| 7508 | $('#chat').find('.swipe_right').css('display', 'none'); | 7519 | $('#chat').find('.last_mes .swipes-counter').hide(); |
| 7509 | $('#chat').find('.swipe_left').css('display', 'none'); | 7520 | $('#chat').find('.swipe_left').hide(); |
| 7510 | } | 7521 | } |
| 7511 | 7522 | ||
| 7512 | /** | 7523 | /** |
| @@ -8341,8 +8352,8 @@ const swipe_right = () => { | |||
| 8341 | } | 8352 | } |
| 8342 | 8353 | ||
| 8343 | const currentMessage = $('#chat').children().filter(`[mesid="${chat.length - 1}"]`); | 8354 | const currentMessage = $('#chat').children().filter(`[mesid="${chat.length - 1}"]`); |
| 8344 | let this_div = currentMessage.children('.swipe_right'); | 8355 | let this_div = currentMessage.find('.swipe_right'); |
| 8345 | let this_mes_div = this_div.parent(); | 8356 | let this_mes_div = this_div.parent().parent(); |
| 8346 | 8357 | ||
| 8347 | if (chat[chat.length - 1]['swipe_id'] > chat[chat.length - 1]['swipes'].length) { //if we swipe right while generating (the swipe ID is greater than what we are viewing now) | 8358 | if (chat[chat.length - 1]['swipe_id'] > chat[chat.length - 1]['swipes'].length) { //if we swipe right while generating (the swipe ID is greater than what we are viewing now) |
| 8348 | chat[chat.length - 1]['swipe_id'] = chat[chat.length - 1]['swipes'].length; //show that message slot (will be '...' while generating) | 8359 | chat[chat.length - 1]['swipe_id'] = chat[chat.length - 1]['swipes'].length; //show that message slot (will be '...' while generating) |
| @@ -8352,7 +8363,7 @@ const swipe_right = () => { | |||
| 8352 | } | 8363 | } |
| 8353 | // handles animated transitions when swipe right, specifically height transitions between messages | 8364 | // handles animated transitions when swipe right, specifically height transitions between messages |
| 8354 | if (run_generate || run_swipe_right) { | 8365 | if (run_generate || run_swipe_right) { |
| 8355 | let this_mes_block = this_mes_div.children('.mes_block').children('.mes_text'); | 8366 | let this_mes_block = this_mes_div.find('.mes_block .mes_text'); |
| 8356 | const this_mes_div_height = this_mes_div[0].scrollHeight; | 8367 | const this_mes_div_height = this_mes_div[0].scrollHeight; |
| 8357 | const this_mes_block_height = this_mes_block[0].scrollHeight; | 8368 | const this_mes_block_height = this_mes_block[0].scrollHeight; |
| 8358 | 8369 | ||
| @@ -9409,9 +9420,9 @@ jQuery(async function () { | |||
| 9409 | 9420 | ||
| 9410 | ///// SWIPE BUTTON CLICKS /////// | 9421 | ///// SWIPE BUTTON CLICKS /////// |
| 9411 | 9422 | ||
| 9412 | $(document).on('click', '.swipe_right', swipe_right); | 9423 | //limit swiping to only last message clicks |
| 9413 | 9424 | $(document).on('click', '.last_mes .swipe_right', swipe_right); | |
| 9414 | $(document).on('click', '.swipe_left', swipe_left); | 9425 | $(document).on('click', '.last_mes .swipe_left', swipe_left); |
| 9415 | 9426 | ||
| 9416 | const debouncedCharacterSearch = debounce((searchQuery) => { | 9427 | const debouncedCharacterSearch = debounce((searchQuery) => { |
| 9417 | entitiesFilter.setFilterData(FILTER_TYPES.SEARCH, searchQuery); | 9428 | entitiesFilter.setFilterData(FILTER_TYPES.SEARCH, searchQuery); |
| @@ -290,6 +290,7 @@ let power_user = { | |||
| 290 | restore_user_input: true, | 290 | restore_user_input: true, |
| 291 | reduced_motion: false, | 291 | reduced_motion: false, |
| 292 | compact_input_area: true, | 292 | compact_input_area: true, |
| 293 | show_swipe_num_all_messages: false, | ||
| 293 | auto_connect: false, | 294 | auto_connect: false, |
| 294 | auto_load_chat: false, | 295 | auto_load_chat: false, |
| 295 | forbid_external_media: true, | 296 | forbid_external_media: true, |
| @@ -469,6 +470,11 @@ function switchCompactInputArea() { | |||
| 469 | $('#compact_input_area').prop('checked', power_user.compact_input_area); | 470 | $('#compact_input_area').prop('checked', power_user.compact_input_area); |
| 470 | } | 471 | } |
| 471 | 472 | ||
| 473 | export function switchSwipeNumAllMessages() { | ||
| 474 | $('#show_swipe_num_all_messages').prop('checked', power_user.show_swipe_num_all_messages); | ||
| 475 | $('.mes:not(.last_mes) .swipes-counter').css('opacity', '').toggle(power_user.show_swipe_num_all_messages); | ||
| 476 | } | ||
| 477 | |||
| 472 | var originalSliderValues = []; | 478 | var originalSliderValues = []; |
| 473 | 479 | ||
| 474 | async function switchLabMode() { | 480 | async function switchLabMode() { |
| @@ -1283,6 +1289,13 @@ function applyTheme(name) { | |||
| 1283 | switchCompactInputArea(); | 1289 | switchCompactInputArea(); |
| 1284 | }, | 1290 | }, |
| 1285 | }, | 1291 | }, |
| 1292 | { | ||
| 1293 | key: 'show_swipe_num_all_messages', | ||
| 1294 | action: () => { | ||
| 1295 | $('#show_swipe_num_all_messages').prop('checked', power_user.show_swipe_num_all_messages); | ||
| 1296 | switchSwipeNumAllMessages(); | ||
| 1297 | }, | ||
| 1298 | }, | ||
| 1286 | ]; | 1299 | ]; |
| 1287 | 1300 | ||
| 1288 | for (const { key, selector, type, action } of themeProperties) { | 1301 | for (const { key, selector, type, action } of themeProperties) { |
| @@ -1352,6 +1365,7 @@ function applyPowerUserSettings() { | |||
| 1352 | switchHideChatAvatars(); | 1365 | switchHideChatAvatars(); |
| 1353 | switchTokenCount(); | 1366 | switchTokenCount(); |
| 1354 | switchMessageActions(); | 1367 | switchMessageActions(); |
| 1368 | switchSwipeNumAllMessages(); | ||
| 1355 | } | 1369 | } |
| 1356 | 1370 | ||
| 1357 | function getExampleMessagesBehavior() { | 1371 | function getExampleMessagesBehavior() { |
| @@ -2296,6 +2310,7 @@ function getThemeObject(name) { | |||
| 2296 | zoomed_avatar_magnification: power_user.zoomed_avatar_magnification, | 2310 | zoomed_avatar_magnification: power_user.zoomed_avatar_magnification, |
| 2297 | reduced_motion: power_user.reduced_motion, | 2311 | reduced_motion: power_user.reduced_motion, |
| 2298 | compact_input_area: power_user.compact_input_area, | 2312 | compact_input_area: power_user.compact_input_area, |
| 2313 | show_swipe_num_all_messages: power_user.show_swipe_num_all_messages, | ||
| 2299 | }; | 2314 | }; |
| 2300 | } | 2315 | } |
| 2301 | 2316 | ||
| @@ -3755,6 +3770,12 @@ $(document).ready(() => { | |||
| 3755 | saveSettingsDebounced(); | 3770 | saveSettingsDebounced(); |
| 3756 | }); | 3771 | }); |
| 3757 | 3772 | ||
| 3773 | $('#show_swipe_num_all_messages').on('input', function () { | ||
| 3774 | power_user.show_swipe_num_all_messages = !!$(this).prop('checked'); | ||
| 3775 | switchSwipeNumAllMessages(); | ||
| 3776 | saveSettingsDebounced(); | ||
| 3777 | }); | ||
| 3778 | |||
| 3758 | $('#auto-connect-checkbox').on('input', function () { | 3779 | $('#auto-connect-checkbox').on('input', function () { |
| 3759 | power_user.auto_connect = !!$(this).prop('checked'); | 3780 | power_user.auto_connect = !!$(this).prop('checked'); |
| 3760 | saveSettingsDebounced(); | 3781 | saveSettingsDebounced(); |
| @@ -969,34 +969,53 @@ body .panelControlBar { | |||
| 969 | 969 | ||
| 970 | /* SWIPE RELATED STYLES*/ | 970 | /* SWIPE RELATED STYLES*/ |
| 971 | 971 | ||
| 972 | .mes { | ||
| 973 | --swipeCounterHeight: 15px; | ||
| 974 | --swipeCounterMargin: 5px; | ||
| 975 | } | ||
| 976 | |||
| 972 | .swipe_right, | 977 | .swipe_right, |
| 973 | .swipe_left { | 978 | .swipe_left { |
| 974 | height: 40px; | 979 | width: 25px; |
| 975 | width: 40px; | 980 | height: 25px; |
| 976 | opacity: 0.3; | 981 | opacity: 0.3; |
| 977 | align-items: center; | 982 | align-items: center; |
| 978 | justify-content: center; | 983 | justify-content: center; |
| 979 | z-index: 9999; | 984 | z-index: 9999; |
| 980 | grid-row-start: 2; | 985 | grid-row-start: 2; |
| 981 | font-size: 30px; | 986 | font-size: 20px; |
| 982 | cursor: pointer; | 987 | cursor: pointer; |
| 983 | align-self: center; | 988 | align-self: center; |
| 989 | } | ||
| 990 | |||
| 991 | .swipe_left { | ||
| 984 | position: absolute; | 992 | position: absolute; |
| 985 | bottom: 15px; | 993 | bottom: calc(var(--swipeCounterHeight) + var(--swipeCounterMargin)); |
| 986 | flex-flow: column; | 994 | flex-flow: column; |
| 987 | } | 995 | } |
| 988 | 996 | ||
| 997 | .swipeRightBlock { | ||
| 998 | position: absolute; | ||
| 999 | right: 0; | ||
| 1000 | bottom: 0; | ||
| 1001 | } | ||
| 989 | 1002 | ||
| 990 | .swipes-counter { | 1003 | .swipes-counter { |
| 991 | color: var(--SmartThemeBodyColor); | 1004 | color: var(--SmartThemeBodyColor); |
| 992 | font-size: 12px; | 1005 | font-size: 12px; |
| 993 | padding: 0; | 1006 | padding: 0 5px; |
| 994 | font-family: var(--mainFontFamily); | 1007 | font-family: var(--mainFontFamily); |
| 995 | font-weight: 400; | 1008 | font-weight: 400; |
| 996 | align-self: center; | 1009 | align-self: center; |
| 997 | min-width: 40px; | 1010 | min-width: 40px; |
| 998 | display: flex; | 1011 | display: flex; |
| 999 | justify-content: center; | 1012 | justify-content: center; |
| 1013 | margin-bottom: var(--swipeCounterMargin); | ||
| 1014 | height: var(--swipeCounterHeight); | ||
| 1015 | } | ||
| 1016 | |||
| 1017 | .mes:not(.last_mes) .swipes-counter { | ||
| 1018 | opacity: 0.3; | ||
| 1000 | } | 1019 | } |
| 1001 | 1020 | ||
| 1002 | .swipe_left { | 1021 | .swipe_left { |
| @@ -1006,7 +1025,7 @@ flex-flow: column; | |||
| 1006 | 1025 | ||
| 1007 | .swipe_right { | 1026 | .swipe_right { |
| 1008 | right: 5px; | 1027 | right: 5px; |
| 1009 | align-self:end; | 1028 | align-self: center; |
| 1010 | } | 1029 | } |
| 1011 | 1030 | ||
| 1012 | .ui-settings { | 1031 | .ui-settings { |
| @@ -2640,7 +2659,7 @@ select option:not(:checked) { | |||
| 2640 | 2659 | ||
| 2641 | #instruct_enabled_label .menu_button:not(.toggleEnabled), | 2660 | #instruct_enabled_label .menu_button:not(.toggleEnabled), |
| 2642 | #sysprompt_enabled_label .menu_button:not(.toggleEnabled) { | 2661 | #sysprompt_enabled_label .menu_button:not(.toggleEnabled) { |
| 2643 | color: Red; | 2662 | color: Red; |
| 2644 | } | 2663 | } |
| 2645 | 2664 | ||
| 2646 | .displayBlock { | 2665 | .displayBlock { |