Skip to content

Commit

Permalink
Fix syntax colors for numbers with separators and / operator
Browse files Browse the repository at this point in the history
Correctly highlights JS formatted numbers with separators, for example:
`100_000`, `0x1234_abcd`

Avoids highlighting multiple lines as regular expression when `/` is
encountered. The syntax matching is still very trivial but should fix
many problems.
  • Loading branch information
hluk committed Nov 4, 2024
1 parent d7a181d commit ce8ae8a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/gui/commandsyntaxhighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CommandSyntaxHighlighter final : public QSyntaxHighlighter
, m_reFunctions(createRegExp(scriptableFunctions()))
, m_reKeywords(createRegExp(scriptableKeywords()))
, m_reLabels(commandLabelRegExp())
, m_reConstants("\\b0x[0-9A-Fa-f]+|(?:\\b|%)\\d+|\\btrue\\b|\\bfalse\\b")
, m_reConstants(R"(\b0x[0-9A-Fa-f](?:_?[0-9A-Fa-f])*|(?:\b|%)\d(?:_?\d)*|\btrue\b|\bfalse\b)")
{
}

Expand Down Expand Up @@ -198,8 +198,14 @@ class CommandSyntaxHighlighter final : public QSyntaxHighlighter
if (i == -1)
i = text.size();

--i;
format(a, i);

setCurrentBlockState(Code);
} else if (c == '\n' || i + 1 == text.size()) {
// The '/' was not regex start, since there is no ending
// '/' on the same line.
i = a;
setCurrentBlockState(Code);
}
} else if (c == '\\') {
Expand Down

0 comments on commit ce8ae8a

Please sign in to comment.