commit 7e469f48f80f4a350120518d8674c6c2c32f83f3
parent 0c2620cd9eb7beff563879bf615eb6a095c7ebf9
Author: cfillion <cfillion@users.noreply.github.com>
Date: Wed, 24 Aug 2016 16:48:46 -0400
browser: remember scroll position when reloading the list on windows
Diffstat:
3 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/src/browser.cpp b/src/browser.cpp
@@ -651,6 +651,8 @@ void Browser::fillList()
{
InhibitControl freeze(m_list);
+ const int scroll = m_list->scroll();
+
// store the indexes to the selected entries if they still exists
// and m_visibleEntries hasn't been emptied
const vector<int> selection = m_list->selection();
@@ -675,6 +677,7 @@ void Browser::fillList()
m_visibleEntries.push_back(i);
}
+ m_list->setScroll(scroll);
m_list->sort();
updateDisplayLabel();
diff --git a/src/listview.cpp b/src/listview.cpp
@@ -278,6 +278,26 @@ int ListView::itemUnderMouse() const
return translateBack(info.iItem);
}
+int ListView::scroll() const
+{
+ return ListView_GetTopIndex(handle());
+}
+
+void ListView::setScroll(const int index)
+{
+#ifdef ListView_GetItemPosition
+ if(index < 0)
+ return;
+
+ RECT rect;
+ ListView_GetViewRect(handle(), &rect);
+
+ POINT itemPos{};
+ if(ListView_GetItemPosition(handle(), index - 1, &itemPos))
+ ListView_Scroll(handle(), abs(rect.left) + itemPos.x, abs(rect.top) + itemPos.y);
+#endif
+}
+
void ListView::onNotify(LPNMHDR info, LPARAM lParam)
{
switch(info->code) {
diff --git a/src/listview.hpp b/src/listview.hpp
@@ -66,6 +66,8 @@ public:
void reset();
int currentIndex() const;
int itemUnderMouse() const;
+ int scroll() const;
+ void setScroll(int);
void setSelected(int index, bool select);
void select(int index) { setSelected(index, true); }