change wrap() to wrap2() to avoid breaking add-ons

This commit is contained in:
Damien Elmes 2019-12-17 18:27:41 +10:00
parent 18a3ead1d2
commit b9f564f49a
2 changed files with 24 additions and 9 deletions

View file

@ -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
######################################################################

View file

@ -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);