mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Don't stick leading/trailing whitespace in a cloze.
This commit is contained in:
parent
50e6fade55
commit
873a981609
1 changed files with 6 additions and 5 deletions
|
@ -123,6 +123,11 @@ function saveField(type) {
|
||||||
clearChangeTimer();
|
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) {
|
function wrap(front, back) {
|
||||||
setFormat('removeFormat', null, true);
|
setFormat('removeFormat', null, true);
|
||||||
var s = window.getSelection();
|
var s = window.getSelection();
|
||||||
|
@ -132,11 +137,7 @@ function wrap(front, back) {
|
||||||
span.appendChild(content);
|
span.appendChild(content);
|
||||||
s.removeAllRanges();
|
s.removeAllRanges();
|
||||||
s.addRange(r);
|
s.addRange(r);
|
||||||
var new_ = front + span.innerHTML + back;
|
var new_ = wrappedExceptForWhitespace(span.innerHTML, front, back);
|
||||||
var f = currentField.innerHTML;
|
|
||||||
if (f.length && f[f.length-1] === " ") {
|
|
||||||
new_ = " " + new_;
|
|
||||||
}
|
|
||||||
setFormat('inserthtml', new_);
|
setFormat('inserthtml', new_);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue