revert to the old wrap() behaviour

wrap2() was introduced recently to try and resolve an issue where
styling outside of the wrapped section was getting lost. eg,

<b>some [text] etc</b>

When the user created a cloze deletion or added math tags to the [text]
part, the text ended up not being bold - the inner portion is displayed
without styling.

wrap2() used setFormat("inserttext", ...), which did fix that issue
- but it also introduced multiple new issues:

- any HTML inside the selected area, including newlines and images,
was lost
- the unicode entities inserted when creating a cloze deletion in
RTL mode end up inserted as plain text

For now, I'm just going to revert to the old behaviour. If anyone
has a suggestion for an approach that is able to preserve both the
inner formatting and the surrounding formatting, a pull request
or post on the forums would be appreciated!
This commit is contained in:
Damien Elmes 2020-01-16 10:33:36 +10:00
parent 69a7ee430d
commit bf93731e49
2 changed files with 9 additions and 10 deletions

View file

@ -606,7 +606,7 @@ to a cloze type first, via Edit>Change Note Type."""
highest += 1
# must start at 1
highest = max(1, highest)
self.web.eval("wrap2('{{c%d::', '}}');" % highest)
self.web.eval("wrap('{{c%d::', '}}');" % highest)
# Foreground colour
######################################################################
@ -888,22 +888,22 @@ to a cloze type first, via Edit>Change Note Type."""
######################################################################
def insertLatex(self):
self.web.eval("wrap2('[latex]', '[/latex]');")
self.web.eval("wrap('[latex]', '[/latex]');")
def insertLatexEqn(self):
self.web.eval("wrap2('[$]', '[/$]');")
self.web.eval("wrap('[$]', '[/$]');")
def insertLatexMathEnv(self):
self.web.eval("wrap2('[$$]', '[/$$]');")
self.web.eval("wrap('[$$]', '[/$$]');")
def insertMathjaxInline(self):
self.web.eval("wrap2('\\\\(', '\\\\)');")
self.web.eval("wrap('\\\\(', '\\\\)');")
def insertMathjaxBlock(self):
self.web.eval("wrap2('\\\\[', '\\\\]');")
self.web.eval("wrap('\\\\[', '\\\\]');")
def insertMathjaxChemistry(self):
self.web.eval("wrap2('\\\\(\\\\ce{', '}\\\\)');")
self.web.eval("wrap('\\\\(\\\\ce{', '}\\\\)');")
# Links from HTML
######################################################################

View file

@ -284,13 +284,12 @@ 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) {
/* currently unused */
function wrapIntoText(front, back) {
wrapInternal(front, back, true);
}