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 TextEdit column index out of bound if column length changes during selection #83451

Closed

Conversation

Lunarisnia
Copy link
Contributor

Fixes #83410

@Lunarisnia Lunarisnia requested a review from a team as a code owner October 16, 2023 18:06
scene/gui/text_edit.cpp Outdated Show resolved Hide resolved
@akien-mga akien-mga changed the title Fix p_column out of bound if column length change during selection Fix TextEdit column index out of bound if column length change during selection Oct 16, 2023
@akien-mga akien-mga changed the title Fix TextEdit column index out of bound if column length change during selection Fix TextEdit column index out of bound if column length changes during selection Oct 16, 2023
@akien-mga akien-mga added this to the 4.2 milestone Oct 16, 2023
@akien-mga akien-mga requested a review from a team October 16, 2023 18:11
@Lunarisnia Lunarisnia force-pushed the fix/selection-out-of-bound branch from 06c2e18 to ceeadf9 Compare October 16, 2023 18:20
@k0T0z
Copy link
Contributor

k0T0z commented Oct 16, 2023

@Lunarisnia So cool 👌

@Lunarisnia Lunarisnia force-pushed the fix/selection-out-of-bound branch from ceeadf9 to f414734 Compare October 16, 2023 18:39
@akien-mga akien-mga modified the milestones: 4.2, 4.3 Oct 26, 2023
@akien-mga akien-mga added the cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release label Oct 26, 2023
@akien-mga akien-mga requested a review from Paulb23 October 26, 2023 12:33
Copy link
Member

@Paulb23 Paulb23 left a comment

Choose a reason for hiding this comment

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

Nice investigation!

TextEdit changes the selection directly in set_line which probably causes this inconstancy in the first place, so we probably need to add another check there for .selection.selecting_column, otherwise might find this error occurring in a few other places.

@Lunarisnia Lunarisnia force-pushed the fix/selection-out-of-bound branch from f414734 to 8c0220e Compare October 30, 2023 05:31
@Lunarisnia Lunarisnia requested a review from Paulb23 October 30, 2023 05:31
@Lunarisnia
Copy link
Contributor Author

Lunarisnia commented Oct 30, 2023

Nice investigation!

TextEdit changes the selection directly in set_line which probably causes this inconstancy in the first place, so we probably need to add another check there for .selection.selecting_column, otherwise might find this error occurring in a few other places.

I've moved the fix into set_line and removed the old one since it just seems redundant, Thank you.

@@ -3445,6 +3445,7 @@ void TextEdit::set_line(int p_line, const String &p_new_text) {

if (has_selection(i) && p_line == get_selection_to_line(i) && get_selection_to_column(i) > text[p_line].length()) {
carets.write[i].selection.to_column = text[p_line].length();
carets.write[i].selection.selecting_column = CLAMP(carets[i].selection.selecting_column, 0, text[p_line].length());
Copy link
Member

Choose a reason for hiding this comment

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

Would add a new check for selecting_column as it's not guaranteed that get_selection_to_line() == selecting_line

@YuriSizov
Copy link
Contributor

@Lunarisnia Are you available to address latest feedback?

@Lunarisnia
Copy link
Contributor Author

@Lunarisnia Are you available to address latest feedback?

@YuriSizov Sorry for letting this go stale, I have been quite busy these few weeks, I don't think I can address the feedback this week. Maybe I'll just close this so that people can take over?

@YuriSizov
Copy link
Contributor

YuriSizov commented Dec 5, 2023

@Lunarisnia There is no rush if you plan to eventually finish it! But voicing that others are welcome to take over is also fine. If anyone pick it up, we can always supersede your PR. In any case, no worries.

@akien-mga
Copy link
Member

Superseded by #86978. Thanks for the contribution!

@akien-mga akien-mga closed this Apr 30, 2024
@akien-mga akien-mga added archived and removed cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release labels Apr 30, 2024
@akien-mga akien-mga removed this from the 4.3 milestone Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when using CTRL+/ on Windows
5 participants