Fix selection after line bugging out

And push big check encapsulating all of select_game_text to the
beginning to be a bit neater
This commit is contained in:
somebody
2022-12-26 17:05:15 -06:00
parent 092c31b0eb
commit 46438b96c3

View File

@@ -2991,66 +2991,74 @@ function toggle_adventure_mode(button) {
} }
function select_game_text(event) { function select_game_text(event) {
if ((event == null) || (event.code == 'ArrowRight') || (event.code == 'ArrowLeft') || (event.code == 'ArrowDown') || (event.code == 'ArrowUp')) { if (!((event === null) || ["ArrowRight", "ArrowLeft", "ArrowDown", "ArrowUp"].includes(event.code))) return;
let new_selected_game_chunk = null;
if (document.selection) { let anchorNode = window.getSelection().anchorNode;
if (document.selection.createRange().parentElement().id == 'story_prompt') { let new_selected_game_chunk = null;
new_selected_game_chunk = document.selection.createRange().parentElement();
} else if (document.selection.createRange().parentElement().id == 'gamescreen') { if (document.selection) {
if (document.selection.createRange().parentElement().id == 'story_prompt') {
new_selected_game_chunk = document.selection.createRange().parentElement();
} else if (document.selection.createRange().parentElement().id == 'gamescreen') {
new_selected_game_chunk = null;
//console.log("Do nothing");
} else {
new_selected_game_chunk = document.selection.createRange().parentElement().parentElement();
}
} else if (anchorNode != null && anchorNode.tagName === "SPAN") {
// If clicking to the right of an action, the event target is actually
// the whole of gametext, and the anchorNode is a child span of an
// action rather than a text node.
new_selected_game_chunk = anchorNode.parentNode;
} else if (anchorNode != null ) {
if(anchorNode.parentNode) {
if (anchorNode.parentNode.id == 'story_prompt') {
new_selected_game_chunk = anchorNode.parentNode;
} else if (anchorNode.parentNode.id == "gamescreen") {
new_selected_game_chunk = null; new_selected_game_chunk = null;
//console.log("Do nothing"); //console.log("Do nothing");
} else { } else {
new_selected_game_chunk = document.selection.createRange().parentElement().parentElement(); new_selected_game_chunk = anchorNode.parentNode.parentNode;
} }
} else if (window.getSelection().anchorNode != null ) { } else {
if(window.getSelection().anchorNode.parentNode) { new_selected_game_chunk = null;
if (window.getSelection().anchorNode.parentNode.id == 'story_prompt') { }
new_selected_game_chunk = window.getSelection().anchorNode.parentNode; }
} else if (window.getSelection().anchorNode.parentNode.id == "gamescreen") {
new_selected_game_chunk = null; //if we've moved to a new game chunk we need to save the old chunk
//console.log("Do nothing"); if (((new_selected_game_chunk != selected_game_chunk) && (selected_game_chunk != null)) || (document.activeElement != document.getElementById("Selected Text"))) {
} else { if ((selected_game_chunk != null) && (selected_game_chunk.innerText != selected_game_chunk.original_text) && (selected_game_chunk != document.getElementById("welcome_text"))) {
new_selected_game_chunk = window.getSelection().anchorNode.parentNode.parentNode; if (selected_game_chunk.id == 'story_prompt') {
} edit_game_text(-1);
} else { } else {
new_selected_game_chunk = null; edit_game_text(parseInt(selected_game_chunk.getAttribute("chunk")));
} }
} }
//if we've moved to a new game chunk we need to save the old chunk }
if (((new_selected_game_chunk != selected_game_chunk) && (selected_game_chunk != null)) || (document.activeElement != document.getElementById("Selected Text"))) {
if ((selected_game_chunk != null) && (selected_game_chunk.innerText != selected_game_chunk.original_text) && (selected_game_chunk != document.getElementById("welcome_text"))) { //Check to see if new selection is a game chunk or something else
if (selected_game_chunk.id == 'story_prompt') { if (new_selected_game_chunk == null) {
edit_game_text(-1); selected_game_chunk = null;
} else { for (item of document.getElementsByClassName("editing")) {
edit_game_text(parseInt(selected_game_chunk.getAttribute("chunk"))); item.classList.remove("editing");
} }
window.getSelection().removeAllRanges()
} else if (((new_selected_game_chunk.id == "story_prompt") || (new_selected_game_chunk.id.slice(0,20) == "Selected Text Chunk ")) && (document.activeElement.isContentEditable)) {
if (new_selected_game_chunk != selected_game_chunk) {
for (item of document.getElementsByClassName("editing")) {
item.classList.remove("editing");
} }
selected_game_chunk = new_selected_game_chunk;
selected_game_chunk.classList.add("editing");
update_story_picture(selected_game_chunk.getAttribute("chunk"));
} }
//Check to see if new selection is a game chunk or something else } else {
if (new_selected_game_chunk == null) { selected_game_chunk = null;
selected_game_chunk = null; for (item of document.getElementsByClassName("editing")) {
for (item of document.getElementsByClassName("editing")) { item.classList.remove("editing");
item.classList.remove("editing");
}
window.getSelection().removeAllRanges()
} else if (((new_selected_game_chunk.id == "story_prompt") || (new_selected_game_chunk.id.slice(0,20) == "Selected Text Chunk ")) && (document.activeElement.isContentEditable)) {
if (new_selected_game_chunk != selected_game_chunk) {
for (item of document.getElementsByClassName("editing")) {
item.classList.remove("editing");
}
selected_game_chunk = new_selected_game_chunk;
selected_game_chunk.classList.add("editing");
update_story_picture(selected_game_chunk.getAttribute("chunk"));
}
} else {
selected_game_chunk = null;
for (item of document.getElementsByClassName("editing")) {
item.classList.remove("editing");
}
window.getSelection().removeAllRanges()
} }
window.getSelection().removeAllRanges()
} }
} }