Implement more smart textarea autosizes

This commit is contained in:
Cohee
2024-09-05 20:55:06 +03:00
parent 758c90be00
commit 2f5e40691c
6 changed files with 38 additions and 22 deletions

View File

@ -724,7 +724,7 @@ function onChatChanged() {
}
async function adjustElementScrollHeight() {
if (!$('.sd_settings').is(':visible')) {
if (CSS.supports('field-sizing', 'content') || !$('.sd_settings').is(':visible')) {
return;
}
@ -737,17 +737,19 @@ async function adjustElementScrollHeight() {
async function onCharacterPromptInput() {
const key = getCharaFilename(this_chid);
extension_settings.sd.character_prompts[key] = $('#sd_character_prompt').val();
await resetScrollHeight($(this));
saveSettingsDebounced();
writePromptFieldsDebounced(this_chid);
if (CSS.supports('field-sizing', 'content')) return;
await resetScrollHeight($(this));
}
async function onCharacterNegativePromptInput() {
const key = getCharaFilename(this_chid);
extension_settings.sd.character_negative_prompts[key] = $('#sd_character_negative_prompt').val();
await resetScrollHeight($(this));
saveSettingsDebounced();
writePromptFieldsDebounced(this_chid);
if (CSS.supports('field-sizing', 'content')) return;
await resetScrollHeight($(this));
}
function getCharacterPrefix() {
@ -856,14 +858,16 @@ function onStepsInput() {
async function onPromptPrefixInput() {
extension_settings.sd.prompt_prefix = $('#sd_prompt_prefix').val();
await resetScrollHeight($(this));
saveSettingsDebounced();
if (CSS.supports('field-sizing', 'content')) return;
await resetScrollHeight($(this));
}
async function onNegativePromptInput() {
extension_settings.sd.negative_prompt = $('#sd_negative_prompt').val();
await resetScrollHeight($(this));
saveSettingsDebounced();
if (CSS.supports('field-sizing', 'content')) return;
await resetScrollHeight($(this));
}
function onSamplerChange() {
@ -3911,12 +3915,14 @@ jQuery(async () => {
$('#sd_stability_style_preset').on('change', onStabilityStylePresetChange);
$('#sd_huggingface_model_id').on('input', onHFModelInput);
$('.sd_settings .inline-drawer-toggle').on('click', function () {
initScrollHeight($('#sd_prompt_prefix'));
initScrollHeight($('#sd_negative_prompt'));
initScrollHeight($('#sd_character_prompt'));
initScrollHeight($('#sd_character_negative_prompt'));
});
if (!CSS.supports('field-sizing', 'content')) {
$('.sd_settings .inline-drawer-toggle').on('click', function () {
initScrollHeight($('#sd_prompt_prefix'));
initScrollHeight($('#sd_negative_prompt'));
initScrollHeight($('#sd_character_prompt'));
initScrollHeight($('#sd_character_negative_prompt'));
});
}
for (const [key, value] of Object.entries(resolutionOptions)) {
const option = document.createElement('option');

View File

@ -408,16 +408,16 @@
</div>
</div>
<label for="sd_prompt_prefix" data-i18n="Common prompt prefix">Common prompt prefix</label>
<textarea id="sd_prompt_prefix" class="text_pole textarea_compact" data-i18n="[placeholder]sd_prompt_prefix_placeholder" placeholder="Use {prompt} to specify where the generated prompt will be inserted"></textarea>
<textarea id="sd_prompt_prefix" class="text_pole textarea_compact autoSetHeight" data-i18n="[placeholder]sd_prompt_prefix_placeholder" placeholder="Use {prompt} to specify where the generated prompt will be inserted"></textarea>
<label for="sd_negative_prompt" data-i18n="Negative common prompt prefix">Negative common prompt prefix</label>
<textarea id="sd_negative_prompt" class="text_pole textarea_compact"></textarea>
<textarea id="sd_negative_prompt" class="text_pole textarea_compact autoSetHeight"></textarea>
<div id="sd_character_prompt_block">
<label for="sd_character_prompt" data-i18n="Character-specific prompt prefix">Character-specific prompt prefix</label>
<small data-i18n="Won't be used in groups.">Won't be used in groups.</small>
<textarea id="sd_character_prompt" class="text_pole textarea_compact" data-i18n="[placeholder]sd_character_prompt_placeholder" placeholder="Any characteristics that describe the currently selected character. Will be added after a common prompt prefix.&#10;Example: female, green eyes, brown hair, pink shirt"></textarea>
<textarea id="sd_character_prompt" class="text_pole textarea_compact autoSetHeight" data-i18n="[placeholder]sd_character_prompt_placeholder" placeholder="Any characteristics that describe the currently selected character. Will be added after a common prompt prefix.&#10;Example: female, green eyes, brown hair, pink shirt"></textarea>
<label for="sd_character_negative_prompt" data-i18n="Character-specific negative prompt prefix">Character-specific negative prompt prefix</label>
<small data-i18n="Won't be used in groups.">Won't be used in groups.</small>
<textarea id="sd_character_negative_prompt" class="text_pole textarea_compact" data-i18n="[placeholder]sd_character_negative_prompt_placeholder" placeholder="Any characteristics that should not appear for the selected character. Will be added after a negative common prompt prefix.&#10;Example: jewellery, shoes, glasses"></textarea>
<textarea id="sd_character_negative_prompt" class="text_pole textarea_compact autoSetHeight" data-i18n="[placeholder]sd_character_negative_prompt_placeholder" placeholder="Any characteristics that should not appear for the selected character. Will be added after a negative common prompt prefix.&#10;Example: jewellery, shoes, glasses"></textarea>
<label for="sd_character_prompt_share" class="checkbox_label flexWrap marginTop5">
<input id="sd_character_prompt_share" type="checkbox" />
<span data-i18n="Shareable">