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 | 4010 | <input id="compact_input_area" type="checkbox" /> |
| 4011 | 4011 | <small data-i18n="Compact Input Area (Mobile)">Compact Input Area</small><i class="fa-solid fa-mobile-screen-button"></i> |
| 4012 | 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 | 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 | 4018 | <input id="hotswapEnabled" type="checkbox" /> |
| 4015 | 4019 | <small data-i18n="Characters Hotswap">Characters Hotswap</small> |
| @@ -5938,9 +5942,10 @@ | ||
| 5938 | 5942 | </div> |
| 5939 | 5943 | <div class="mes_bias"></div> |
| 5940 | 5944 | </div> |
| 5941 | 5945 | <div class="swipe_right faflex-solidcontainer fa-chevron-right"swipeRightBlock style="display:flexFlowColumn none;flexNoGap"> |
| 5942 | 5946 | <div class="swipesswipe_right fa-countersolid fa-chevron-right" style="display: none;"></div> |
| 5943 | - </div> | |
| 5947 | + <div class="swipes-counter"></div> | |
| 5948 | + </div> | |
| 5944 | 5949 | </div> |
| 5945 | 5950 | </div> |
| 5946 | 5951 | <div id="group_avatars_template" class="template_element"> |
| @@ -83,6 +83,7 @@ import { | ||
| 83 | 83 | resetMovableStyles, |
| 84 | 84 | forceCharacterEditorTokenize, |
| 85 | 85 | applyPowerUserSettings, |
| 86 | + switchSwipeNumAllMessages, | |
| 86 | 87 | } from './scripts/power-user.js'; |
| 87 | 88 | |
| 88 | 89 | import { |
| @@ -2369,6 +2370,13 @@ export function addOneMessage(mes, { type = 'normal', insertAfter = null, scroll | ||
| 2369 | 2370 | |
| 2370 | 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 | 2380 | if (showSwipes) { |
| 2373 | 2381 | $('#chat .mes').last().addClass('last_mes'); |
| 2374 | 2382 | $('#chat .mes').eq(-2).removeClass('last_mes'); |
| @@ -7471,7 +7479,6 @@ export function showSwipeButtons() { | ||
| 7471 | 7479 | //had to add this to make the swipe counter work |
| 7472 | 7480 | //(copied from the onclick functions for swipe buttons.. |
| 7473 | 7481 | //don't know why the array isn't set for non-swipe messsages in Generate or addOneMessage..) |
| 7474 | - | |
| 7475 | 7482 | if (chat[chat.length - 1]['swipe_id'] === undefined) { // if there is no swipe-message in the last spot of the chat array |
| 7476 | 7483 | chat[chat.length - 1]['swipe_id'] = 0; // set it to id 0 |
| 7477 | 7484 | chat[chat.length - 1]['swipes'] = []; // empty the array |
| @@ -7481,32 +7488,36 @@ export function showSwipeButtons() { | ||
| 7481 | 7488 | const currentMessage = $('#chat').children().filter(`[mesid="${chat.length - 1}"]`); |
| 7482 | 7489 | const swipeId = chat[chat.length - 1].swipe_id; |
| 7483 | 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 | 7495 | if (swipeId !== undefined && (chat[chat.length - 1].swipes.length > 1 || swipeId > 0)) { |
| 7486 | 7496 | currentMessage.children('.swipe_left')swipeLeft.css('display', 'flex'); |
| 7487 | 7497 | } |
| 7488 | 7498 | //only show right when generate is off, or when next right swipe would not make a generate happen |
| 7489 | 7499 | if (is_send_press === false || chat[chat.length - 1].swipes.length >= swipeId) { |
| 7490 | 7500 | currentMessageswipeRight.childrencss('.swipe_rightdisplay', 'flex').css('displayopacity', 'flex0.3'); |
| 7491 | 7501 | currentMessage.children('.swipe_right')swipeCounter.css('opacity', '0.3'); |
| 7492 | 7502 | } |
| 7493 | - //console.log((chat[chat.length - 1])); | |
| 7494 | 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 | 7514 | //console.logswitchSwipeNumAllMessages(swipeId); |
| 7503 | - //console.log(chat[chat.length - 1].swipes.length); | |
| 7504 | 7515 | } |
| 7505 | 7516 | |
| 7506 | 7517 | export function hideSwipeButtons() { |
| 7507 | - //console.log('hideswipebuttons entered'); | |
| 7518 | + $('#chat').find('.swipe_right').hide(); | |
| 7508 | 7519 | $('#chat').find('.swipe_rightlast_mes .swipes-counter').csshide('display', 'none'); |
| 7509 | 7520 | $('#chat').find('.swipe_left').csshide('display', 'none'); |
| 7510 | 7521 | } |
| 7511 | 7522 | |
| 7512 | 7523 | /** |
| @@ -8341,8 +8352,8 @@ const swipe_right = () => { | ||
| 8341 | 8352 | } |
| 8342 | 8353 | |
| 8343 | 8354 | const currentMessage = $('#chat').children().filter(`[mesid="${chat.length - 1}"]`); |
| 8344 | 8355 | let this_div = currentMessage.childrenfind('.swipe_right'); |
| 8345 | 8356 | let this_mes_div = this_div.parent().parent(); |
| 8346 | 8357 | |
| 8347 | 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 | 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 | 8364 | // handles animated transitions when swipe right, specifically height transitions between messages |
| 8354 | 8365 | if (run_generate || run_swipe_right) { |
| 8355 | 8366 | let this_mes_block = this_mes_div.childrenfind('.mes_block').children(' .mes_text'); |
| 8356 | 8367 | const this_mes_div_height = this_mes_div[0].scrollHeight; |
| 8357 | 8368 | const this_mes_block_height = this_mes_block[0].scrollHeight; |
| 8358 | 8369 | |
| @@ -9409,9 +9420,9 @@ jQuery(async function () { | ||
| 9409 | 9420 | |
| 9410 | 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 | 9425 | $(document).on('click', '.last_mes .swipe_left', swipe_left); |
| 9415 | 9426 | |
| 9416 | 9427 | const debouncedCharacterSearch = debounce((searchQuery) => { |
| 9417 | 9428 | entitiesFilter.setFilterData(FILTER_TYPES.SEARCH, searchQuery); |
| @@ -290,6 +290,7 @@ let power_user = { | ||
| 290 | 290 | restore_user_input: true, |
| 291 | 291 | reduced_motion: false, |
| 292 | 292 | compact_input_area: true, |
| 293 | + show_swipe_num_all_messages: false, | |
| 293 | 294 | auto_connect: false, |
| 294 | 295 | auto_load_chat: false, |
| 295 | 296 | forbid_external_media: true, |
| @@ -469,6 +470,11 @@ function switchCompactInputArea() { | ||
| 469 | 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 | 478 | var originalSliderValues = []; |
| 473 | 479 | |
| 474 | 480 | async function switchLabMode() { |
| @@ -1283,6 +1289,13 @@ function applyTheme(name) { | ||
| 1283 | 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 | 1301 | for (const { key, selector, type, action } of themeProperties) { |
| @@ -1352,6 +1365,7 @@ function applyPowerUserSettings() { | ||
| 1352 | 1365 | switchHideChatAvatars(); |
| 1353 | 1366 | switchTokenCount(); |
| 1354 | 1367 | switchMessageActions(); |
| 1368 | + switchSwipeNumAllMessages(); | |
| 1355 | 1369 | } |
| 1356 | 1370 | |
| 1357 | 1371 | function getExampleMessagesBehavior() { |
| @@ -2296,6 +2310,7 @@ function getThemeObject(name) { | ||
| 2296 | 2310 | zoomed_avatar_magnification: power_user.zoomed_avatar_magnification, |
| 2297 | 2311 | reduced_motion: power_user.reduced_motion, |
| 2298 | 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 | 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 | 3779 | $('#auto-connect-checkbox').on('input', function () { |
| 3759 | 3780 | power_user.auto_connect = !!$(this).prop('checked'); |
| 3760 | 3781 | saveSettingsDebounced(); |
| @@ -969,34 +969,53 @@ body .panelControlBar { | ||
| 969 | 969 | |
| 970 | 970 | /* SWIPE RELATED STYLES*/ |
| 971 | 971 | |
| 972 | +.mes { | |
| 973 | + --swipeCounterHeight: 15px; | |
| 974 | + --swipeCounterMargin: 5px; | |
| 975 | +} | |
| 976 | + | |
| 972 | 977 | .swipe_right, |
| 973 | 978 | .swipe_left { |
| 974 | 979 | heightwidth: 40px25px; |
| 975 | 980 | widthheight: 40px25px; |
| 976 | 981 | opacity: 0.3; |
| 977 | 982 | align-items: center; |
| 978 | 983 | justify-content: center; |
| 979 | 984 | z-index: 9999; |
| 980 | 985 | grid-row-start: 2; |
| 981 | 986 | font-size: 30px20px; |
| 982 | 987 | cursor: pointer; |
| 983 | 988 | align-self: center; |
| 989 | +} | |
| 990 | + | |
| 991 | +.swipe_left { | |
| 984 | 992 | position: absolute; |
| 985 | -bottom: 15px; | |
| 993 | + bottom: calc(var(--swipeCounterHeight) + var(--swipeCounterMargin)); | |
| 986 | 994 | flex-flow: column; |
| 987 | 995 | } |
| 988 | 996 | |
| 997 | +.swipeRightBlock { | |
| 998 | + position: absolute; | |
| 999 | + right: 0; | |
| 1000 | + bottom: 0; | |
| 1001 | +} | |
| 989 | 1002 | |
| 990 | 1003 | .swipes-counter { |
| 991 | 1004 | color: var(--SmartThemeBodyColor); |
| 992 | 1005 | font-size: 12px; |
| 993 | 1006 | padding: 0 5px; |
| 994 | 1007 | font-family: var(--mainFontFamily); |
| 995 | 1008 | font-weight: 400; |
| 996 | 1009 | align-self: center; |
| 997 | 1010 | min-width: 40px; |
| 998 | 1011 | display: flex; |
| 999 | 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 | 1021 | .swipe_left { |
| @@ -1006,7 +1025,7 @@ flex-flow: column; | ||
| 1006 | 1025 | |
| 1007 | 1026 | .swipe_right { |
| 1008 | 1027 | right: 5px; |
| 1009 | 1028 | align-self:end center; |
| 1010 | 1029 | } |
| 1011 | 1030 | |
| 1012 | 1031 | .ui-settings { |
| @@ -2640,7 +2659,7 @@ select option:not(:checked) { | ||
| 2640 | 2659 | |
| 2641 | 2660 | #instruct_enabled_label .menu_button:not(.toggleEnabled), |
| 2642 | 2661 | #sysprompt_enabled_label .menu_button:not(.toggleEnabled) { |
| 2643 | 2662 | color: Red; |
| 2644 | 2663 | } |
| 2645 | 2664 | |
| 2646 | 2665 | .displayBlock { |