From b9f564f49a4f68ff5025c69d45cc0807b4a10c20 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 17 Dec 2019 18:27:41 +1000 Subject: [PATCH] change wrap() to wrap2() to avoid breaking add-ons --- aqt/editor.py | 14 +++++++------- web/editor.js | 19 +++++++++++++++++-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index 916f3ad92..a333b373c 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -510,7 +510,7 @@ to a cloze type first, via Edit>Change Note Type.""")) highest += 1 # must start at 1 highest = max(1, highest) - self.web.eval("wrap('{{c%d::', '}}');" % highest) + self.web.eval("wrap2('{{c%d::', '}}');" % highest) # Foreground colour ###################################################################### @@ -791,22 +791,22 @@ to a cloze type first, via Edit>Change Note Type.""")) ###################################################################### def insertLatex(self): - self.web.eval("wrap('[latex]', '[/latex]');") + self.web.eval("wrap2('[latex]', '[/latex]');") def insertLatexEqn(self): - self.web.eval("wrap('[$]', '[/$]');") + self.web.eval("wrap2('[$]', '[/$]');") def insertLatexMathEnv(self): - self.web.eval("wrap('[$$]', '[/$$]');") + self.web.eval("wrap2('[$$]', '[/$$]');") def insertMathjaxInline(self): - self.web.eval("wrap('\\\\(', '\\\\)');") + self.web.eval("wrap2('\\\\(', '\\\\)');") def insertMathjaxBlock(self): - self.web.eval("wrap('\\\\[', '\\\\]');") + self.web.eval("wrap2('\\\\[', '\\\\]');") def insertMathjaxChemistry(self): - self.web.eval("wrap('\\\\(\\\\ce{', '}\\\\)');") + self.web.eval("wrap2('\\\\(\\\\ce{', '}\\\\)');") # Links from HTML ###################################################################### diff --git a/web/editor.js b/web/editor.js index ac2cadca3..f6d378a21 100644 --- a/web/editor.js +++ b/web/editor.js @@ -266,7 +266,17 @@ function maybeDisableButtons() { } } +/* old method, kept around for the benefit of add-ons that were using it */ function wrap(front, back) { + wrapInternal(front, back, false); +} + +/* new method */ +function wrap2(front, back) { + wrapInternal(front, back, true); +} + +function wrapInternal(front, back, plainText) { if (currentField.dir === "rtl") { front = "‫" + front + "‬"; back = "‫" + back + "‬"; @@ -276,8 +286,13 @@ function wrap(front, back) { var content = r.cloneContents(); var span = document.createElement("span"); span.appendChild(content); - var new_ = wrappedExceptForWhitespace(span.innerText, front, back); - setFormat("inserttext", new_); + if (plainText) { + var new_ = wrappedExceptForWhitespace(span.innerText, front, back); + setFormat("inserttext", new_); + } else { + var new_ = wrappedExceptForWhitespace(span.innerHTML, front, back); + setFormat("inserthtml", new_); + } if (!span.innerHTML) { // run with an empty selection; move cursor back past postfix r = s.getRangeAt(0);