Bug Fix for text highlighting and deleting old code

This commit is contained in:
ebolam
2023-04-21 08:13:25 -04:00
parent b63103b729
commit dd79a54904
2 changed files with 24 additions and 12 deletions

View File

@@ -566,9 +566,9 @@ function do_story_text_updates(action) {
item.classList.add("rawtext");
item.setAttribute("chunk", action.id);
item.setAttribute("tabindex", parseInt(action.id)+1);
item.addEventListener("focus", (event) => {
set_edit(event.target);
});
//item.addEventListener("focus", (event) => {
// set_edit(event.target);
//});
//need to find the closest element
closest_element = document.getElementById("story_prompt");
@@ -3044,11 +3044,23 @@ function toggle_adventure_mode(button) {
}
function set_edit(element) {
function set_edit(event) {
//get the element sitting on
var game_text = document.getElementById("Selected Text");
if ((event.key === undefined) || (event.key == 'ArrowDown') || (event.key == 'ArrowUp') || (event.key == 'ArrowLeft') || (event.key == 'ArrowRight')) {
var chunk = window.getSelection().anchorNode;
while (chunk != game_text) {
if ((chunk instanceof HTMLElement) && (chunk.hasAttribute("chunk"))) {
break;
}
chunk = chunk.parentNode;
}
for (item of document.getElementsByClassName("editing")) {
item.classList.remove("editing");
}
element.classList.add("editing");
chunk.classList.add("editing");
}
return true;
}
function gametextwatcher(records) {
@@ -3089,9 +3101,9 @@ function gametextwatcher(records) {
} 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);
});
//document.getElementById("Selected Text Chunk " + chunk.getAttribute("chunk")).addEventListener("focus", (event) => {
// set_edit(event.target);
//});
}
}
}

View File

@@ -53,8 +53,8 @@
<div id="welcome_text" class="var_sync_model_welcome" draggable="False"></div>
</div>
<div class="gametext" id="Selected Text" contenteditable=false tabindex=0 onfocusout="savegametextchanges();">
<span id="story_prompt" class="var_sync_story_prompt var_sync_alt_story_prompt_in_ai rawtext hidden" tabindex=0 chunk="-1" onfocus="set_edit(this);"></span></div><!--don't move the /div down or it'll cause odd spacing issues in the UI--->
<div class="gametext" id="Selected Text" contenteditable=false tabindex=0 onfocusout="savegametextchanges();" onclick="return set_edit(event)" 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--->
</div>
<!------------ Sequences --------------------->