diff options
author | Yuri Sizov <yuris@humnom.net> | 2023-11-03 12:52:20 +0100 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-11-03 12:52:20 +0100 |
commit | 330d22e99a43517a024f5db099dd864f16017191 (patch) | |
tree | 52ab96dc305843701b3d730aba3711d307f92b51 /editor/filesystem_dock.cpp | |
parent | 64d20e0ebf77c8e496b4ba6a924e29b891665a22 (diff) | |
parent | 7fea0cef4cf4fd60456ebf84812c78c8c2acbde2 (diff) | |
download | redot-engine-330d22e99a43517a024f5db099dd864f16017191.tar.gz |
Merge pull request #84217 from SaracenOne/fix_filesystem_rename_crash
Fix file rename crash after toggling split mode.
Diffstat (limited to 'editor/filesystem_dock.cpp')
-rw-r--r-- | editor/filesystem_dock.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 0aa8ef66e7..944da47242 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -88,6 +88,7 @@ void FileSystemList::_line_editor_submit(String p_text) { bool FileSystemList::edit_selected() { ERR_FAIL_COND_V_MSG(!is_anything_selected(), false, "No item selected."); int s = get_current(); + ERR_FAIL_COND_V_MSG(s < 0, false, "No current item selected."); ensure_current_is_visible(); Rect2 rect; @@ -907,12 +908,13 @@ void FileSystemDock::_sort_file_info_list(List<FileSystemDock::FileInfo> &r_file } void FileSystemDock::_update_file_list(bool p_keep_selection) { - // Register the previously selected items. - HashSet<String> cselection; + // Register the previously current and selected items. + HashSet<String> previous_selection; + HashSet<int> valid_selection; if (p_keep_selection) { for (int i = 0; i < files->get_item_count(); i++) { if (files->is_selected(i)) { - cselection.insert(files->get_item_text(i)); + previous_selection.insert(files->get_item_text(i)); } } } @@ -1068,8 +1070,9 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { Color this_folder_color = has_custom_color ? folder_colors[assigned_folder_colors[dpath]] : inherited_folder_color; files->set_item_icon_modulate(-1, editor_is_dark_theme ? this_folder_color : this_folder_color * 1.75); - if (cselection.has(dname)) { + if (previous_selection.has(dname)) { files->select(files->get_item_count() - 1, false); + valid_selection.insert(files->get_item_count() - 1); } } } @@ -1142,8 +1145,9 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { } // Select the items. - if (cselection.has(fname)) { + if (previous_selection.has(fname)) { files->select(item_index, false); + valid_selection.insert(item_index); } if (!p_keep_selection && !file.is_empty() && fname == file) { @@ -1159,6 +1163,11 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { } files->set_item_tooltip(item_index, tooltip); } + + // If we only have any selected items retained, we need to update the current idx. + if (!valid_selection.is_empty()) { + files->set_current(*valid_selection.begin()); + } } void FileSystemDock::_select_file(const String &p_path, bool p_select_in_favorites) { |