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 scroll to symbol's documentation #100156

Merged
merged 1 commit into from
Dec 30, 2024

Conversation

ydeltastar
Copy link
Contributor

@ydeltastar ydeltastar commented Dec 7, 2024

Same fix as #90035 but for a different code path.
A doc page goes through this code path the first time it opens but depending on the device it will execute too early so the correct offsets weren't calculated yet.

@ydeltastar ydeltastar requested a review from a team as a code owner December 7, 2024 22:00
@passivestar
Copy link
Contributor

Works on my end, thanks

@@ -215,7 +215,7 @@ void EditorHelp::_search(bool p_search_previous) {

void EditorHelp::_class_desc_finished() {
if (scroll_to >= 0) {
class_desc->scroll_to_paragraph(scroll_to);
class_desc->connect("draw", callable_mp(class_desc, &RichTextLabel::scroll_to_paragraph).bind(scroll_to), CONNECT_ONE_SHOT | CONNECT_DEFERRED);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
class_desc->connect("draw", callable_mp(class_desc, &RichTextLabel::scroll_to_paragraph).bind(scroll_to), CONNECT_ONE_SHOT | CONNECT_DEFERRED);
class_desc->connect(SceneStringName(draw), callable_mp(class_desc, &RichTextLabel::scroll_to_paragraph).bind(scroll_to), CONNECT_ONE_SHOT | CONNECT_DEFERRED);

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if a call_deferred() is enough now, without connect to the draw signal.

Copy link
Member

Choose a reason for hiding this comment

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

Thread can't directly update scrollbars, so it is done in the draw. This change is correct (scrolling after finished and first redraw), but we might want to add another signal instead of directly connecting to the draw (finished probably should not be changed, since other code might expect it to fire even for hidden RTL that will never redraw).

Copy link
Member

Choose a reason for hiding this comment

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

@ydeltastar WDYT about the above suggestion? Do you want to implement that?

Copy link
Contributor Author

@ydeltastar ydeltastar Dec 18, 2024

Choose a reason for hiding this comment

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

Sounds good. I added a signal that triggers after loading, processing, and validation for drawing. It also needed an equivalent method for is_finished() so the EditorHelp could use the signal correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm very perplexed on the addition of another signal. It sounds "needlessly" confusing. I'd be wary as developers may use one or the other without understanding the difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, all it does is simulate a one-shot connection to draw. It is very specific, can only happen in the first draw after finished so it could be just a note in the documentation as well.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe you can connect to finished and then in the callback connect to draw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's what I did in the first iteration. I reverted the PR to it and added a note to the finished signal.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, simpler solutions are better. No point in adding a signal if it does the same.

@akien-mga
Copy link
Member

akien-mga commented Dec 10, 2024

Same fix as #90035 but for a different code path.

Seems like this was changed further in #96449.

It's starting to look like a game of whac-a-mole....

CC @Maran23 @KoBeWi @kitbdev

@Maran23
Copy link
Contributor

Maran23 commented Dec 10, 2024

Seems like this was changed further in #96449.

It's starting to look like a game of whac-a-mole....

CC @Maran23 @KoBeWi @kitbdev

I think the problem is in the RTL control, as when it finished, I expect that the scrolling will always work. But it does not.

Why it happens sometimes for the RTL control is not clear, I also start to wonder if this might be related to the refresh rate of the screen as suggested in the issue. I have a 240 Hz screen and never got this issue after my fix again.

My fix removed code that was calling the whole help logic twice, so it fixed a problem, but the scrolling is still not stable (enough). For now, I wonder if simply calling call_deferred() is enough here, doing the scrolling at the end of the frame.

EDIT: What is weird is that the finished signal is called, then the vscroll might get hidden, then queue_redraw is called. I wonder, if we rather want to emit the finished signal after the redraw instead (Or at least after _validate_line_caches is called, which seems to be done right after).

@passivestar
Copy link
Contributor

I also start to wonder if this might be related to the refresh rate of the screen as suggested in the issue. I have a 240 Hz screen and never got this issue after my fix again

I use a 120hz one. I get it every time I use search in dev6

@ydeltastar
Copy link
Contributor Author

ydeltastar commented Dec 10, 2024

Seems like this was changed further in #96449.

From what I debugged, #90035 didn't fix the issue because the offsets were already calculated in that code path. Having it or reverting it didn't have any effect. I think it is good to have it connected to draw too as a guarantee anyway.

This PR affects another code path when the documentation is loaded and processed for the first time. When scroll_to_paragraph is called, the offsets aren't calculated yet.

My fix removed code that was calling the whole help logic twice, so it fixed a problem, but the scrolling is still not stable (enough). For now, I wonder if simply calling call_deferred() is enough here, doing the scrolling at the end of the frame.

EDIT: What is weird is that the finished signal is called, then the vscroll might get hidden, then queue_redraw is called. I wonder, if we rather want to emit the finished signal after the redraw instead (Or at least after _validate_line_caches is called, which seems to be done right after).

Yes, the main issue is that RichTextLabel.finished can be emitted before the offsets are calculated in _validate_line_caches which happens in NOTIFICATION_DRAW.

// Start text shaping.
if (_validate_line_caches()) {
set_physics_process_internal(false); // Disable auto refresh, if text is fully processed.
} else {

I think it makes sense since these calculations are dependent on theme changes and only relevant when drawing. So connecting to the draw signal which happens after NOTIFICATION_DRAW sounds like the best fix here.

@akien-mga
Copy link
Member

Note that AFAIK, the RichTextLabel for the editor help updates on a thread, so there might be race conditions. CC @bruvzg

@Maran23
Copy link
Contributor

Maran23 commented Dec 10, 2024

@passivestar Does CTRL+Left Click works for you?

@passivestar
Copy link
Contributor

@passivestar Does CTRL+Left Click works for you?

yeah it does

@ydeltastar ydeltastar force-pushed the fix-doc-scroll branch 2 times, most recently from bb481c0 to f87ba44 Compare December 18, 2024 00:09
@ydeltastar ydeltastar requested review from a team as code owners December 18, 2024 00:09
Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

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

Fixes the bug.

@Repiteo Repiteo merged commit b987e90 into godotengine:master Dec 30, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Dec 30, 2024

Thanks!

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.

Editor help doesn't scroll to where it should
9 participants