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 != ""):
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 %}
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):