async for resetScrollHeight, slightly faster WI/AF panel loads
| @@ -6424,7 +6424,7 @@ export async function getSettings() { | |||
| 6424 | loadHordeSettings(settings); | 6424 | loadHordeSettings(settings); |
| 6425 | 6425 | ||
| 6426 | // Load power user settings | 6426 | // Load power user settings |
| 6427 | loadPowerUserSettings(settings, data); | 6427 | await loadPowerUserSettings(settings, data); |
| 6428 | 6428 | ||
| 6429 | // Load character tags | 6429 | // Load character tags |
| 6430 | loadTagsSettings(settings); | 6430 | loadTagsSettings(settings); |
| @@ -10457,8 +10457,9 @@ jQuery(async function () { | |||
| 10457 | } | 10457 | } |
| 10458 | 10458 | ||
| 10459 | // Set the height of "autoSetHeight" textareas within the drawer to their scroll height | 10459 | // Set the height of "autoSetHeight" textareas within the drawer to their scroll height |
| 10460 | $(this).closest('.drawer').find('.drawer-content textarea.autoSetHeight').each(function () { | 10460 | $(this).closest('.drawer').find('.drawer-content textarea.autoSetHeight').each(async function () { |
| 10461 | resetScrollHeight($(this)); | 10461 | await resetScrollHeight($(this)); |
| 10462 | return; | ||
| 10462 | }); | 10463 | }); |
| 10463 | 10464 | ||
| 10464 | } else if (drawerWasOpenAlready) { //to close manually | 10465 | } else if (drawerWasOpenAlready) { //to close manually |
| @@ -10531,8 +10532,9 @@ jQuery(async function () { | |||
| 10531 | $(this).closest('.inline-drawer').find('.inline-drawer-content').stop().slideToggle(); | 10532 | $(this).closest('.inline-drawer').find('.inline-drawer-content').stop().slideToggle(); |
| 10532 | 10533 | ||
| 10533 | // Set the height of "autoSetHeight" textareas within the inline-drawer to their scroll height | 10534 | // Set the height of "autoSetHeight" textareas within the inline-drawer to their scroll height |
| 10534 | $(this).closest('.inline-drawer').find('.inline-drawer-content textarea.autoSetHeight').each(function () { | 10535 | $(this).closest('.inline-drawer').find('.inline-drawer-content textarea.autoSetHeight').each(async function () { |
| 10535 | resetScrollHeight($(this)); | 10536 | await resetScrollHeight($(this)); |
| 10537 | return; | ||
| 10536 | }); | 10538 | }); |
| 10537 | }); | 10539 | }); |
| 10538 | 10540 | ||
| @@ -719,29 +719,29 @@ function onChatChanged() { | |||
| 719 | adjustElementScrollHeight(); | 719 | adjustElementScrollHeight(); |
| 720 | } | 720 | } |
| 721 | 721 | ||
| 722 | function adjustElementScrollHeight() { | 722 | async function adjustElementScrollHeight() { |
| 723 | if (!$('.sd_settings').is(':visible')) { | 723 | if (!$('.sd_settings').is(':visible')) { |
| 724 | return; | 724 | return; |
| 725 | } | 725 | } |
| 726 | 726 | ||
| 727 | resetScrollHeight($('#sd_prompt_prefix')); | 727 | await resetScrollHeight($('#sd_prompt_prefix')); |
| 728 | resetScrollHeight($('#sd_negative_prompt')); | 728 | await resetScrollHeight($('#sd_negative_prompt')); |
| 729 | resetScrollHeight($('#sd_character_prompt')); | 729 | await resetScrollHeight($('#sd_character_prompt')); |
| 730 | resetScrollHeight($('#sd_character_negative_prompt')); | 730 | await resetScrollHeight($('#sd_character_negative_prompt')); |
| 731 | } | 731 | } |
| 732 | 732 | ||
| 733 | function onCharacterPromptInput() { | 733 | async function onCharacterPromptInput() { |
| 734 | const key = getCharaFilename(this_chid); | 734 | const key = getCharaFilename(this_chid); |
| 735 | extension_settings.sd.character_prompts[key] = $('#sd_character_prompt').val(); | 735 | extension_settings.sd.character_prompts[key] = $('#sd_character_prompt').val(); |
| 736 | resetScrollHeight($(this)); | 736 | await resetScrollHeight($(this)); |
| 737 | saveSettingsDebounced(); | 737 | saveSettingsDebounced(); |
| 738 | writePromptFieldsDebounced(this_chid); | 738 | writePromptFieldsDebounced(this_chid); |
| 739 | } | 739 | } |
| 740 | 740 | ||
| 741 | function onCharacterNegativePromptInput() { | 741 | async function onCharacterNegativePromptInput() { |
| 742 | const key = getCharaFilename(this_chid); | 742 | const key = getCharaFilename(this_chid); |
| 743 | extension_settings.sd.character_negative_prompts[key] = $('#sd_character_negative_prompt').val(); | 743 | extension_settings.sd.character_negative_prompts[key] = $('#sd_character_negative_prompt').val(); |
| 744 | resetScrollHeight($(this)); | 744 | await resetScrollHeight($(this)); |
| 745 | saveSettingsDebounced(); | 745 | saveSettingsDebounced(); |
| 746 | writePromptFieldsDebounced(this_chid); | 746 | writePromptFieldsDebounced(this_chid); |
| 747 | } | 747 | } |
| @@ -850,15 +850,15 @@ function onStepsInput() { | |||
| 850 | saveSettingsDebounced(); | 850 | saveSettingsDebounced(); |
| 851 | } | 851 | } |
| 852 | 852 | ||
| 853 | function onPromptPrefixInput() { | 853 | async function onPromptPrefixInput() { |
| 854 | extension_settings.sd.prompt_prefix = $('#sd_prompt_prefix').val(); | 854 | extension_settings.sd.prompt_prefix = $('#sd_prompt_prefix').val(); |
| 855 | resetScrollHeight($(this)); | 855 | await resetScrollHeight($(this)); |
| 856 | saveSettingsDebounced(); | 856 | saveSettingsDebounced(); |
| 857 | } | 857 | } |
| 858 | 858 | ||
| 859 | function onNegativePromptInput() { | 859 | async function onNegativePromptInput() { |
| 860 | extension_settings.sd.negative_prompt = $('#sd_negative_prompt').val(); | 860 | extension_settings.sd.negative_prompt = $('#sd_negative_prompt').val(); |
| 861 | resetScrollHeight($(this)); | 861 | await resetScrollHeight($(this)); |
| 862 | saveSettingsDebounced(); | 862 | saveSettingsDebounced(); |
| 863 | } | 863 | } |
| 864 | 864 | ||
| @@ -59,8 +59,8 @@ async function doTokenCounter() { | |||
| 59 | $('#tokenized_chunks_display').text('—'); | 59 | $('#tokenized_chunks_display').text('—'); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | resetScrollHeight($('#token_counter_textarea')); | 62 | await resetScrollHeight($('#token_counter_textarea')); |
| 63 | resetScrollHeight($('#token_counter_ids')); | 63 | await resetScrollHeight($('#token_counter_ids')); |
| 64 | }, debounce_timeout.relaxed); | 64 | }, debounce_timeout.relaxed); |
| 65 | dialog.find('#token_counter_textarea').on('input', () => countDebounced()); | 65 | dialog.find('#token_counter_textarea').on('input', () => countDebounced()); |
| 66 | 66 | ||
| @@ -134,7 +134,8 @@ jQuery(() => { | |||
| 134 | </div>`; | 134 | </div>`; |
| 135 | $('#token_counter_wand_container').append(buttonHtml); | 135 | $('#token_counter_wand_container').append(buttonHtml); |
| 136 | $('#token_counter').on('click', doTokenCounter); | 136 | $('#token_counter').on('click', doTokenCounter); |
| 137 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'count', | 137 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 138 | name: 'count', | ||
| 138 | callback: async () => String(await doCount()), | 139 | callback: async () => String(await doCount()), |
| 139 | returns: 'number of tokens', | 140 | returns: 'number of tokens', |
| 140 | helpString: 'Counts the number of tokens in the current chat.', | 141 | helpString: 'Counts the number of tokens in the current chat.', |
| @@ -94,11 +94,11 @@ export function loadInstructMode(data) { | |||
| 94 | $element.val(power_user.instruct[control.property]); | 94 | $element.val(power_user.instruct[control.property]); |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | $element.on('input', function () { | 97 | $element.on('input', async function () { |
| 98 | power_user.instruct[control.property] = control.isCheckbox ? !!$(this).prop('checked') : $(this).val(); | 98 | power_user.instruct[control.property] = control.isCheckbox ? !!$(this).prop('checked') : $(this).val(); |
| 99 | saveSettingsDebounced(); | 99 | saveSettingsDebounced(); |
| 100 | if (!control.isCheckbox) { | 100 | if (!control.isCheckbox) { |
| 101 | resetScrollHeight($element); | 101 | await resetScrollHeight($element); |
| 102 | } | 102 | } |
| 103 | }); | 103 | }); |
| 104 | 104 | ||
| @@ -1480,7 +1480,7 @@ function getExampleMessagesBehavior() { | |||
| 1480 | return 'normal'; | 1480 | return 'normal'; |
| 1481 | } | 1481 | } |
| 1482 | 1482 | ||
| 1483 | function loadPowerUserSettings(settings, data) { | 1483 | async function loadPowerUserSettings(settings, data) { |
| 1484 | const defaultStscript = JSON.parse(JSON.stringify(power_user.stscript)); | 1484 | const defaultStscript = JSON.parse(JSON.stringify(power_user.stscript)); |
| 1485 | // Load from settings.json | 1485 | // Load from settings.json |
| 1486 | if (settings.power_user !== undefined) { | 1486 | if (settings.power_user !== undefined) { |
| @@ -1740,7 +1740,7 @@ function loadPowerUserSettings(settings, data) { | |||
| 1740 | switchCompactInputArea(); | 1740 | switchCompactInputArea(); |
| 1741 | reloadMarkdownProcessor(power_user.render_formulas); | 1741 | reloadMarkdownProcessor(power_user.render_formulas); |
| 1742 | loadInstructMode(data); | 1742 | loadInstructMode(data); |
| 1743 | loadContextSettings(); | 1743 | await loadContextSettings(); |
| 1744 | loadMaxContextUnlocked(); | 1744 | loadMaxContextUnlocked(); |
| 1745 | switchWaifuMode(); | 1745 | switchWaifuMode(); |
| 1746 | switchSpoilerMode(); | 1746 | switchSpoilerMode(); |
| @@ -1872,7 +1872,7 @@ function getContextSettings() { | |||
| 1872 | 1872 | ||
| 1873 | // TODO: Maybe add a refresh button to reset settings to preset | 1873 | // TODO: Maybe add a refresh button to reset settings to preset |
| 1874 | // TODO: Add "global state" if a preset doesn't set the power_user checkboxes | 1874 | // TODO: Add "global state" if a preset doesn't set the power_user checkboxes |
| 1875 | function loadContextSettings() { | 1875 | async function loadContextSettings() { |
| 1876 | contextControls.forEach(control => { | 1876 | contextControls.forEach(control => { |
| 1877 | const $element = $(`#${control.id}`); | 1877 | const $element = $(`#${control.id}`); |
| 1878 | 1878 | ||
| @@ -1892,7 +1892,7 @@ function loadContextSettings() { | |||
| 1892 | 1892 | ||
| 1893 | // If the setting already exists, no need to duplicate it | 1893 | // If the setting already exists, no need to duplicate it |
| 1894 | // TODO: Maybe check the power_user object for the setting instead of a flag? | 1894 | // TODO: Maybe check the power_user object for the setting instead of a flag? |
| 1895 | $element.on('input', function () { | 1895 | $element.on('input', async function () { |
| 1896 | const value = control.isCheckbox ? !!$(this).prop('checked') : $(this).val(); | 1896 | const value = control.isCheckbox ? !!$(this).prop('checked') : $(this).val(); |
| 1897 | if (control.isGlobalSetting) { | 1897 | if (control.isGlobalSetting) { |
| 1898 | power_user[control.property] = value; | 1898 | power_user[control.property] = value; |
| @@ -1902,7 +1902,7 @@ function loadContextSettings() { | |||
| 1902 | 1902 | ||
| 1903 | saveSettingsDebounced(); | 1903 | saveSettingsDebounced(); |
| 1904 | if (!control.isCheckbox) { | 1904 | if (!control.isCheckbox) { |
| 1905 | resetScrollHeight($element); | 1905 | await resetScrollHeight($element); |
| 1906 | } | 1906 | } |
| 1907 | }); | 1907 | }); |
| 1908 | }); | 1908 | }); |
| @@ -498,8 +498,9 @@ export function restoreCaretPosition(element, position) { | |||
| 498 | } | 498 | } |
| 499 | 499 | ||
| 500 | export async function resetScrollHeight(element) { | 500 | export async function resetScrollHeight(element) { |
| 501 | let scrollHeight = $(element).prop('scrollHeight'); | ||
| 501 | $(element).css('height', '0px'); | 502 | $(element).css('height', '0px'); |
| 502 | $(element).css('height', $(element).prop('scrollHeight') + 3 + 'px'); | 503 | $(element).css('height', scrollHeight + 3 + 'px'); |
| 503 | } | 504 | } |
| 504 | 505 | ||
| 505 | /** | 506 | /** |
| @@ -2331,7 +2331,7 @@ function getWorldEntry(name, data, entry) { | |||
| 2331 | /** @type {string[]} */ | 2331 | /** @type {string[]} */ |
| 2332 | const keys = ($(this).select2('data')).map(x => x.text); | 2332 | const keys = ($(this).select2('data')).map(x => x.text); |
| 2333 | 2333 | ||
| 2334 | !skipReset && resetScrollHeight(this); | 2334 | !skipReset && await resetScrollHeight(this); |
| 2335 | if (!noSave) { | 2335 | if (!noSave) { |
| 2336 | data.entries[uid][entryPropName] = keys; | 2336 | data.entries[uid][entryPropName] = keys; |
| 2337 | setWIOriginalDataValue(data, uid, originalDataValueName, data.entries[uid][entryPropName]); | 2337 | setWIOriginalDataValue(data, uid, originalDataValueName, data.entries[uid][entryPropName]); |
| @@ -2369,7 +2369,7 @@ function getWorldEntry(name, data, entry) { | |||
| 2369 | input.on('input', async function (_, { skipReset, noSave } = {}) { | 2369 | input.on('input', async function (_, { skipReset, noSave } = {}) { |
| 2370 | const uid = $(this).data('uid'); | 2370 | const uid = $(this).data('uid'); |
| 2371 | const value = String($(this).val()); | 2371 | const value = String($(this).val()); |
| 2372 | !skipReset && resetScrollHeight(this); | 2372 | !skipReset && await resetScrollHeight(this); |
| 2373 | if (!noSave) { | 2373 | if (!noSave) { |
| 2374 | data.entries[uid][entryPropName] = splitKeywordsAndRegexes(value); | 2374 | data.entries[uid][entryPropName] = splitKeywordsAndRegexes(value); |
| 2375 | setWIOriginalDataValue(data, uid, originalDataValueName, data.entries[uid][entryPropName]); | 2375 | setWIOriginalDataValue(data, uid, originalDataValueName, data.entries[uid][entryPropName]); |
| @@ -2538,7 +2538,7 @@ function getWorldEntry(name, data, entry) { | |||
| 2538 | commentInput.on('input', async function (_, { skipReset } = {}) { | 2538 | commentInput.on('input', async function (_, { skipReset } = {}) { |
| 2539 | const uid = $(this).data('uid'); | 2539 | const uid = $(this).data('uid'); |
| 2540 | const value = $(this).val(); | 2540 | const value = $(this).val(); |
| 2541 | !skipReset && resetScrollHeight(this); | 2541 | !skipReset && await resetScrollHeight(this); |
| 2542 | data.entries[uid].comment = value; | 2542 | data.entries[uid].comment = value; |
| 2543 | 2543 | ||
| 2544 | setWIOriginalDataValue(data, uid, 'comment', data.entries[uid].comment); | 2544 | setWIOriginalDataValue(data, uid, 'comment', data.entries[uid].comment); |