From 4beb1a4b334a272d59a83a8c1654ec09b2f6f834 Mon Sep 17 00:00:00 2001 From: somebody Date: Fri, 16 Dec 2022 21:49:52 -0600 Subject: [PATCH 1/3] Standardize linebreak behavior --- static/koboldai.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/static/koboldai.js b/static/koboldai.js index 748e0f95..25220c64 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -6991,4 +6991,12 @@ function showGeneratedWIData(data) { world_info_data[data.uid].manual_text = data.out; send_world_info(data.uid); } -} \ No newline at end of file +} + +$el(".gametext").addEventListener("keydown", function(event) { + if (event.key !== "Enter") return; + // execCommand is deprecated but until Firefox supports + // contentEditable="plaintext-only" we're just gonna have to roll with it + document.execCommand("insertLineBreak"); + event.preventDefault(); +}); \ No newline at end of file From d77e8e34c9d8d887308fd9f0534b4f235a0f8947 Mon Sep 17 00:00:00 2001 From: somebody Date: Fri, 16 Dec 2022 22:17:18 -0600 Subject: [PATCH 2/3] Almost have newlines working no save yet!!!!!!!!!!!!!!!!!!!!!!!!!1 --- static/koboldai.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/static/koboldai.js b/static/koboldai.js index 25220c64..d60d8bbc 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -570,7 +570,7 @@ function do_story_text_updates(action) { if ('wi_highlighted_text' in action.action) { for (chunk of action.action['wi_highlighted_text']) { chunk_element = document.createElement("span"); - chunk_element.textContent = chunk['text']; + chunk_element.innerText = chunk['text']; if (chunk['WI matches'] != null) { chunk_element.classList.add("wi_match"); chunk_element.setAttribute("tooltip", chunk['WI Text']); @@ -580,7 +580,7 @@ function do_story_text_updates(action) { } } else { chunk_element = document.createElement("span"); - chunk_element.textContent = action.action['Selected Text']; + chunk_element.innerText = action.action['Selected Text']; item.append(chunk_element); } item.original_text = action.action['Selected Text']; @@ -613,7 +613,7 @@ function do_prompt(data) { } for (chunk of data.value) { chunk_element = document.createElement("span"); - chunk_element.textContent = chunk['text']; + chunk_element.innerText = chunk['text']; if (chunk['WI matches'] != null) { chunk_element.classList.add("wi_match"); chunk_element.setAttribute("tooltip", chunk['WI Text']); @@ -2874,7 +2874,7 @@ function sync_to_server(item) { if (item.classList.contains("sync_as_float")) value = parseFloat(value); } } else { - value = item.textContent; + value = item.innerText; } //get name @@ -3078,14 +3078,14 @@ function update_game_text(id) { let new_text = "" if (id == -1) { temp = document.getElementById("story_prompt"); - new_text = temp.textContent; + new_text = temp.innerText; sync_to_server(temp); temp.original_text = new_text; temp.classList.add("pulse"); } else { temp = document.getElementById("Selected Text Chunk " + id); if (temp) { - new_text = temp.textContent; + new_text = temp.innerText; socket.emit("Set Selected Text", {"id": id, "text": new_text}); temp.original_text = new_text; temp.classList.add("pulse"); @@ -4212,7 +4212,7 @@ function highlight_world_info_text_in_chunk(action_id, wi) { } else { action = document.getElementById("Selected Text Chunk "+action_id); } - let words = action.textContent.split(" "); + let words = action.innerText.split(" "); current_ids = action.getAttribute("world_info_uids")?action.getAttribute("world_info_uids").split(','):[]; if (!(current_ids.includes(uid))) { current_ids.push(uid); @@ -4243,8 +4243,8 @@ function highlight_world_info_text_in_chunk(action_id, wi) { for (span of action.childNodes) { //console.log(span); //console.log("passed_words("+passed_words+")+span("+(span.textContent.trim().split(" ").length)+") Date: Sat, 17 Dec 2022 12:27:48 -0600 Subject: [PATCH 3/3] Fix for saving --- static/koboldai.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/koboldai.js b/static/koboldai.js index d60d8bbc..9a49f3aa 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -2994,7 +2994,7 @@ function select_game_text(event) { } //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.textContent != selected_game_chunk.original_text) && (selected_game_chunk != document.getElementById("welcome_text"))) { + if ((selected_game_chunk != null) && (selected_game_chunk.innerText != selected_game_chunk.original_text) && (selected_game_chunk != document.getElementById("welcome_text"))) { if (selected_game_chunk.id == 'story_prompt') { edit_game_text(-1); } else {