mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
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:
@@ -2991,8 +2991,11 @@ function toggle_adventure_mode(button) {
|
||||
}
|
||||
|
||||
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 anchorNode = window.getSelection().anchorNode;
|
||||
let new_selected_game_chunk = null;
|
||||
|
||||
if (document.selection) {
|
||||
if (document.selection.createRange().parentElement().id == 'story_prompt') {
|
||||
new_selected_game_chunk = document.selection.createRange().parentElement();
|
||||
@@ -3002,20 +3005,26 @@ function select_game_text(event) {
|
||||
} else {
|
||||
new_selected_game_chunk = document.selection.createRange().parentElement().parentElement();
|
||||
}
|
||||
} else if (window.getSelection().anchorNode != null ) {
|
||||
if(window.getSelection().anchorNode.parentNode) {
|
||||
if (window.getSelection().anchorNode.parentNode.id == 'story_prompt') {
|
||||
new_selected_game_chunk = window.getSelection().anchorNode.parentNode;
|
||||
} else if (window.getSelection().anchorNode.parentNode.id == "gamescreen") {
|
||||
} 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;
|
||||
//console.log("Do nothing");
|
||||
} else {
|
||||
new_selected_game_chunk = window.getSelection().anchorNode.parentNode.parentNode;
|
||||
new_selected_game_chunk = anchorNode.parentNode.parentNode;
|
||||
}
|
||||
} else {
|
||||
new_selected_game_chunk = null;
|
||||
}
|
||||
}
|
||||
|
||||
//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"))) {
|
||||
@@ -3052,7 +3061,6 @@ function select_game_text(event) {
|
||||
window.getSelection().removeAllRanges()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function edit_game_text(id) {
|
||||
update_game_text(id)
|
||||
|
Reference in New Issue
Block a user