From 137d056cb3011a16b55c44d840ee2b60a728d4fe Mon Sep 17 00:00:00 2001 From: ebolam Date: Mon, 1 May 2023 10:48:45 -0400 Subject: [PATCH 1/3] Fix for pasting text in the middle of an action --- static/koboldai.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/static/koboldai.js b/static/koboldai.js index 7dfc4a5e..2d62103d 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -3081,6 +3081,7 @@ function gametextwatcher(records) { //Here we want to take care of two possible events //User deleted an action. For this we'll restore the action and set it's text to "" and mark it as dirty //User changes text. For this we simply mark it as dirty + console.log(records); var game_text = document.getElementById("Selected Text"); for (const record of records) { if ((record.type === "childList") && (record.removedNodes.length > 0)) { @@ -3129,7 +3130,7 @@ function gametextwatcher(records) { } } } - //console.log(dirty_chunks); + console.log(dirty_chunks); } function fix_dirty_game_text() { @@ -3165,6 +3166,11 @@ function fix_dirty_game_text() { if (!dirty_chunks.includes(node.previousElementSibling.getAttribute("chunk"))) { dirty_chunks.push(node.previousElementSibling.getAttribute("chunk")); } + //Looks like sometimes it splits the parent. Let's look for that and fix it too + if (node.nextElementSibling && (node.nextElementSibling.getAttribute("chunk") == node.previousElementSibling.getAttribute("chunk"))) { + node.previousElementSibling.innerText = node.previousElementSibling.innerText + node.nextElementSibling.innerText; + node.nextElementSibling.remove(); + } node.remove(); } } From 5a32159e58a205cb5e6ea94f0ce1a0c6029e218d Mon Sep 17 00:00:00 2001 From: ebolam Date: Mon, 1 May 2023 10:53:02 -0400 Subject: [PATCH 2/3] Remove debug prints --- aiserver.py | 2 +- static/koboldai.js | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/aiserver.py b/aiserver.py index 82b14969..d08e21c1 100644 --- a/aiserver.py +++ b/aiserver.py @@ -8671,7 +8671,7 @@ def UI_2_download_story(): @logger.catch def UI_2_Set_Selected_Text(data): if not koboldai_vars.quiet: - print("Updating Selected Text: {}".format(data)) + logger.info("Updating Selected Text: {}".format(data)) action_id = int(data["id"]) if not koboldai_vars.actions.actions[action_id].get("Original Text"): diff --git a/static/koboldai.js b/static/koboldai.js index 2d62103d..7cc7a7e5 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -3081,7 +3081,6 @@ function gametextwatcher(records) { //Here we want to take care of two possible events //User deleted an action. For this we'll restore the action and set it's text to "" and mark it as dirty //User changes text. For this we simply mark it as dirty - console.log(records); var game_text = document.getElementById("Selected Text"); for (const record of records) { if ((record.type === "childList") && (record.removedNodes.length > 0)) { @@ -3130,7 +3129,6 @@ function gametextwatcher(records) { } } } - console.log(dirty_chunks); } function fix_dirty_game_text() { @@ -3155,8 +3153,6 @@ function fix_dirty_game_text() { //Fixing text outside of chunks for (node of game_text.childNodes) { if ((!(node instanceof HTMLElement) || !node.hasAttribute("chunk")) && (node.textContent.trim() != "")) { - console.log("Found Node that needs to be combined"); - console.log(node); //We have a text only node. It should be moved into the previous chunk if (node instanceof HTMLElement) { node.previousElementSibling.innerText = node.previousElementSibling.innerText + node.innerText; From 0c9537e91019516bae1438e1007a6e28c4798353 Mon Sep 17 00:00:00 2001 From: ebolam Date: Wed, 3 May 2023 12:04:05 -0400 Subject: [PATCH 3/3] Potential fix for putting pasted text in wrong action --- static/koboldai.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/static/koboldai.js b/static/koboldai.js index 7cc7a7e5..cfc32d21 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -3153,15 +3153,22 @@ function fix_dirty_game_text() { //Fixing text outside of chunks for (node of game_text.childNodes) { if ((!(node instanceof HTMLElement) || !node.hasAttribute("chunk")) && (node.textContent.trim() != "")) { - //We have a text only node. It should be moved into the previous chunk + //We have a text only node. It should be moved into the previous chunk if it is marked as dirty, next node if not and it's dirty, or the previous if neither is dirty + var node_text = "" if (node instanceof HTMLElement) { - node.previousElementSibling.innerText = node.previousElementSibling.innerText + node.innerText; + node_text = node.innerText; } else { - node.previousElementSibling.innerText = node.previousElementSibling.innerText + node.data; + node_text = node.data; } - if (!dirty_chunks.includes(node.previousElementSibling.getAttribute("chunk"))) { - dirty_chunks.push(node.previousElementSibling.getAttribute("chunk")); + if (!(node.nextElementSibling) || !(dirty_chunks.includes(node.nextElementSibling.getAttribute("chunk"))) || dirty_chunks.includes(node.previousElementSibling.getAttribute("chunk"))) { + node.previousElementSibling.innerText = node.previousElementSibling.innerText + node_text; + if (!dirty_chunks.includes(node.previousElementSibling.getAttribute("chunk"))) { + dirty_chunks.push(node.previousElementSibling.getAttribute("chunk")); + } + } else { + node.nextElementSibling.innerText = node.nextElementSibling.innerText + node_text; } + //Looks like sometimes it splits the parent. Let's look for that and fix it too if (node.nextElementSibling && (node.nextElementSibling.getAttribute("chunk") == node.previousElementSibling.getAttribute("chunk"))) { node.previousElementSibling.innerText = node.previousElementSibling.innerText + node.nextElementSibling.innerText;