From b63103b729ff5894f135bd49149786c953a8e4a3 Mon Sep 17 00:00:00 2001 From: ebolam Date: Thu, 20 Apr 2023 13:30:36 -0400 Subject: [PATCH] Text highlighting fix --- static/koboldai.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/static/koboldai.js b/static/koboldai.js index caba2f2b..09dca8e4 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -3060,8 +3060,11 @@ function gametextwatcher(records) { for (const record of records) { if ((record.type === "childList") && (record.removedNodes.length > 0)) { for (const chunk of record.removedNodes) { + //we've deleted a node. Let's find the chunk span and put it back + //Skip over deletes that are not chunks if ((chunk instanceof HTMLElement) && (chunk.hasAttribute("chunk"))) { if (!document.getElementById("Selected Text Chunk " + chunk.getAttribute("chunk"))) { + //Node was actually deleted. Now let's figure out where to put it back (could be in the middle) chunk.innerText = ''; var found = -1 for (let i = parseInt(chunk.getAttribute("chunk"))-1; i > -1; i--) { @@ -3083,6 +3086,12 @@ function gametextwatcher(records) { game_text.append(chunk); } chunk.classList.add("dirty"); + } else { + //For some reason we've deleted a chunk but it still exists in the DOM. Something is wrong here + //Seems to loose the events on the item, but otherwise is OK. DEPLOY HACK!!! + document.getElementById("Selected Text Chunk " + chunk.getAttribute("chunk")).addEventListener("focus", (event) => { + set_edit(event.target); + }); } } }