mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
async for resetScrollHeight, slightly faster WI/AF panel loads
This commit is contained in:
@ -6424,7 +6424,7 @@ export async function getSettings() {
|
||||
loadHordeSettings(settings);
|
||||
|
||||
// Load power user settings
|
||||
loadPowerUserSettings(settings, data);
|
||||
await loadPowerUserSettings(settings, data);
|
||||
|
||||
// Load character tags
|
||||
loadTagsSettings(settings);
|
||||
@ -10457,8 +10457,9 @@ jQuery(async function () {
|
||||
}
|
||||
|
||||
// Set the height of "autoSetHeight" textareas within the drawer to their scroll height
|
||||
$(this).closest('.drawer').find('.drawer-content textarea.autoSetHeight').each(function () {
|
||||
resetScrollHeight($(this));
|
||||
$(this).closest('.drawer').find('.drawer-content textarea.autoSetHeight').each(async function () {
|
||||
await resetScrollHeight($(this));
|
||||
return;
|
||||
});
|
||||
|
||||
} else if (drawerWasOpenAlready) { //to close manually
|
||||
@ -10531,8 +10532,9 @@ jQuery(async function () {
|
||||
$(this).closest('.inline-drawer').find('.inline-drawer-content').stop().slideToggle();
|
||||
|
||||
// Set the height of "autoSetHeight" textareas within the inline-drawer to their scroll height
|
||||
$(this).closest('.inline-drawer').find('.inline-drawer-content textarea.autoSetHeight').each(function () {
|
||||
resetScrollHeight($(this));
|
||||
$(this).closest('.inline-drawer').find('.inline-drawer-content textarea.autoSetHeight').each(async function () {
|
||||
await resetScrollHeight($(this));
|
||||
return;
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -719,29 +719,29 @@ function onChatChanged() {
|
||||
adjustElementScrollHeight();
|
||||
}
|
||||
|
||||
function adjustElementScrollHeight() {
|
||||
async function adjustElementScrollHeight() {
|
||||
if (!$('.sd_settings').is(':visible')) {
|
||||
return;
|
||||
}
|
||||
|
||||
resetScrollHeight($('#sd_prompt_prefix'));
|
||||
resetScrollHeight($('#sd_negative_prompt'));
|
||||
resetScrollHeight($('#sd_character_prompt'));
|
||||
resetScrollHeight($('#sd_character_negative_prompt'));
|
||||
await resetScrollHeight($('#sd_prompt_prefix'));
|
||||
await resetScrollHeight($('#sd_negative_prompt'));
|
||||
await resetScrollHeight($('#sd_character_prompt'));
|
||||
await resetScrollHeight($('#sd_character_negative_prompt'));
|
||||
}
|
||||
|
||||
function onCharacterPromptInput() {
|
||||
async function onCharacterPromptInput() {
|
||||
const key = getCharaFilename(this_chid);
|
||||
extension_settings.sd.character_prompts[key] = $('#sd_character_prompt').val();
|
||||
resetScrollHeight($(this));
|
||||
await resetScrollHeight($(this));
|
||||
saveSettingsDebounced();
|
||||
writePromptFieldsDebounced(this_chid);
|
||||
}
|
||||
|
||||
function onCharacterNegativePromptInput() {
|
||||
async function onCharacterNegativePromptInput() {
|
||||
const key = getCharaFilename(this_chid);
|
||||
extension_settings.sd.character_negative_prompts[key] = $('#sd_character_negative_prompt').val();
|
||||
resetScrollHeight($(this));
|
||||
await resetScrollHeight($(this));
|
||||
saveSettingsDebounced();
|
||||
writePromptFieldsDebounced(this_chid);
|
||||
}
|
||||
@ -850,15 +850,15 @@ function onStepsInput() {
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
function onPromptPrefixInput() {
|
||||
async function onPromptPrefixInput() {
|
||||
extension_settings.sd.prompt_prefix = $('#sd_prompt_prefix').val();
|
||||
resetScrollHeight($(this));
|
||||
await resetScrollHeight($(this));
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
function onNegativePromptInput() {
|
||||
async function onNegativePromptInput() {
|
||||
extension_settings.sd.negative_prompt = $('#sd_negative_prompt').val();
|
||||
resetScrollHeight($(this));
|
||||
await resetScrollHeight($(this));
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,8 @@ async function doTokenCounter() {
|
||||
$('#tokenized_chunks_display').text('—');
|
||||
}
|
||||
|
||||
resetScrollHeight($('#token_counter_textarea'));
|
||||
resetScrollHeight($('#token_counter_ids'));
|
||||
await resetScrollHeight($('#token_counter_textarea'));
|
||||
await resetScrollHeight($('#token_counter_ids'));
|
||||
}, debounce_timeout.relaxed);
|
||||
dialog.find('#token_counter_textarea').on('input', () => countDebounced());
|
||||
|
||||
@ -134,7 +134,8 @@ jQuery(() => {
|
||||
</div>`;
|
||||
$('#token_counter_wand_container').append(buttonHtml);
|
||||
$('#token_counter').on('click', doTokenCounter);
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'count',
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'count',
|
||||
callback: async () => String(await doCount()),
|
||||
returns: 'number of tokens',
|
||||
helpString: 'Counts the number of tokens in the current chat.',
|
||||
|
@ -94,11 +94,11 @@ export function loadInstructMode(data) {
|
||||
$element.val(power_user.instruct[control.property]);
|
||||
}
|
||||
|
||||
$element.on('input', function () {
|
||||
$element.on('input', async function () {
|
||||
power_user.instruct[control.property] = control.isCheckbox ? !!$(this).prop('checked') : $(this).val();
|
||||
saveSettingsDebounced();
|
||||
if (!control.isCheckbox) {
|
||||
resetScrollHeight($element);
|
||||
await resetScrollHeight($element);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1480,7 +1480,7 @@ function getExampleMessagesBehavior() {
|
||||
return 'normal';
|
||||
}
|
||||
|
||||
function loadPowerUserSettings(settings, data) {
|
||||
async function loadPowerUserSettings(settings, data) {
|
||||
const defaultStscript = JSON.parse(JSON.stringify(power_user.stscript));
|
||||
// Load from settings.json
|
||||
if (settings.power_user !== undefined) {
|
||||
@ -1740,7 +1740,7 @@ function loadPowerUserSettings(settings, data) {
|
||||
switchCompactInputArea();
|
||||
reloadMarkdownProcessor(power_user.render_formulas);
|
||||
loadInstructMode(data);
|
||||
loadContextSettings();
|
||||
await loadContextSettings();
|
||||
loadMaxContextUnlocked();
|
||||
switchWaifuMode();
|
||||
switchSpoilerMode();
|
||||
@ -1872,7 +1872,7 @@ function getContextSettings() {
|
||||
|
||||
// TODO: Maybe add a refresh button to reset settings to preset
|
||||
// TODO: Add "global state" if a preset doesn't set the power_user checkboxes
|
||||
function loadContextSettings() {
|
||||
async function loadContextSettings() {
|
||||
contextControls.forEach(control => {
|
||||
const $element = $(`#${control.id}`);
|
||||
|
||||
@ -1892,7 +1892,7 @@ function loadContextSettings() {
|
||||
|
||||
// If the setting already exists, no need to duplicate it
|
||||
// TODO: Maybe check the power_user object for the setting instead of a flag?
|
||||
$element.on('input', function () {
|
||||
$element.on('input', async function () {
|
||||
const value = control.isCheckbox ? !!$(this).prop('checked') : $(this).val();
|
||||
if (control.isGlobalSetting) {
|
||||
power_user[control.property] = value;
|
||||
@ -1902,7 +1902,7 @@ function loadContextSettings() {
|
||||
|
||||
saveSettingsDebounced();
|
||||
if (!control.isCheckbox) {
|
||||
resetScrollHeight($element);
|
||||
await resetScrollHeight($element);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -334,12 +334,12 @@ export function debouncedThrottle(func, limit = 300) {
|
||||
let last, deferTimer;
|
||||
let db = debounce(func);
|
||||
|
||||
return function() {
|
||||
return function () {
|
||||
let now = +new Date, args = arguments;
|
||||
if(!last || (last && now < last + limit)) {
|
||||
if (!last || (last && now < last + limit)) {
|
||||
clearTimeout(deferTimer);
|
||||
db.apply(this, args);
|
||||
deferTimer = setTimeout(function() {
|
||||
deferTimer = setTimeout(function () {
|
||||
last = now;
|
||||
func.apply(this, args);
|
||||
}, limit);
|
||||
@ -498,8 +498,9 @@ export function restoreCaretPosition(element, position) {
|
||||
}
|
||||
|
||||
export async function resetScrollHeight(element) {
|
||||
let scrollHeight = $(element).prop('scrollHeight');
|
||||
$(element).css('height', '0px');
|
||||
$(element).css('height', $(element).prop('scrollHeight') + 3 + 'px');
|
||||
$(element).css('height', scrollHeight + 3 + 'px');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1936,7 +1937,7 @@ export async function fetchFaFile(name) {
|
||||
document.head.append(style);
|
||||
const sheet = style.sheet;
|
||||
style.remove();
|
||||
return [...sheet.cssRules].filter(it=>it.style?.content).map(it=>it.selectorText.split('::').shift().slice(1));
|
||||
return [...sheet.cssRules].filter(it => it.style?.content).map(it => it.selectorText.split('::').shift().slice(1));
|
||||
}
|
||||
export async function fetchFa() {
|
||||
return [...new Set((await Promise.all([
|
||||
@ -1961,8 +1962,8 @@ export async function showFontAwesomePicker(customList = null) {
|
||||
qry.type = 'search';
|
||||
qry.placeholder = 'Filter icons';
|
||||
qry.autofocus = true;
|
||||
const qryDebounced = debounce(()=>{
|
||||
const result = faList.filter(it=>it.includes(qry.value));
|
||||
const qryDebounced = debounce(() => {
|
||||
const result = faList.filter(it => it.includes(qry.value));
|
||||
for (const fa of faList) {
|
||||
if (!result.includes(fa)) {
|
||||
fas[fa].classList.add('hidden');
|
||||
|
@ -2331,7 +2331,7 @@ function getWorldEntry(name, data, entry) {
|
||||
/** @type {string[]} */
|
||||
const keys = ($(this).select2('data')).map(x => x.text);
|
||||
|
||||
!skipReset && resetScrollHeight(this);
|
||||
!skipReset && await resetScrollHeight(this);
|
||||
if (!noSave) {
|
||||
data.entries[uid][entryPropName] = keys;
|
||||
setWIOriginalDataValue(data, uid, originalDataValueName, data.entries[uid][entryPropName]);
|
||||
@ -2369,7 +2369,7 @@ function getWorldEntry(name, data, entry) {
|
||||
input.on('input', async function (_, { skipReset, noSave } = {}) {
|
||||
const uid = $(this).data('uid');
|
||||
const value = String($(this).val());
|
||||
!skipReset && resetScrollHeight(this);
|
||||
!skipReset && await resetScrollHeight(this);
|
||||
if (!noSave) {
|
||||
data.entries[uid][entryPropName] = splitKeywordsAndRegexes(value);
|
||||
setWIOriginalDataValue(data, uid, originalDataValueName, data.entries[uid][entryPropName]);
|
||||
@ -2538,7 +2538,7 @@ function getWorldEntry(name, data, entry) {
|
||||
commentInput.on('input', async function (_, { skipReset } = {}) {
|
||||
const uid = $(this).data('uid');
|
||||
const value = $(this).val();
|
||||
!skipReset && resetScrollHeight(this);
|
||||
!skipReset && await resetScrollHeight(this);
|
||||
data.entries[uid].comment = value;
|
||||
|
||||
setWIOriginalDataValue(data, uid, 'comment', data.entries[uid].comment);
|
||||
|
Reference in New Issue
Block a user