Skip to content

Commit

Permalink
Fix syntax highlighting for math expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Dec 20, 2024
1 parent 2ac71c7 commit c8ee485
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Source/Utility/CachedTextRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,23 @@ class CachedTextRender {
auto tokens = StringArray::fromTokens(text, true);

auto const flagColour = colour.interpolatedWith(LookAndFeel::getDefaultLookAndFeel().findColour(PlugDataColour::signalColourId), 0.7f);

auto const mathColour = colour.interpolatedWith(Colours::purple, 0.5f);

bool firstToken = true;
bool hadFlag = false;
bool mathExpression = false;
for (auto token : tokens) {
if (token != tokens.strings.getLast())
token += " ";
if (firstToken) {
attributedText.append(token, font, nameColour);
if(token == "expr " || token == "expr~ " || token == "fexpr~ " || token == "op " || token == "op~ ")
{
mathExpression = true;
}
firstToken = false;
} else if(mathExpression) {
attributedText.append(token, font, mathColour);
} else if (token.startsWith("-") && !token.containsOnly("e.-0123456789 ")) {
attributedText.append(token, font, flagColour);
hadFlag = true;
Expand Down

0 comments on commit c8ee485

Please sign in to comment.