Repository: godotengine/godot (language: cpp)

Issue:
Reopening Godot with FileSystem filter active expands the filesystem tree
### Tested versions

Reproducible in v4.4.dev.mono.custom_build [11e7bf844], 4.4-dev6, 4.4-dev5

Not reproducible in v4.4-dev4

### System information

Godot v4.4.dev.mono (11e7bf844) - Ubuntu 24.04.1 LTS 24.04 on Wayland - X11 display driver, Multi-window, 3 monitors - Vulkan (Forward+) - integrated AMD Radeon Graphics (RADV RENOIR) - AMD Ryzen 7 5800H with Radeon Graphics (16 threads)

### Issue description

When closing Godot while a FileSystem filter is active it expands some unrelated folders. 

After some playing around it seems like all folders are expanded where the content matches any prefix of the search-string.
Let's say the filter is set to 'test'. If now Godot is reopened, all folders containing files matching 't', 'te', 'tes' or 'test' are expanded (which is basically everything because of '.tscn').

### Steps to reproduce

Open a project with some folders. Search for 'test' in the FileSystem dock. Close Godot and reopen it. Now all folders containing .tscn files are expanded.

### Minimal reproduction project (MRP)

N/A


Discussion / hints:
I can reproduce, i'll bisect rn.
Bisected to #95107, @KoBeWi 

![Image](https://github.com/user-attachments/assets/a9068ee6-e977-4a04-866a-43e5ef84d63f)

<br>

While testing this issue i noticed before #95107 the filesystem had other two similar bugs, consider a project with this files:

![Image](https://github.com/user-attachments/assets/cfc9e26f-6ca5-43c3-bff6-122c003f2150)

<br>

Before #95107:

If you type a character/word without any match in the filesystem filter (example: "z") with all folders open and restart, all the folders will appear closed.
If you type a word with a partial match (example: fife) with all folders closed and restart, nothing happens.
If you a word that fully match the files in the filter (example: "file") with all folders closed and restart, all the folders will appear open.


After #95107:

If you type a character/word without any match in the filesystem filter (example: "z") with all folders open and restart, nothing happens.
If you type a word with a partial match (example: fife) with all folders closed and restart, all the folders will be open (this issue).
If you a word that fully match the files in the filter (example: "file") with all folders closed and restart, all the folders will be open.

Fix patch:
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index 9bf21a543884..c53b5f692cd1 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -3991,7 +3991,7 @@ void FileSystemDock::save_layout_to_config(Ref<ConfigFile> p_layout, const Strin
 	PackedStringArray selected_files = get_selected_paths();
 	p_layout->set_value(p_section, "dock_filesystem_selected_paths", selected_files);
 	Vector<String> uncollapsed_paths = get_uncollapsed_paths();
-	p_layout->set_value(p_section, "dock_filesystem_uncollapsed_paths", uncollapsed_paths);
+	p_layout->set_value(p_section, "dock_filesystem_uncollapsed_paths", searched_tokens.is_empty() ? uncollapsed_paths : uncollapsed_paths_before_search);
 }
 
 void FileSystemDock::load_layout_from_config(Ref<ConfigFile> p_layout, const String &p_section) {


Test patch: