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

Avoid resetting the code completion popup excessively #81633

Merged
merged 1 commit into from
Oct 3, 2023

Conversation

matorin57
Copy link
Contributor

@matorin57 matorin57 commented Sep 14, 2023

Fixes #57027. The issue was that _filter_code_completion_candidates_impl always resets the selected item. While up/down won't cause an update, there is a race condition where updating the list and then quickly changing selection will cause the selection to move and then reset. This can also happen even when the update doesn't actually change the list of options.

The fix here was to have _filter_code_completion_candidates_impl check to see if the new options list is the same up to the currently selected item. Then we only reset the selection if the list differs before the selection. That way if the list only changes after the selection we won't reset. If the list changes before our selection, then we still want to reset as the selected item may no longer be meaningful.

This is done by building a new list and then comparing. There is an increased memory footprint in that we must hold two lists while doing the update, but once we are done we discard the old list. There is also a time increase in that we need to perform the list comparison (copying over the new list should be the same as clearing the old list and building the new one like we did originally). Considering that this lists will typically be small the time and memory hit should be unnoticeable from a UX standpoint.

I also implemented it for the overridden version but I wasn't sure how to test that directly. But the tests for the non-overridden version should check the base logic. I am not 100% sure how this override system works so any notes and explanation would be appreciated.

I haven't squashed yet, but figured I was going to have to make some updates in the review anyway so will squash after the notes.

@matorin57 matorin57 requested review from a team as code owners September 14, 2023 04:10
@Chaosus Chaosus added this to the 4.2 milestone Sep 14, 2023
scene/gui/code_edit.cpp Outdated Show resolved Hide resolved
scene/gui/code_edit.cpp Outdated Show resolved Hide resolved
scene/gui/code_edit.cpp Outdated Show resolved Hide resolved
@YuriSizov YuriSizov changed the title Code completion popup Avoid resetting the code completion popup excessively Sep 14, 2023
@YuriSizov
Copy link
Contributor

I haven't squashed yet, but figured I was going to have to make some updates in the review anyway so will squash after the notes.

Yeah, that's fine. But when you do, please make sure to use a commit message that follows the project's style. The current title of this PR is a good option.

@matorin57
Copy link
Contributor Author

Squashed commits and addressed feedback

scene/gui/code_edit.cpp Outdated Show resolved Hide resolved
tests/scene/test_code_edit.h Outdated Show resolved Hide resolved
tests/scene/test_code_edit.h Outdated Show resolved Hide resolved
tests/scene/test_code_edit.h Outdated Show resolved Hide resolved
tests/scene/test_code_edit.h Outdated Show resolved Hide resolved
tests/scene/test_code_edit.h Outdated Show resolved Hide resolved
tests/scene/test_code_edit.h Outdated Show resolved Hide resolved
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.

Thanks for the contribution!

Looks great with test as well, couple small comments left inline

scene/gui/code_edit.cpp Outdated Show resolved Hide resolved
scene/gui/code_edit.cpp Outdated Show resolved Hide resolved
scene/gui/code_edit.cpp Outdated Show resolved Hide resolved
@matorin57 matorin57 force-pushed the code-completion-popup branch from 2735aec to 303d099 Compare September 20, 2023 20:50
@matorin57
Copy link
Contributor Author

Addressed Feedback

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.

LGTM

@akien-mga akien-mga merged commit b11309d into godotengine:master Oct 3, 2023
15 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code completion popup interrupts itself even if contents are the same
6 participants