Skip to content

Commit 1e03975

Browse files
committed
Cleanup CopyAs code -- I thought I had committed this early.
1 parent 72acb4c commit 1e03975

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

addon/globalPlugins/MathCAT/MathCAT.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -306,33 +306,33 @@ def script_navigate(self, gesture: KeyboardInputGesture):
306306
)
307307
def script_rawdataToClip(self, gesture: KeyboardInputGesture):
308308
try:
309-
mathml = libmathcat.GetNavigationMathML()[0]
310-
if not re.match(self._startsWithMath, mathml):
311-
mathml = (
312-
"<math>\n" + mathml + "</math>"
313-
) # copy will fix up name spacing
314-
elif self.init_mathml != "":
315-
mathml = self.init_mathml
316-
copy_as = "mathml"
309+
copy_as = "mathml" # value used even if "CopyAs" pref is invalid
310+
text_to_copy = ""
317311
try:
318312
copy_as = libmathcat.GetPreference("CopyAs").lower()
319-
match copy_as:
320-
case "mathml" | "latex" | "asciimath":
321-
pass
322-
case _:
323-
copy_as = "mathml"
324313
except Exception as e:
325314
log.error(f"Not able to get 'CopyAs' preference: {e}")
326-
327-
mathml = self._wrapMathMLForClipBoard(mathml)
328-
if copy_as != "mathml":
315+
if copy_as == "asciimath" or copy_as == "latex":
316+
# save the old braille code, set the new one, get the braille, then reset the code
329317
saved_braille_code: str = libmathcat.GetPreference("BrailleCode")
330318
libmathcat.SetPreference("BrailleCode", "LaTeX" if copy_as == "latex" else "ASCIIMath")
331-
mathml = libmathcat.GetNavigationBraille()
319+
text_to_copy = libmathcat.GetNavigationBraille()
332320
libmathcat.SetPreference("BrailleCode", saved_braille_code)
333-
self._copyToClipAsMathML(mathml, copy_as == "mathml")
321+
if copy_as == "asciimath":
322+
copy_as = "ASCIIMath" # speaks better in at least some voices
323+
else:
324+
mathml = libmathcat.GetNavigationMathML()[0]
325+
if not re.match(self._startsWithMath, mathml):
326+
mathml = (
327+
"<math>\n" + mathml + "</math>"
328+
) # copy will fix up name spacing
329+
elif self.init_mathml != "":
330+
mathml = self.init_mathml
331+
text_to_copy = self._wrapMathMLForClipBoard(mathml)
332+
333+
self._copyToClipAsMathML(text_to_copy, copy_as == "mathml")
334334
# Translators: copy to clipboard
335-
ui.message(_("copy"))
335+
ui.message(_("copy as ") + copy_as)
336336
except Exception as e:
337337
log.error(e)
338338
# Translators: this message directs users to look in the log file

0 commit comments

Comments
 (0)