Fix for editing text before the prompt exists

This commit is contained in:
ebolam
2023-09-07 20:36:48 -04:00
parent 1a58dbf6f5
commit 75bbe3a0fb
2 changed files with 10 additions and 4 deletions

View File

@@ -957,7 +957,6 @@ function var_changed(data) {
if (current_action <= 0) {
//console.log("setting action_count to "+current_action);
const storyPrompt = $el("#story_prompt");
if (storyPrompt) storyPrompt.classList.remove("hidden");
scroll_trigger_element = undefined;
document.getElementById("Selected Text").onscroll = undefined;
}
@@ -3388,6 +3387,10 @@ function gametextwatcher(records) {
if (!dirty_chunks.includes("game_text")) {
dirty_chunks.push("game_text");
}
} else if ((record.target.nodeName == "#text") && (record.target.parentNode == game_text)) {
if (!dirty_chunks.includes("game_text")) {
dirty_chunks.push("game_text");
}
}
}
}
@@ -3427,17 +3430,20 @@ function fix_dirty_game_text() {
} else {
node_text = node.data;
}
if (!(node.nextElementSibling) || !(dirty_chunks.includes(node.nextElementSibling.getAttribute("chunk"))) || dirty_chunks.includes(node.previousElementSibling.getAttribute("chunk"))) {
if ((!(node.nextElementSibling) || !(dirty_chunks.includes(node.nextElementSibling.getAttribute("chunk"))) || dirty_chunks.includes(node.previousElementSibling.getAttribute("chunk"))) && (node.previousElementSibling)) {
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;
if (!dirty_chunks.includes(node.nextElementSibling.getAttribute("chunk"))) {
dirty_chunks.push(node.nextElementSibling.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"))) {
if (node.nextElementSibling && node.previousElementSibling && (node.nextElementSibling.getAttribute("chunk") == node.previousElementSibling.getAttribute("chunk"))) {
node.previousElementSibling.innerText = node.previousElementSibling.innerText + node.nextElementSibling.innerText;
node.nextElementSibling.remove();
}

View File

@@ -54,7 +54,7 @@
</div>
<div class="gametext" id="Selected Text" contenteditable="false" tabindex="0" onkeyup="return set_edit(event);">
<span id="story_prompt" class="var_sync_story_prompt var_sync_alt_story_prompt_in_ai rawtext hidden" chunk="-1"></span></div><!--don't move the /div down or it'll cause odd spacing issues in the UI--->
<span id="story_prompt" class="var_sync_story_prompt var_sync_alt_story_prompt_in_ai rawtext" chunk="-1"></span></div><!--don't move the /div down or it'll cause odd spacing issues in the UI--->
</div>
<!------------ Sequences --------------------->