Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code editor toggle comment doesn't uncomment if there's a different amount of #'s #83331

Closed
aXu-AP opened this issue Oct 14, 2023 · 5 comments · Fixed by #83382
Closed

Code editor toggle comment doesn't uncomment if there's a different amount of #'s #83331

aXu-AP opened this issue Oct 14, 2023 · 5 comments · Fixed by #83382

Comments

@aXu-AP
Copy link
Contributor

aXu-AP commented Oct 14, 2023

Godot version

v4.2.beta1.official [b137180]

System information

Windows 10

Issue description

Toggle comment adds more comment delimiters when there's different amount of delimiters, even if all the lines are commented.

Current behavior:
comment

Expected behavior (from v4.2.dev6.official [57a6813]):
comment_old

Regression likely happened in #81486

Steps to reproduce

Open script editor. Comment some lines. Then select bigger area enclosing some of the commented lines, and toggle comment twice or more.

Minimal reproduction project

N/A

@aXu-AP
Copy link
Contributor Author

aXu-AP commented Oct 14, 2023

I might fix this next week if I have time, but feel free to work on this if you want. Shouldn't be hard to fix.

@Lunarisnia
Copy link
Contributor

I would love to try and fix this, can I get assigned to this issue?

@aXu-AP
Copy link
Contributor Author

aXu-AP commented Oct 14, 2023

Just go ahead, issues aren't usually assigned 👍

@Lunarisnia
Copy link
Contributor

Lunarisnia commented Oct 15, 2023

int delimiter_idx = text_editor->is_in_comment(line, text_editor->get_first_non_whitespace_column(line) + delimiter.length());

godot/scene/gui/code_edit.cpp

Lines 1912 to 1915 in a574c02

String CodeEdit::get_delimiter_start_key(int p_delimiter_idx) const {
ERR_FAIL_INDEX_V(p_delimiter_idx, delimiters.size(), "");
return delimiters[p_delimiter_idx].start_key;
}

godot/scene/gui/code_edit.cpp

Lines 2939 to 2963 in a574c02

for (int d = 0; d < delimiters.size(); d++) {
/* check there is enough room */
int chars_left = line_length - from;
int start_key_length = delimiters[d].start_key.length();
int end_key_length = delimiters[d].end_key.length();
if (chars_left < start_key_length) {
continue;
}
/* search the line */
bool match = true;
const char32_t *start_key = delimiters[d].start_key.get_data();
for (int k = 0; k < start_key_length; k++) {
if (start_key[k] != str[from + k]) {
match = false;
break;
}
}
if (!match) {
continue;
}
same_line = true;
in_region = d;
delimiter_cache.write[i][from + 1] = d;
from += start_key_length;

From my investigation. The issue seems to root from the function CodeEdit::is_in_comment returning 2 instead of 3 when there is a multiple comment delimiter in a line. it seems to cause CodeEdit::get_delimiter_start_key to return ## instead of # which cause the error. CMIIW

This issue can also be reproduced by simply adding multiple comment delimiter in a line then using the In-line comment shortcut:
Example:

# Try using the inline comment shortcut on this line below
##var l1

@aXu-AP
Copy link
Contributor Author

aXu-AP commented Oct 16, 2023

Thanks @Lunarisnia for taking care of this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants