Skip to content

Fix region folding not loading properly#110946

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
KoBeWi:regions_of_ruin
Oct 1, 2025
Merged

Fix region folding not loading properly#110946
Repiteo merged 1 commit into
godotengine:masterfrom
KoBeWi:regions_of_ruin

Conversation

@KoBeWi
Copy link
Copy Markdown
Member

@KoBeWi KoBeWi commented Sep 26, 2025

Fixes #96370
Fixes #85780

ScriptTextEditor has a nice optimization™ that makes the script instances not fully loaded on startup. It loads the script, but does not initialize the CodeEdit until you switch tab, which makes it faster to restore scripts (similar to #110183).

The problem is that the editor also tried to restore script's state before it was enabled (i.e. initialized). So it went over folded lines and tried to fold them, but thanks to the aforementioned nice optimization™, it did not recognize that the folded lines are code regions (the language features were not fully loaded yet) and failed to fold them. Then the editor for whatever reason will immediately overwrite its stored state, so the folding is gone forever. It did work "sometimes", because the first script tab is initialized earlier for whatever reason.

This PR introduces pending_state. If editor tries to restore CodeEditor's state while it's not yet initialized, the state is stored in a variable and applied once the editor is fully initialized.

@KoBeWi KoBeWi added this to the 4.6 milestone Sep 26, 2025
@KoBeWi KoBeWi requested a review from a team as a code owner September 26, 2025 21:30
@KoBeWi KoBeWi added bug topic:editor cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release labels Sep 26, 2025
Copy link
Copy Markdown
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.

Makes sense, fixes the issue.

I have been thinking about refactoring this optimization to be on the ScriptEditor side so that ScriptTextEditor wouldn't have a half-loaded state and so it works on other text files too.

@Repiteo Repiteo merged commit ac65df5 into godotengine:master Oct 1, 2025
20 checks passed
@Repiteo
Copy link
Copy Markdown
Contributor

Repiteo commented Oct 1, 2025

Thanks!

@KoBeWi KoBeWi deleted the regions_of_ruin branch October 1, 2025 09:28
@akien-mga akien-mga removed the cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release label Jan 16, 2026
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 region folding is not remembered for some scripts Script Editor's folded lines are oftentimes forgotten between editor restarts.

4 participants