From d18f16e3693016e7d306ebb5eaf83dde50cc87c9 Mon Sep 17 00:00:00 2001 From: ebolam Date: Wed, 9 Nov 2022 18:12:40 -0500 Subject: [PATCH] Fix for right click add to world info not working if root folder is missing --- static/koboldai.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/static/koboldai.js b/static/koboldai.js index 4e48f1e5..fa91a8bd 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -1702,6 +1702,13 @@ function world_info_entry(data) { //First let's get the id of the element we're on so we can restore it after removing the object var original_focus = document.activeElement.id; + if (!(document.getElementById("world_info_folder_"+data.folder))) { + folder = document.createElement("div"); + //console.log("Didn't find folder " + data.folder); + } else { + folder = document.getElementById("world_info_folder_"+data.folder); + } + if (document.getElementById("world_info_"+data.uid)) { world_info_card = document.getElementById("world_info_"+data.uid); } else { @@ -1709,6 +1716,7 @@ function world_info_entry(data) { world_info_card = world_info_card_template.cloneNode(true); world_info_card.id = "world_info_"+data.uid; world_info_card.setAttribute("uid", data.uid); + folder.append(world_info_card); } if (data.used_in_game) { world_info_card.classList.add("used_in_game"); @@ -1967,12 +1975,6 @@ function world_info_entry(data) { constant.checked = data.constant; constant.classList.remove("pulse"); - if (!(document.getElementById("world_info_folder_"+data.folder))) { - folder = document.createElement("div"); - //console.log("Didn't find folder " + data.folder); - } else { - folder = document.getElementById("world_info_folder_"+data.folder); - } //Let's figure out the order to insert this card var found = false; var moved = false; @@ -2806,6 +2808,11 @@ function push_selection_to_world_info() { menu.classList.add("open"); } document.getElementById("story_flyout_tab_wi").onclick(); + + if (~("root" in world_info_folder_data)) { + world_info_folder_data["root"] = []; + world_info_folder(world_info_folder_data); + } create_new_wi_entry("root"); document.getElementById("world_info_entry_text_-1").value = getSelectionText(); }