From 54a19f1d126c32e6e7a273b5e29c21ab00c3a951 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Fri, 21 Jun 2024 09:09:39 +0900 Subject: [PATCH] Fix issue #2359: Selected files changes on expanding a folder that is upper on the tree --- Src/DirView.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Src/DirView.cpp b/Src/DirView.cpp index ae70654e0dd..dae284b7ffc 100644 --- a/Src/DirView.cpp +++ b/Src/DirView.cpp @@ -1253,6 +1253,8 @@ void CDirView::ExpandSubdir(int sel, bool bRecursive) m_pList->SetRedraw(FALSE); // Turn off updating (better performance) + size_t oldItemCount = m_listViewItems.size(); + CDiffContext &ctxt = GetDiffContext(); dip.customFlags |= ViewCustomFlags::EXPANDED; if (bRecursive) @@ -1265,8 +1267,18 @@ void CDirView::ExpandSubdir(int sel, bool bRecursive) SortColumnsAppropriately(); + if (m_pList->GetNextItem(sel, LVNI_SELECTED) != -1) + { + LVITEM lvi {0, sel + 1}; + for (size_t i = 0; i < m_listViewItems.size() - oldItemCount; i++) + m_pList->InsertItem(&lvi); + } + else + { + m_pList->SetItemCountEx(static_cast(m_listViewItems.size()), LVSICF_NOSCROLL); + } + m_pList->SetRedraw(TRUE); // Turn updating back on - m_pList->SetItemCountEx(static_cast(m_listViewItems.size()), LVSICF_NOSCROLL); m_pList->Invalidate(); }