From 873a981609580ca8070337091eb1531cdacec416 Mon Sep 17 00:00:00 2001 From: Aaron Harsh Date: Sun, 29 Jan 2012 20:18:26 -0800 Subject: [PATCH] Don't stick leading/trailing whitespace in a cloze. --- aqt/editor.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index dcfa99e7c..10cb05a16 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -123,6 +123,11 @@ function saveField(type) { clearChangeTimer(); }; +function wrappedExceptForWhitespace(text, front, back) { + var match = text.match(/^(\s*)([^]*?)(\s*)$/); + return match[1] + front + match[2] + back + match[3]; +}; + function wrap(front, back) { setFormat('removeFormat', null, true); var s = window.getSelection(); @@ -132,11 +137,7 @@ function wrap(front, back) { span.appendChild(content); s.removeAllRanges(); s.addRange(r); - var new_ = front + span.innerHTML + back; - var f = currentField.innerHTML; - if (f.length && f[f.length-1] === " ") { - new_ = " " + new_; - } + var new_ = wrappedExceptForWhitespace(span.innerHTML, front, back); setFormat('inserthtml', new_); };