Fix region folding not loading properly#110946
Merged
Merged
Conversation
kitbdev
approved these changes
Sep 28, 2025
Contributor
kitbdev
left a comment
There was a problem hiding this comment.
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.
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.