New character renaming logic

This commit is contained in:
SillyLossy
2023-04-28 21:38:02 +03:00
parent 5d3a2b70fa
commit 3cfba38ce0
4 changed files with 173 additions and 168 deletions

View File

@@ -11,7 +11,7 @@ import {
api_server_textgenerationwebui,
is_send_press,
getTokenCount,
max_context,
selected_button,
} from "../script.js";
@@ -148,7 +148,7 @@ $("#character_popup").on("input", function () { RA_CountCharTokens(); });
function RA_CountCharTokens() {
$("#result_info").html("");
//console.log('RA_TC -- starting with this_chid = ' + this_chid);
if (document.getElementById('name_div').style.display == "block") { //if new char
if (selected_button === "create") { //if new char
function saveFormVariables() {
create_save_name = $("#character_name_pole").val();
create_save_description = $("#description_textarea").val();

View File

@@ -9,6 +9,8 @@ export {
isElementTagged,
getTagsList,
appendTagToList,
createTagMapFromList,
renameTagKey,
};
const random_id = () => Math.round(Date.now() * Math.random()).toString();
@@ -30,6 +32,19 @@ function loadTagsSettings(settings) {
tag_map = settings.tag_map !== undefined ? settings.tag_map : Object.create(null);
}
function renameTagKey(oldKey, newKey) {
const value = tag_map[oldKey];
tag_map[newKey] = value || [];
delete tag_map[oldKey];
saveSettingsDebounced();
}
function createTagMapFromList(listElement, key) {
const tagIds = [...($(listElement).find(".tag").map((_, el) => $(el).attr("id")))];
tag_map[key] = tagIds;
saveSettingsDebounced();
}
function getTagsList(key) {
if (!Array.isArray(tag_map[key])) {
tag_map[key] = [];