From ed81a17e1e7025b4ddaa481014a25b46b1412363 Mon Sep 17 00:00:00 2001 From: Wierdox <104049283+Wierdox@users.noreply.github.com> Date: Wed, 18 Dec 2024 09:32:17 -0800 Subject: [PATCH] Improve '&&' and '&' syntax highlighting by altering StringName highlighting --- modules/gdscript/editor/gdscript_highlighter.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index b8851e5bf21c..a4218c8b7b14 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -560,12 +560,17 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l } } - // Keep symbol color for binary '&&'. In the case of '&&&' use StringName color for the last ampersand. + // Set color of StringName, keeping symbol color for binary '&&' and '&'. if (!in_string_name && in_region == -1 && str[j] == '&' && !is_binary_op) { - if (j >= 2 && str[j - 1] == '&' && str[j - 2] != '&' && prev_is_binary_op) { - is_binary_op = true; - } else if (j == 0 || (j > 0 && str[j - 1] != '&') || prev_is_binary_op) { + if (j + 1 <= line_length - 1 && (str[j + 1] == '\'' || str[j + 1] == '"')) { in_string_name = true; + // Cover edge cases of i.e. '+&""' and '&&&""', so the StringName is properly colored. + if (prev_is_binary_op && j >= 2 && str[j - 1] == '&' && str[j - 2] != '&') { + in_string_name = false; + is_binary_op = true; + } + } else { + is_binary_op = true; } } else if (in_region != -1 || is_a_symbol) { in_string_name = false;