async for resetScrollHeight, slightly faster WI/AF panel loads

64e716bb626e34fa396d7b6346617647e37e2c8d

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

7 files changed, +42 -38Ignore whitespace
public/script.js+7 -5
@@ -6424,7 +6424,7 @@ export async function getSettings() {
64246424 loadHordeSettings(settings);
64256425
64266426 // Load power user settings
64276427 await loadPowerUserSettings(settings, data);
64286428
64296429 // Load character tags
64306430 loadTagsSettings(settings);
@@ -10457,8 +10457,9 @@ jQuery(async function () {
1045710457 }
1045810458
1045910459 // Set the height of "autoSetHeight" textareas within the drawer to their scroll height
1046010460 $(this).closest('.drawer').find('.drawer-content textarea.autoSetHeight').each(async function () {
1046110461 await resetScrollHeight($(this));
10462+ return;
1046210463 });
1046310464
1046410465 } else if (drawerWasOpenAlready) { //to close manually
@@ -10531,8 +10532,9 @@ jQuery(async function () {
1053110532 $(this).closest('.inline-drawer').find('.inline-drawer-content').stop().slideToggle();
1053210533
1053310534 // Set the height of "autoSetHeight" textareas within the inline-drawer to their scroll height
1053410535 $(this).closest('.inline-drawer').find('.inline-drawer-content textarea.autoSetHeight').each(async function () {
1053510536 await resetScrollHeight($(this));
10537+ return;
1053610538 });
1053710539 });
1053810540
public/scripts/extensions/stable-diffusion/index.js+13 -13
@@ -719,29 +719,29 @@ function onChatChanged() {
719719 adjustElementScrollHeight();
720720}
721721
722722async function adjustElementScrollHeight() {
723723 if (!$('.sd_settings').is(':visible')) {
724724 return;
725725 }
726726
727727 await resetScrollHeight($('#sd_prompt_prefix'));
728728 await resetScrollHeight($('#sd_negative_prompt'));
729729 await resetScrollHeight($('#sd_character_prompt'));
730730 await resetScrollHeight($('#sd_character_negative_prompt'));
731731}
732732
733733async function onCharacterPromptInput() {
734734 const key = getCharaFilename(this_chid);
735735 extension_settings.sd.character_prompts[key] = $('#sd_character_prompt').val();
736736 await resetScrollHeight($(this));
737737 saveSettingsDebounced();
738738 writePromptFieldsDebounced(this_chid);
739739}
740740
741741async function onCharacterNegativePromptInput() {
742742 const key = getCharaFilename(this_chid);
743743 extension_settings.sd.character_negative_prompts[key] = $('#sd_character_negative_prompt').val();
744744 await resetScrollHeight($(this));
745745 saveSettingsDebounced();
746746 writePromptFieldsDebounced(this_chid);
747747}
@@ -850,15 +850,15 @@ function onStepsInput() {
850850 saveSettingsDebounced();
851851}
852852
853853async function onPromptPrefixInput() {
854854 extension_settings.sd.prompt_prefix = $('#sd_prompt_prefix').val();
855855 await resetScrollHeight($(this));
856856 saveSettingsDebounced();
857857}
858858
859859async function onNegativePromptInput() {
860860 extension_settings.sd.negative_prompt = $('#sd_negative_prompt').val();
861861 await resetScrollHeight($(this));
862862 saveSettingsDebounced();
863863}
864864
public/scripts/extensions/token-counter/index.js+4 -3
@@ -59,8 +59,8 @@ async function doTokenCounter() {
5959 $('#tokenized_chunks_display').text('—');
6060 }
6161
6262 await resetScrollHeight($('#token_counter_textarea'));
6363 await resetScrollHeight($('#token_counter_ids'));
6464 }, debounce_timeout.relaxed);
6565 dialog.find('#token_counter_textarea').on('input', () => countDebounced());
6666
@@ -134,7 +134,8 @@ jQuery(() => {
134134 </div>`;
135135 $('#token_counter_wand_container').append(buttonHtml);
136136 $('#token_counter').on('click', doTokenCounter);
137137 SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'count',
138+ name: 'count',
138139 callback: async () => String(await doCount()),
139140 returns: 'number of tokens',
140141 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) {
9494 $element.val(power_user.instruct[control.property]);
9595 }
9696
9797 $element.on('input', async function () {
9898 power_user.instruct[control.property] = control.isCheckbox ? !!$(this).prop('checked') : $(this).val();
9999 saveSettingsDebounced();
100100 if (!control.isCheckbox) {
101101 await resetScrollHeight($element);
102102 }
103103 });
104104
public/scripts/power-user.js+5 -5
@@ -1480,7 +1480,7 @@ function getExampleMessagesBehavior() {
14801480 return 'normal';
14811481}
14821482
14831483async function loadPowerUserSettings(settings, data) {
14841484 const defaultStscript = JSON.parse(JSON.stringify(power_user.stscript));
14851485 // Load from settings.json
14861486 if (settings.power_user !== undefined) {
@@ -1740,7 +1740,7 @@ function loadPowerUserSettings(settings, data) {
17401740 switchCompactInputArea();
17411741 reloadMarkdownProcessor(power_user.render_formulas);
17421742 loadInstructMode(data);
17431743 await loadContextSettings();
17441744 loadMaxContextUnlocked();
17451745 switchWaifuMode();
17461746 switchSpoilerMode();
@@ -1872,7 +1872,7 @@ function getContextSettings() {
18721872
18731873// TODO: Maybe add a refresh button to reset settings to preset
18741874// TODO: Add "global state" if a preset doesn't set the power_user checkboxes
18751875async function loadContextSettings() {
18761876 contextControls.forEach(control => {
18771877 const $element = $(`#${control.id}`);
18781878
@@ -1892,7 +1892,7 @@ function loadContextSettings() {
18921892
18931893 // If the setting already exists, no need to duplicate it
18941894 // TODO: Maybe check the power_user object for the setting instead of a flag?
18951895 $element.on('input', async function () {
18961896 const value = control.isCheckbox ? !!$(this).prop('checked') : $(this).val();
18971897 if (control.isGlobalSetting) {
18981898 power_user[control.property] = value;
@@ -1902,7 +1902,7 @@ function loadContextSettings() {
19021902
19031903 saveSettingsDebounced();
19041904 if (!control.isCheckbox) {
19051905 await resetScrollHeight($element);
19061906 }
19071907 });
19081908 });
public/scripts/utils.js+8 -7
@@ -334,12 +334,12 @@ export function debouncedThrottle(func, limit = 300) {
334334 let last, deferTimer;
335335 let db = debounce(func);
336336
337337 return function () {
338338 let now = +new Date, args = arguments;
339339 if (!last || (last && now < last + limit)) {
340340 clearTimeout(deferTimer);
341341 db.apply(this, args);
342342 deferTimer = setTimeout(function () {
343343 last = now;
344344 func.apply(this, args);
345345 }, limit);
@@ -498,8 +498,9 @@ export function restoreCaretPosition(element, position) {
498498}
499499
500500export async function resetScrollHeight(element) {
501+ let scrollHeight = $(element).prop('scrollHeight');
501502 $(element).css('height', '0px');
502503 $(element).css('height', $(element).prop('scrollHeight') + 3 + 'px');
503504}
504505
505506/**
@@ -1936,7 +1937,7 @@ export async function fetchFaFile(name) {
19361937 document.head.append(style);
19371938 const sheet = style.sheet;
19381939 style.remove();
19391940 return [...sheet.cssRules].filter(it => it.style?.content).map(it => it.selectorText.split('::').shift().slice(1));
19401941}
19411942export async function fetchFa() {
19421943 return [...new Set((await Promise.all([
@@ -1961,8 +1962,8 @@ export async function showFontAwesomePicker(customList = null) {
19611962 qry.type = 'search';
19621963 qry.placeholder = 'Filter icons';
19631964 qry.autofocus = true;
19641965 const qryDebounced = debounce(() => {
19651966 const result = faList.filter(it => it.includes(qry.value));
19661967 for (const fa of faList) {
19671968 if (!result.includes(fa)) {
19681969 fas[fa].classList.add('hidden');
public/scripts/world-info.js+3 -3
@@ -2331,7 +2331,7 @@ function getWorldEntry(name, data, entry) {
23312331 /** @type {string[]} */
23322332 const keys = ($(this).select2('data')).map(x => x.text);
23332333
23342334 !skipReset && await resetScrollHeight(this);
23352335 if (!noSave) {
23362336 data.entries[uid][entryPropName] = keys;
23372337 setWIOriginalDataValue(data, uid, originalDataValueName, data.entries[uid][entryPropName]);
@@ -2369,7 +2369,7 @@ function getWorldEntry(name, data, entry) {
23692369 input.on('input', async function (_, { skipReset, noSave } = {}) {
23702370 const uid = $(this).data('uid');
23712371 const value = String($(this).val());
23722372 !skipReset && await resetScrollHeight(this);
23732373 if (!noSave) {
23742374 data.entries[uid][entryPropName] = splitKeywordsAndRegexes(value);
23752375 setWIOriginalDataValue(data, uid, originalDataValueName, data.entries[uid][entryPropName]);
@@ -2538,7 +2538,7 @@ function getWorldEntry(name, data, entry) {
25382538 commentInput.on('input', async function (_, { skipReset } = {}) {
25392539 const uid = $(this).data('uid');
25402540 const value = $(this).val();
25412541 !skipReset && await resetScrollHeight(this);
25422542 data.entries[uid].comment = value;
25432543
25442544 setWIOriginalDataValue(data, uid, 'comment', data.entries[uid].comment);