diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 286d406c3f4..d2a740ad81b 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -5158,6 +5158,10 @@ void CEditor::RenderFileDialog() Ui()->DoLabel(&PathBox, aBuf, 10.0f, TEXTALIGN_ML); } + // filebox + static CListBox s_ListBox; + s_ListBox.SetActive(!Ui()->IsPopupOpen()); + const auto &&UpdateFileNameInput = [this]() { if(m_FilesSelectedIndex >= 0 && !m_vpFilteredFileList[m_FilesSelectedIndex]->m_IsDir) { @@ -5168,10 +5172,22 @@ void CEditor::RenderFileDialog() else m_FileDialogFileNameInput.Clear(); }; - - // filebox - static CListBox s_ListBox; - s_ListBox.SetActive(!Ui()->IsPopupOpen()); + const auto &&UpdateSelectedIndex = [&]() { + m_FilesSelectedIndex = -1; + m_aFilesSelectedName[0] = '\0'; + // find first valid entry, if it exists + for(size_t i = 0; i < m_vpFilteredFileList.size(); i++) + { + if(str_comp_nocase(m_vpFilteredFileList[i]->m_aName, m_FileDialogFileNameInput.GetString()) == 0) + { + m_FilesSelectedIndex = i; + str_copy(m_aFilesSelectedName, m_vpFilteredFileList[i]->m_aName); + break; + } + } + if(m_FilesSelectedIndex >= 0) + s_ListBox.ScrollToSelected(); + }; if(m_FileDialogSaveAction) { @@ -5187,24 +5203,17 @@ void CEditor::RenderFileDialog() --i; } } - m_FilesSelectedIndex = -1; - m_aFilesSelectedName[0] = '\0'; - // find first valid entry, if it exists - for(size_t i = 0; i < m_vpFilteredFileList.size(); i++) - { - if(str_comp_nocase(m_vpFilteredFileList[i]->m_aName, m_FileDialogFileNameInput.GetString()) == 0) - { - m_FilesSelectedIndex = i; - str_copy(m_aFilesSelectedName, m_vpFilteredFileList[i]->m_aName); - break; - } - } - if(m_FilesSelectedIndex >= 0) - s_ListBox.ScrollToSelected(); + UpdateSelectedIndex(); } if(m_FileDialogOpening) + { Ui()->SetActiveItem(&m_FileDialogFileNameInput); + if(!m_FileDialogFileNameInput.IsEmpty()) + { + UpdateSelectedIndex(); + } + } } else {