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