From c9129a1a267228f0e7f469c49f846a91b72ac48c Mon Sep 17 00:00:00 2001 From: Lukas Holecek Date: Mon, 4 Nov 2024 13:50:19 +0100 Subject: [PATCH] Fix syntax colors for numbers with separators and / operator 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. --- src/gui/commandsyntaxhighlighter.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gui/commandsyntaxhighlighter.cpp b/src/gui/commandsyntaxhighlighter.cpp index ad04a8d345..4d08124bfb 100644 --- a/src/gui/commandsyntaxhighlighter.cpp +++ b/src/gui/commandsyntaxhighlighter.cpp @@ -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)") { } @@ -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 == '\\') {