Skip to content

Commit

Permalink
Fix fraction convert error
Browse files Browse the repository at this point in the history
Fraction failed to convert if previous line ended in a letter.
This was due to surprising (to me) regex behavior where
a dollar matches end-of-string OR a newline at the end
of the string.
  • Loading branch information
windymilla committed Dec 6, 2024
1 parent a19a3b9 commit 055d30b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/guiguts/misc_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,8 +1105,10 @@ def fraction_convert(conversion_type: FractionConvertType) -> None:
new_frac = f"{gmatch[2].translate(superscripts)}{frac_slash}{gmatch[3].translate(subscripts)}"
# Only convert if we found one that should be converted. Don't convert strings like
# "B1/2" or "C-1/3" - probably a plate/serial number, but not a fraction
prefix = maintext().get(f"{match.rowcol.index()}-2c", match.rowcol.index())
if new_frac and not re.search(r"(\p{L}-|\p{L}$)", prefix):
prefix = maintext().get(
f"{match.rowcol.index()} linestart", match.rowcol.index()
)
if new_frac and not re.search(r"\p{L}-?$", prefix):
len_frac = len(new_frac)
maintext().insert(match_index, new_frac)
maintext().delete(
Expand Down

0 comments on commit 055d30b

Please sign in to comment.