From bf93731e49ec93f699fea98541a19c9b24a91cd9 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 16 Jan 2020 10:33:36 +1000 Subject: [PATCH] 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, some [text] etc 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! --- qt/aqt/editor.py | 14 +++++++------- qt/ts/src/editor.ts | 5 ++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 32ace7269..74b9d9358 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -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 ###################################################################### diff --git a/qt/ts/src/editor.ts b/qt/ts/src/editor.ts index e5f230c45..ae70a31ce 100644 --- a/qt/ts/src/editor.ts +++ b/qt/ts/src/editor.ts @@ -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); }