async for resetScrollHeight, slightly faster WI/AF panel loads

64e716bb626e34fa396d7b6346617647e37e2c8d

RossAscends <124905043+RossAscends@users.noreply.github.com>

7 files changed, +36 -32Showing whitespace changes
public/script.js+7 -5
@@ -6424,7 +6424,7 @@ export async function getSettings() {
6424 loadHordeSettings(settings);6424 loadHordeSettings(settings);
64256425
6426 // Load power user settings6426 // Load power user settings
6427 loadPowerUserSettings(settings, data);6427 await loadPowerUserSettings(settings, data);
64286428
6429 // Load character tags6429 // Load character tags
6430 loadTagsSettings(settings);6430 loadTagsSettings(settings);
@@ -10457,8 +10457,9 @@ jQuery(async function () {
10457 }10457 }
1045810458
10459 // Set the height of "autoSetHeight" textareas within the drawer to their scroll height10459 // 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 });
1046310464
10464 } else if (drawerWasOpenAlready) { //to close manually10465 } 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();
1053210533
10533 // Set the height of "autoSetHeight" textareas within the inline-drawer to their scroll height10534 // 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 });
1053810540
public/scripts/extensions/stable-diffusion/index.js+13 -13
@@ -719,29 +719,29 @@ function onChatChanged() {
719 adjustElementScrollHeight();719 adjustElementScrollHeight();
720}720}
721721
722function adjustElementScrollHeight() {722async function adjustElementScrollHeight() {
723 if (!$('.sd_settings').is(':visible')) {723 if (!$('.sd_settings').is(':visible')) {
724 return;724 return;
725 }725 }
726726
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}
732732
733function onCharacterPromptInput() {733async 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}
740740
741function onCharacterNegativePromptInput() {741async 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}
852852
853function onPromptPrefixInput() {853async 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}
858858
859function onNegativePromptInput() {859async 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}
864864
public/scripts/extensions/token-counter/index.js+4 -3
@@ -59,8 +59,8 @@ async function doTokenCounter() {
59 $('#tokenized_chunks_display').text('—');59 $('#tokenized_chunks_display').text('—');
60 }60 }
6161
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());
6666
@@ -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.',
public/scripts/instruct-mode.js+2 -2
@@ -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 }
9696
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 });
104104
public/scripts/power-user.js+5 -5
@@ -1480,7 +1480,7 @@ function getExampleMessagesBehavior() {
1480 return 'normal';1480 return 'normal';
1481}1481}
14821482
1483function loadPowerUserSettings(settings, data) {1483async 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.json1485 // 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() {
18721872
1873// TODO: Maybe add a refresh button to reset settings to preset1873// 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 checkboxes1874// TODO: Add "global state" if a preset doesn't set the power_user checkboxes
1875function loadContextSettings() {1875async function loadContextSettings() {
1876 contextControls.forEach(control => {1876 contextControls.forEach(control => {
1877 const $element = $(`#${control.id}`);1877 const $element = $(`#${control.id}`);
18781878
@@ -1892,7 +1892,7 @@ function loadContextSettings() {
18921892
1893 // If the setting already exists, no need to duplicate it1893 // 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() {
19021902
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 });
public/scripts/utils.js+2 -1
@@ -498,8 +498,9 @@ export function restoreCaretPosition(element, position) {
498}498}
499499
500export async function resetScrollHeight(element) {500export 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}
504505
505/**506/**
public/scripts/world-info.js+3 -3
@@ -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);
23332333
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;
25432543
2544 setWIOriginalDataValue(data, uid, 'comment', data.entries[uid].comment);2544 setWIOriginalDataValue(data, uid, 'comment', data.entries[uid].comment);