Only autoexpand the keys of WI

This commit is contained in:
SillyLossy
2023-04-30 23:30:08 +03:00
parent 0e34d73acf
commit e4b16cebd6

View File

@@ -1,5 +1,5 @@
import { saveSettings, callPopup, substituteParams, getTokenCount, getRequestHeaders } from "../script.js"; import { saveSettings, callPopup, substituteParams, getTokenCount, getRequestHeaders } from "../script.js";
import { download, debounce } from "./utils.js"; import { download, debounce, delay } from "./utils.js";
export { export {
world_info, world_info,
@@ -151,11 +151,14 @@ function appendWorldEntry(entry) {
// key // key
const keyInput = template.find('textarea[name="key"]'); const keyInput = template.find('textarea[name="key"]');
keyInput.data("uid", entry.uid); keyInput.data("uid", entry.uid);
keyInput.on("click", function (event) {
// Prevent closing the drawer on clicking the input
event.stopPropagation();
});
keyInput.on("input", function () { keyInput.on("input", function () {
const uid = $(this).data("uid"); const uid = $(this).data("uid");
const value = $(this).val(); const value = $(this).val();
$(this).css("height", ""); //reset the height resetScrollHeight(this);
$(this).css("height", $(this).prop("scrollHeight") + "px");
world_info_data.entries[uid].key = value world_info_data.entries[uid].key = value
.split(",") .split(",")
.map((x) => x.trim()) .map((x) => x.trim())
@@ -163,8 +166,6 @@ function appendWorldEntry(entry) {
saveWorldInfo(); saveWorldInfo();
}); });
keyInput.val(entry.key.join(",")).trigger("input"); keyInput.val(entry.key.join(",")).trigger("input");
keyInput.css("height", ""); //reset the height
keyInput.css("height", $(this).prop("scrollHeight") + "px");
// keysecondary // keysecondary
const keySecondaryInput = template.find('textarea[name="keysecondary"]'); const keySecondaryInput = template.find('textarea[name="keysecondary"]');
@@ -172,8 +173,7 @@ function appendWorldEntry(entry) {
keySecondaryInput.on("input", function () { keySecondaryInput.on("input", function () {
const uid = $(this).data("uid"); const uid = $(this).data("uid");
const value = $(this).val(); const value = $(this).val();
$(this).css("height", ""); //reset the height resetScrollHeight(this);
$(this).css("height", $(this).prop("scrollHeight") + "px");
world_info_data.entries[uid].keysecondary = value world_info_data.entries[uid].keysecondary = value
.split(",") .split(",")
.map((x) => x.trim()) .map((x) => x.trim())
@@ -181,8 +181,6 @@ function appendWorldEntry(entry) {
saveWorldInfo(); saveWorldInfo();
}); });
keySecondaryInput.val(entry.keysecondary.join(",")).trigger("input"); keySecondaryInput.val(entry.keysecondary.join(",")).trigger("input");
keySecondaryInput.css("height", ""); //reset the height
keySecondaryInput.css("height", $(this).prop("scrollHeight") + "px");
// comment // comment
const commentInput = template.find('textarea[name="comment"]'); const commentInput = template.find('textarea[name="comment"]');
@@ -190,14 +188,10 @@ function appendWorldEntry(entry) {
commentInput.on("input", function () { commentInput.on("input", function () {
const uid = $(this).data("uid"); const uid = $(this).data("uid");
const value = $(this).val(); const value = $(this).val();
$(this).css("height", ""); //reset the height
$(this).css("height", $(this).prop("scrollHeight") + "px");
world_info_data.entries[uid].comment = value; world_info_data.entries[uid].comment = value;
saveWorldInfo(); saveWorldInfo();
}); });
commentInput.val(entry.comment).trigger("input"); commentInput.val(entry.comment).trigger("input");
commentInput.css("height", ""); //reset the height
commentInput.css("height", $(this).prop("scrollHeight") + "px");
// content // content
const contentInput = template.find('textarea[name="content"]'); const contentInput = template.find('textarea[name="content"]');
@@ -206,8 +200,6 @@ function appendWorldEntry(entry) {
const uid = $(this).data("uid"); const uid = $(this).data("uid");
const value = $(this).val(); const value = $(this).val();
world_info_data.entries[uid].content = value; world_info_data.entries[uid].content = value;
$(this).css("height", ""); //reset the height
$(this).css("height", $(this).prop("scrollHeight") + "px");
saveWorldInfo(); saveWorldInfo();
// count tokens // count tokens
@@ -218,8 +210,6 @@ function appendWorldEntry(entry) {
.html(numberOfTokens); .html(numberOfTokens);
}); });
contentInput.val(entry.content).trigger("input"); contentInput.val(entry.content).trigger("input");
contentInput.css("height", ""); //reset the height
contentInput.css("height", $(this).prop("scrollHeight") + "px");
// selective // selective
const selectiveInput = template.find('input[name="selective"]'); const selectiveInput = template.find('input[name="selective"]');
@@ -285,7 +275,7 @@ function appendWorldEntry(entry) {
.trigger("input"); .trigger("input");
// display uid // display uid
template.find(".world_entry_form_uid_value").html(entry.uid); template.find(".world_entry_form_uid_value").text(entry.uid);
// delete button // delete button
const deleteButton = template.find("input.delete_entry_button"); const deleteButton = template.find("input.delete_entry_button");
@@ -301,6 +291,13 @@ function appendWorldEntry(entry) {
return template; return template;
} }
async function resetScrollHeight(element) {
await delay(1);
const height = Number($(element).prop("scrollHeight")) + 1;
$(element).css("height", "");
$(element).css("height", `${height}px`);
}
async function deleteWorldInfoEntry(uid) { async function deleteWorldInfoEntry(uid) {
if (!world_info_data || !("entries" in world_info_data)) { if (!world_info_data || !("entries" in world_info_data)) {
return; return;