From 151407a001651c70f49a0c659957d80a36ec2a8a Mon Sep 17 00:00:00 2001 From: vfbd Date: Sun, 26 Jun 2022 13:02:22 -0400 Subject: [PATCH 1/3] Don't add sentence spacing if submission is empty When you retry, it actually sends an empty submission, so if you have add sentence spacing on, retrying could add an extra action with a single space. --- utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils.py b/utils.py index 430e729b..3c5d2a1e 100644 --- a/utils.py +++ b/utils.py @@ -104,6 +104,9 @@ def removespecialchars(txt, vars=None): # If the next action follows a sentence closure, add a space #==================================================================# def addsentencespacing(txt, vars): + # Don't add sentence spacing if submission is empty or starts with whitespace + if(len(txt) == 0 or len(txt) != len(txt.lstrip())): + return txt # Get last character of last action if(len(vars.actions) > 0): if(len(vars.actions[vars.actions.get_last_key()]) > 0): From b99d1449c942286113df3c98ba7dd99137fcae64 Mon Sep 17 00:00:00 2001 From: vfbd Date: Sun, 26 Jun 2022 13:15:55 -0400 Subject: [PATCH 2/3] Remove trailing whitespace from submissions --- aiserver.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aiserver.py b/aiserver.py index 69b40119..91057d5c 100644 --- a/aiserver.py +++ b/aiserver.py @@ -3495,6 +3495,7 @@ def actionsubmit(data, actionmode=0, force_submit=False, force_prompt_gen=False, if(not vars.gamestarted): vars.submission = data execute_inmod() + vars.submission = re.sub(r"[^\S\r\n]*([\r\n]*)$", r"\1", vars.submission) # Remove trailing whitespace, excluding newlines data = vars.submission if(not force_submit and len(data.strip()) == 0): assert False @@ -3553,6 +3554,7 @@ def actionsubmit(data, actionmode=0, force_submit=False, force_prompt_gen=False, data = applyinputformatting(data) vars.submission = data execute_inmod() + vars.submission = re.sub(r"[^\S\r\n]*([\r\n]*)$", r"\1", vars.submission) # Remove trailing whitespace, excluding newlines data = vars.submission # Dont append submission if it's a blank/continue action if(data != ""): From ae41ad298cc54a1ef9972cef57dd25455b07f9fe Mon Sep 17 00:00:00 2001 From: vfbd Date: Sun, 26 Jun 2022 13:40:58 -0400 Subject: [PATCH 3/3] Make sure editor changes are applied before submitting --- static/application.js | 3 ++- templates/index.html | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/static/application.js b/static/application.js index 5b9820d2..a7a10016 100644 --- a/static/application.js +++ b/static/application.js @@ -891,6 +891,7 @@ function dosubmit(disallow_abort) { if((disallow_abort || gamestate !== "wait") && !memorymode && !gamestarted && ((!adventure || !action_mode) && txt.trim().length == 0)) { return; } + chunkOnFocusOut("override"); input_text.val(""); hideMessage(); hidegenseqs(); @@ -1969,7 +1970,7 @@ function chunkOnKeyDownSelectionChange(event) { // This gets run when you defocus the editor by clicking // outside of the editor or by pressing escape or tab function chunkOnFocusOut(event) { - if(!gametext_bound || !allowedit || event.target !== game_text[0]) { + if(event !== "override" && (!gametext_bound || !allowedit || event.target !== game_text[0])) { return; } setTimeout(function() { diff --git a/templates/index.html b/templates/index.html index 2603dec2..9cc53626 100644 --- a/templates/index.html +++ b/templates/index.html @@ -17,7 +17,7 @@ - + {% if flaskwebgui %}