From 50e6fade55ae3eb1024b67314c5e6d81f557ca03 Mon Sep 17 00:00:00 2001 From: Aaron Harsh Date: Sun, 29 Jan 2012 19:34:50 -0800 Subject: [PATCH 1/3] Make undoing a cloze operation behave more intuitively Prior to this change, undoing the clozeing of a block of text would delete the text altogether. We'd prefer it to revert to unclozed text. --- aqt/editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aqt/editor.py b/aqt/editor.py index 2dd33f49e..dcfa99e7c 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -127,7 +127,7 @@ function wrap(front, back) { setFormat('removeFormat', null, true); var s = window.getSelection(); var r = s.getRangeAt(0); - var content = r.extractContents(); + var content = r.cloneContents(); var span = document.createElement("span") span.appendChild(content); s.removeAllRanges(); From 873a981609580ca8070337091eb1531cdacec416 Mon Sep 17 00:00:00 2001 From: Aaron Harsh Date: Sun, 29 Jan 2012 20:18:26 -0800 Subject: [PATCH 2/3] 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_); }; From 765e586a43376d960871a4bcb238386598aaf0b3 Mon Sep 17 00:00:00 2001 From: Aaron Harsh Date: Sun, 29 Jan 2012 20:20:35 -0800 Subject: [PATCH 3/3] Get rid of obsolete(?) code for setting selection during cloze creation. --- aqt/editor.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index 10cb05a16..e1434324f 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -135,8 +135,6 @@ function wrap(front, back) { var content = r.cloneContents(); var span = document.createElement("span") span.appendChild(content); - s.removeAllRanges(); - s.addRange(r); var new_ = wrappedExceptForWhitespace(span.innerHTML, front, back); setFormat('inserthtml', new_); };