@@ -245,6 +245,8 @@ void FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
245
245
}
246
246
subdirectory_item->set_selectable (0 , true );
247
247
subdirectory_item->set_metadata (0 , lpath);
248
+ folder_map[lpath] = subdirectory_item;
249
+
248
250
if (!p_select_in_favorites && (current_path == lpath || ((display_mode != DISPLAY_MODE_TREE_ONLY) && current_path.get_base_dir () == lpath))) {
249
251
subdirectory_item->select (0 );
250
252
// Keep select an item when re-created a tree
@@ -371,6 +373,7 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo
371
373
tree_update_id++;
372
374
updating_tree = true ;
373
375
TreeItem *root = tree->create_item ();
376
+ folder_map.clear ();
374
377
375
378
// Handles the favorites.
376
379
favorites_item = tree->create_item (root);
@@ -702,19 +705,21 @@ void FileSystemDock::_set_current_path_line_edit_text(const String &p_path) {
702
705
}
703
706
704
707
void FileSystemDock::_navigate_to_path (const String &p_path, bool p_select_in_favorites) {
708
+ bool is_directory = false ;
705
709
if (p_path == " Favorites" ) {
706
710
current_path = p_path;
707
711
} else {
708
712
String target_path = p_path;
709
713
// If the path is a file, do not only go to the directory in the tree, also select the file in the file list.
710
714
if (target_path.ends_with (" /" )) {
711
- target_path = target_path.substr ( 0 , target_path. length () - 1 );
715
+ target_path = target_path.trim_suffix ( " / " );
712
716
}
713
717
Ref<DirAccess> da = DirAccess::create (DirAccess::ACCESS_RESOURCES);
714
718
if (da->file_exists (p_path)) {
715
719
current_path = target_path;
716
720
} else if (da->dir_exists (p_path)) {
717
721
current_path = target_path + " /" ;
722
+ is_directory = true ;
718
723
} else {
719
724
ERR_FAIL_MSG (vformat (" Cannot navigate to '%s' as it has not been found in the file system!" , p_path));
720
725
}
@@ -723,17 +728,56 @@ void FileSystemDock::_navigate_to_path(const String &p_path, bool p_select_in_fa
723
728
_set_current_path_line_edit_text (current_path);
724
729
_push_to_history ();
725
730
726
- _update_tree (get_uncollapsed_paths (), false , p_select_in_favorites, true );
731
+ const String file_name = is_directory ? p_path.trim_suffix (" /" ).get_file () + " /" : p_path.get_file ();
732
+ bool found = false ;
733
+
734
+ TreeItem **base_dir_ptr;
735
+ {
736
+ const String base_dir = current_path.get_base_dir ();
737
+ if (base_dir == " res://" ) {
738
+ base_dir_ptr = folder_map.getptr (base_dir);
739
+ } else if (is_directory) {
740
+ base_dir_ptr = folder_map.getptr (base_dir.get_base_dir () + " /" );
741
+ } else {
742
+ base_dir_ptr = folder_map.getptr (base_dir + " /" );
743
+ }
744
+ }
745
+
746
+ if (base_dir_ptr) {
747
+ TreeItem *directory = *base_dir_ptr;
748
+ {
749
+ TreeItem *entry = directory->get_first_child ();
750
+ while (entry) {
751
+ if (entry->get_metadata (0 ).operator String ().ends_with (file_name)) {
752
+ tree->deselect_all ();
753
+ entry->select (0 );
754
+ found = true ;
755
+ break ;
756
+ }
757
+ entry = entry->get_next ();
758
+ }
759
+ }
760
+
761
+ while (directory) {
762
+ directory->set_collapsed (false );
763
+ directory = directory->get_parent ();
764
+ }
765
+ }
766
+
767
+ if (!found) {
768
+ return ;
769
+ }
770
+
771
+ tree->ensure_cursor_is_visible ();
727
772
if (display_mode != DISPLAY_MODE_TREE_ONLY) {
728
773
_update_file_list (false );
729
774
730
775
// Reset the scroll for a directory.
731
- if (p_path. ends_with ( " / " ) ) {
776
+ if (is_directory ) {
732
777
files->get_v_scroll_bar ()->set_value (0 );
733
778
}
734
779
}
735
780
736
- String file_name = p_path.get_file ();
737
781
if (!file_name.is_empty ()) {
738
782
for (int i = 0 ; i < files->get_item_count (); i++) {
739
783
if (files->get_item_text (i) == file_name) {
0 commit comments