Skip to content

Commit 0f95e9f

Browse files
committed
Merge pull request #100575 from Wierdox/improve_syntax_highlighting_for_shorthand_of_and_plus_bitwise_and_by_altering_string_name_highlighting
Improve `&&` and `&` syntax highlighting by altering `StringName` highlighting
2 parents 3df8eb5 + ed81a17 commit 0f95e9f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

modules/gdscript/editor/gdscript_highlighter.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,12 +561,17 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
561561
}
562562
}
563563

564-
// Keep symbol color for binary '&&'. In the case of '&&&' use StringName color for the last ampersand.
564+
// Set color of StringName, keeping symbol color for binary '&&' and '&'.
565565
if (!in_string_name && in_region == -1 && str[j] == '&' && !is_binary_op) {
566-
if (j >= 2 && str[j - 1] == '&' && str[j - 2] != '&' && prev_is_binary_op) {
567-
is_binary_op = true;
568-
} else if (j == 0 || (j > 0 && str[j - 1] != '&') || prev_is_binary_op) {
566+
if (j + 1 <= line_length - 1 && (str[j + 1] == '\'' || str[j + 1] == '"')) {
569567
in_string_name = true;
568+
// Cover edge cases of i.e. '+&""' and '&&&""', so the StringName is properly colored.
569+
if (prev_is_binary_op && j >= 2 && str[j - 1] == '&' && str[j - 2] != '&') {
570+
in_string_name = false;
571+
is_binary_op = true;
572+
}
573+
} else {
574+
is_binary_op = true;
570575
}
571576
} else if (in_region != -1 || is_a_symbol) {
572577
in_string_name = false;

0 commit comments

Comments
 (0)