From 444abfff9468b6c2e2834b448a0461dd0b1c0a7c Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 27 Feb 2019 13:54:50 +1000 Subject: [PATCH] avoid nbsp for single spaces when pasting text https://anki.tenderapp.com/discussions/ankidesktop/32823-all-spaces-are-being-replaced-with-nbsp-when-pasting-219-linux --- aqt/editor.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index e284e4a2c..52b8ef297 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -939,8 +939,13 @@ class EditorWebView(AnkiWebView): # normal text; convert it to HTML txt = html.escape(txt) txt = txt.replace("\n", "
")\ - .replace("\t", " "*4)\ - .replace(" ", " ") + .replace("\t", " "*4) + + # if there's more than one consecutive space, + # use non-breaking spaces for the second one on + def repl(match): + return " " + match.group(1).replace(" ", " ") + txt = re.sub(" ( +)", repl, txt) return txt