reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 783b091154aa82fa55943c3d6cde036e4a0b63df
parent 789f191649cb6860c7727ec298b55c5b15060e42
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun, 27 Aug 2017 21:09:49 -0400

browser: wait until the list is sorted before restoring selection

This fixes the scrolling position not being correctly restored on macOS
since commit c192c4f5fd2700a8094cf5adfbdee1a8cb9bb40b.

Diffstat:
Msrc/browser.cpp | 22++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/browser.cpp b/src/browser.cpp @@ -517,10 +517,11 @@ void Browser::fillList() const int scroll = m_list->scroll(); - const vector<int> selectedIndexes = m_list->selection(); - vector<const Entry *> oldSelection(selectedIndexes.size()); - for(size_t i = 0; i < selectedIndexes.size(); i++) - oldSelection[i] = (Entry *)m_list->row(selectedIndexes[i])->userData; + vector<int> selectIndexes = m_list->selection(); + vector<const Entry *> oldSelection(selectIndexes.size()); + for(size_t i = 0; i < selectIndexes.size(); i++) + oldSelection[i] = (Entry *)m_list->row(selectIndexes[i])->userData; + selectIndexes.clear(); // will put new indexes below m_list->clear(); m_list->reserveRows(m_entries.size()); @@ -529,19 +530,24 @@ void Browser::fillList() if(!match(entry)) continue; - const auto &matchingEntryIt = find_if(oldSelection.begin(), oldSelection.end(), - [&entry] (const Entry *oldEntry) { return *oldEntry == entry; }); - auto row = m_list->createRow((void *)&entry); entry.updateRow(row); + const auto &matchingEntryIt = find_if(oldSelection.begin(), oldSelection.end(), + [&entry] (const Entry *oldEntry) { return *oldEntry == entry; }); + if(matchingEntryIt != oldSelection.end()) - m_list->select(row->index()); + selectIndexes.push_back(row->index()); } m_list->setScroll(scroll); m_list->sort(); + // restore selection only after having sorted the table + // in order to get the same scroll position as before if possible + for(const int index : selectIndexes) + m_list->select(index); + updateDisplayLabel(); }