mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
change wrap() to wrap2() to avoid breaking add-ons
This commit is contained in:
parent
18a3ead1d2
commit
b9f564f49a
2 changed files with 24 additions and 9 deletions
|
@ -510,7 +510,7 @@ to a cloze type first, via Edit>Change Note Type."""))
|
||||||
highest += 1
|
highest += 1
|
||||||
# must start at 1
|
# must start at 1
|
||||||
highest = max(1, highest)
|
highest = max(1, highest)
|
||||||
self.web.eval("wrap('{{c%d::', '}}');" % highest)
|
self.web.eval("wrap2('{{c%d::', '}}');" % highest)
|
||||||
|
|
||||||
# Foreground colour
|
# Foreground colour
|
||||||
######################################################################
|
######################################################################
|
||||||
|
@ -791,22 +791,22 @@ to a cloze type first, via Edit>Change Note Type."""))
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def insertLatex(self):
|
def insertLatex(self):
|
||||||
self.web.eval("wrap('[latex]', '[/latex]');")
|
self.web.eval("wrap2('[latex]', '[/latex]');")
|
||||||
|
|
||||||
def insertLatexEqn(self):
|
def insertLatexEqn(self):
|
||||||
self.web.eval("wrap('[$]', '[/$]');")
|
self.web.eval("wrap2('[$]', '[/$]');")
|
||||||
|
|
||||||
def insertLatexMathEnv(self):
|
def insertLatexMathEnv(self):
|
||||||
self.web.eval("wrap('[$$]', '[/$$]');")
|
self.web.eval("wrap2('[$$]', '[/$$]');")
|
||||||
|
|
||||||
def insertMathjaxInline(self):
|
def insertMathjaxInline(self):
|
||||||
self.web.eval("wrap('\\\\(', '\\\\)');")
|
self.web.eval("wrap2('\\\\(', '\\\\)');")
|
||||||
|
|
||||||
def insertMathjaxBlock(self):
|
def insertMathjaxBlock(self):
|
||||||
self.web.eval("wrap('\\\\[', '\\\\]');")
|
self.web.eval("wrap2('\\\\[', '\\\\]');")
|
||||||
|
|
||||||
def insertMathjaxChemistry(self):
|
def insertMathjaxChemistry(self):
|
||||||
self.web.eval("wrap('\\\\(\\\\ce{', '}\\\\)');")
|
self.web.eval("wrap2('\\\\(\\\\ce{', '}\\\\)');")
|
||||||
|
|
||||||
# Links from HTML
|
# Links from HTML
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
|
@ -266,7 +266,17 @@ function maybeDisableButtons() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* old method, kept around for the benefit of add-ons that were using it */
|
||||||
function wrap(front, back) {
|
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") {
|
if (currentField.dir === "rtl") {
|
||||||
front = "‫" + front + "‬";
|
front = "‫" + front + "‬";
|
||||||
back = "‫" + back + "‬";
|
back = "‫" + back + "‬";
|
||||||
|
@ -276,8 +286,13 @@ function wrap(front, back) {
|
||||||
var content = r.cloneContents();
|
var content = r.cloneContents();
|
||||||
var span = document.createElement("span");
|
var span = document.createElement("span");
|
||||||
span.appendChild(content);
|
span.appendChild(content);
|
||||||
var new_ = wrappedExceptForWhitespace(span.innerText, front, back);
|
if (plainText) {
|
||||||
setFormat("inserttext", new_);
|
var new_ = wrappedExceptForWhitespace(span.innerText, front, back);
|
||||||
|
setFormat("inserttext", new_);
|
||||||
|
} else {
|
||||||
|
var new_ = wrappedExceptForWhitespace(span.innerHTML, front, back);
|
||||||
|
setFormat("inserthtml", new_);
|
||||||
|
}
|
||||||
if (!span.innerHTML) {
|
if (!span.innerHTML) {
|
||||||
// run with an empty selection; move cursor back past postfix
|
// run with an empty selection; move cursor back past postfix
|
||||||
r = s.getRangeAt(0);
|
r = s.getRangeAt(0);
|
||||||
|
|
Loading…
Reference in a new issue