From d64d2e4d09ecd343e07b9f066a0185578bd8eb48 Mon Sep 17 00:00:00 2001 From: speles Date: Mon, 1 Mar 2021 23:32:27 +0200 Subject: [PATCH] LibGUI: Scroll selection into view when the IconView is first laid out If we set selection before the IconView is laid out, it has no size. So it can't correctly calculate where to scroll. Forcing scroll after the first resize fixes that. --- Userland/Libraries/LibGUI/IconView.cpp | 6 ++++++ Userland/Libraries/LibGUI/IconView.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Userland/Libraries/LibGUI/IconView.cpp b/Userland/Libraries/LibGUI/IconView.cpp index 5308aa077c..9179c4d06b 100644 --- a/Userland/Libraries/LibGUI/IconView.cpp +++ b/Userland/Libraries/LibGUI/IconView.cpp @@ -72,6 +72,12 @@ void IconView::resize_event(ResizeEvent& event) { AbstractView::resize_event(event); update_content_size(); + + if (!m_had_valid_size) { + m_had_valid_size = true; + if (!selection().is_empty()) + scroll_into_view(selection().first()); + } } void IconView::reinit_item_cache() const diff --git a/Userland/Libraries/LibGUI/IconView.h b/Userland/Libraries/LibGUI/IconView.h index ecc895f645..dcc0d964f3 100644 --- a/Userland/Libraries/LibGUI/IconView.h +++ b/Userland/Libraries/LibGUI/IconView.h @@ -182,6 +182,8 @@ private: mutable bool m_item_data_cache_valid { false }; bool m_changing_selection { false }; + + bool m_had_valid_size { false }; }; }