X Tutup
Skip to content

Fix completion popup placement and adjust lines to available space#112991

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
syntaxerror247:fix-completion-popup-placement
Dec 2, 2025
Merged

Fix completion popup placement and adjust lines to available space#112991
Repiteo merged 1 commit intogodotengine:masterfrom
syntaxerror247:fix-completion-popup-placement

Conversation

@syntaxerror247
Copy link
Member

@syntaxerror247 syntaxerror247 commented Nov 20, 2025

Previously, when the code completion popup could not fully fit either above or below the current line, the editor always defaulted to drawing it below. This caused the popup to be partially cut off in small editor windows.

This PR improves that behavior:

  • When the popup cannot fit both above and below, it now compare the available space on each side and choose the side with more room.
  • The popup's line count is then dynamically reduced based on the available space, to ensure the completion window never clips.

Before

Screenrecorder-2025-11-20-23-24-02-268.mp4

After

Screenrecorder-2025-11-20-23-18-38-631.mp4

@akien-mga
Copy link
Member

If you're able to get that, screenshots of before/after could be useful for a quick assessment of the placement change.

@syntaxerror247
Copy link
Member Author

syntaxerror247 commented Nov 20, 2025

If you're able to get that, screenshots of before/after could be useful for a quick assessment of the placement change.

Updated the PR description with before/after videos. In the before clip, the completion window gets cut off, but in the after clip it correctly positions itself above the line and line no is also reduced to fit.

You can observe the issue on desktop editor too, just minimize the script editor height.

Screencast_20251121_001128.webm

@syntaxerror247 syntaxerror247 force-pushed the fix-completion-popup-placement branch from fac8555 to 8b01363 Compare November 21, 2025 07:15
@kitbdev
Copy link
Contributor

kitbdev commented Nov 21, 2025

The completion popup should be changed to an actual popup so it can show outside of the CodeEdit, at some point.
But it will need logic like this for screen boundaries still.

Copy link
Member

@Alex2782 Alex2782 left a comment

Choose a reason for hiding this comment

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

I've included some print_line functions to examine their impact on the Unit Tests.

./tests/scene/test_code_edit.h:4164: ERROR: CHECK( code_edit->get_code_completion_selected_index() == 2 ) is NOT correct!
  values: CHECK( -1 == 2 )
total_height:  81
code_edit->get_line_height():  27
81 / 27 = 3 lines

Your PR reduces the number of lines from 3 to 2.

// Reduce the line count and recalculate heights to better fit the completion popup.
...
total_height = theme_cache.code_completion_style->get_minimum_size().y + code_completion_rect.size.height;
total_height:  54
54 / 27 = 2 lines

Possible fix: no longer check the 3rd line, but the 2nd.

https://github.com/godotengine/godot/blob/master/tests/scene/test_code_edit.h#L4160-L4170

			/* Single click selects. */
			caret_pos.y += code_edit->get_line_height();
			SEND_GUI_MOUSE_BUTTON_EVENT(caret_pos, MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
			SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(caret_pos, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
			CHECK(code_edit->get_code_completion_selected_index() == 1);

			/* Double click inserts. */
			SEND_GUI_DOUBLE_CLICK(caret_pos, Key::NONE);
			CHECK(code_edit->get_code_completion_selected_index() == -1);
			CHECK(code_edit->get_line(0) == "item_1");

@syntaxerror247 syntaxerror247 requested a review from a team as a code owner November 24, 2025 18:43
Copy link
Member

@Alex2782 Alex2782 left a comment

Choose a reason for hiding this comment

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

Tested on MacOS, looks good to me.

Screen-2025-11-25-010711.mp4

@syntaxerror247 syntaxerror247 force-pushed the fix-completion-popup-placement branch from 2ed16e8 to ef5fbe8 Compare November 25, 2025 14:27
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

Changes seem good to me.

Copy link
Contributor

@kitbdev kitbdev left a comment

Choose a reason for hiding this comment

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

Works as expected.

@syntaxerror247 syntaxerror247 force-pushed the fix-completion-popup-placement branch from ef5fbe8 to 834dfcb Compare November 26, 2025 13:42
@Repiteo Repiteo merged commit 554c2ab into godotengine:master Dec 2, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Dec 2, 2025

Thanks!

@syntaxerror247 syntaxerror247 deleted the fix-completion-popup-placement branch December 2, 2025 18:08
@Jowan-Spooner
Copy link

This kindof fixes #38560 (which is very nice, thanks!), but I would kindly request again for the AutoComplete popup to be able to extend beyond the CodeEdits size. Would be super useful to allow small code edits to use autocompletion, which we could use in Dialogic (as proposed here godotengine/godot-proposals#7162) and as you can see above this could even be useful for the script editor on small devices.

As said above:

The completion popup should be changed to an actual popup so it can show outside of the CodeEdit, at some point. But it will need logic like this for screen boundaries still.

Thank you very much for all your work already 🙏😊

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.

6 participants

X Tutup