@@ -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);
@@ -698,19 +701,21 @@ void FileSystemDock::_set_current_path_line_edit_text(const String &p_path) {
698
701
}
699
702
700
703
void FileSystemDock::_navigate_to_path (const String &p_path, bool p_select_in_favorites) {
704
+ bool is_directory = false ;
701
705
if (p_path == " Favorites" ) {
702
706
current_path = p_path;
703
707
} else {
704
708
String target_path = p_path;
705
709
// If the path is a file, do not only go to the directory in the tree, also select the file in the file list.
706
710
if (target_path.ends_with (" /" )) {
707
- target_path = target_path.substr ( 0 , target_path. length () - 1 );
711
+ target_path = target_path.trim_suffix ( " / " );
708
712
}
709
713
Ref<DirAccess> da = DirAccess::create (DirAccess::ACCESS_RESOURCES);
710
714
if (da->file_exists (p_path)) {
711
715
current_path = target_path;
712
716
} else if (da->dir_exists (p_path)) {
713
717
current_path = target_path + " /" ;
718
+ is_directory = true ;
714
719
} else {
715
720
ERR_FAIL_MSG (vformat (" Cannot navigate to '%s' as it has not been found in the file system!" , p_path));
716
721
}
@@ -719,17 +724,56 @@ void FileSystemDock::_navigate_to_path(const String &p_path, bool p_select_in_fa
719
724
_set_current_path_line_edit_text (current_path);
720
725
_push_to_history ();
721
726
722
- _update_tree (get_uncollapsed_paths (), false , p_select_in_favorites, true );
727
+ const String file_name = is_directory ? p_path.trim_suffix (" /" ).get_file () + " /" : p_path.get_file ();
728
+ bool found = false ;
729
+
730
+ TreeItem **base_dir_ptr;
731
+ {
732
+ const String base_dir = current_path.get_base_dir ();
733
+ if (base_dir == " res://" ) {
734
+ base_dir_ptr = folder_map.getptr (base_dir);
735
+ } else if (is_directory) {
736
+ base_dir_ptr = folder_map.getptr (base_dir.get_base_dir () + " /" );
737
+ } else {
738
+ base_dir_ptr = folder_map.getptr (base_dir + " /" );
739
+ }
740
+ }
741
+
742
+ if (base_dir_ptr) {
743
+ TreeItem *directory = *base_dir_ptr;
744
+ {
745
+ TreeItem *entry = directory->get_first_child ();
746
+ while (entry) {
747
+ if (entry->get_metadata (0 ).operator String ().ends_with (file_name)) {
748
+ tree->deselect_all ();
749
+ entry->select (0 );
750
+ found = true ;
751
+ break ;
752
+ }
753
+ entry = entry->get_next ();
754
+ }
755
+ }
756
+
757
+ while (directory) {
758
+ directory->set_collapsed (false );
759
+ directory = directory->get_parent ();
760
+ }
761
+ }
762
+
763
+ if (!found) {
764
+ return ;
765
+ }
766
+
767
+ tree->ensure_cursor_is_visible ();
723
768
if (display_mode != DISPLAY_MODE_TREE_ONLY) {
724
769
_update_file_list (false );
725
770
726
771
// Reset the scroll for a directory.
727
- if (p_path. ends_with ( " / " ) ) {
772
+ if (is_directory ) {
728
773
files->get_v_scroll_bar ()->set_value (0 );
729
774
}
730
775
}
731
776
732
- String file_name = p_path.get_file ();
733
777
if (!file_name.is_empty ()) {
734
778
for (int i = 0 ; i < files->get_item_count (); i++) {
735
779
if (files->get_item_text (i) == file_name) {
0 commit comments