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

Fix bug related to multicursor and backspacing with brackets #89469

Merged
merged 1 commit into from
Mar 14, 2024

Conversation

garrettgu10
Copy link
Contributor

@garrettgu10 garrettgu10 commented Mar 14, 2024

Fixes #89417.

The root of the issue is that when removing an opening brace remove_text is sometimes called with just cc (when the opening and closing brace are not next to each other), but adjust_carets_after_edit was always being called assuming that the closing brace was removed as well.

@garrettgu10 garrettgu10 requested a review from a team as a code owner March 14, 2024 05:03
@YeldhamDev YeldhamDev added this to the 4.3 milestone Mar 14, 2024
Comment on lines 735 to 737
int new_cc;
if (_get_auto_brace_pair_close_at_pos(cl, cc) == idx) {
remove_text(prev_line, prev_column, cl, cc + auto_brace_completion_pairs[idx].close_key.length());
new_cc = cc + auto_brace_completion_pairs[idx].close_key.length();
} else {
remove_text(prev_line, prev_column, cl, cc);
new_cc = cc;
}
Copy link
Member

@akien-mga akien-mga Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be simplified to:

int new_cc = cc;
if (_get_auto_brace_pair_close_at_pos(cl, cc) == idx) {
	new_cc += auto_brace_completion_pairs[idx].close_key.length();
}

Note: Please make modifications by amending the commit, and force pushing the changes, so that it stays as a single commit (see PR workflow).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also just use cc instead of making new_cc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc is still used further down in other branches and iterations of the loop, so modifying it might change behavior. Does it fix further bugs by doing so or actually risk introducing bugs?

Copy link
Contributor

@kitbdev kitbdev Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a continue after this, and it is re-set on the next loop iteration, so it doesn't affect any other uses.
It won't fix any other bugs, its just cleaner.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah indeed 👍

@akien-mga akien-mga requested a review from a team March 14, 2024 11:07
@kitbdev
Copy link
Contributor

kitbdev commented Mar 14, 2024

@garrettgu10 garrettgu10 force-pushed the ggu/multicursor-bugfix branch from ae54a8a to 769aff5 Compare March 14, 2024 16:47
@garrettgu10 garrettgu10 force-pushed the ggu/multicursor-bugfix branch from 769aff5 to 4ab08fb Compare March 14, 2024 16:48
@akien-mga akien-mga added the cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release label Mar 14, 2024
@akien-mga akien-mga merged commit a5a5ce7 into godotengine:master Mar 14, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release topic:gui
Projects
None yet
4 participants