From f3cdb9bfeb01cf3f7469201968172562deaef865 Mon Sep 17 00:00:00 2001 From: Marcus Nilsson Date: Thu, 8 Jul 2021 21:40:58 +0200 Subject: [PATCH] PixelPaint: Only scroll into view in LayerListWidget when needed This makes sure that scroll_into_view is not called when not necessary, or when m_layers is empty, which previously caused a crash upon removing the last layer. --- Userland/Applications/PixelPaint/LayerListWidget.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/PixelPaint/LayerListWidget.cpp b/Userland/Applications/PixelPaint/LayerListWidget.cpp index d048f2dcd7..fbf6ac39de 100644 --- a/Userland/Applications/PixelPaint/LayerListWidget.cpp +++ b/Userland/Applications/PixelPaint/LayerListWidget.cpp @@ -310,12 +310,18 @@ void LayerListWidget::set_selected_layer(Layer* layer) { if (!m_image) return; - for (size_t i = 0; i < m_image->layer_count(); ++i) - m_image->layer(i).set_selected(layer == &m_image->layer(i)); + for (size_t i = 0; i < m_image->layer_count(); ++i) { + if (layer == &m_image->layer(i)) { + m_image->layer(i).set_selected(true); + scroll_into_view(m_gadgets[i].rect, false, true); + m_selected_layer_index = i; + } else { + m_image->layer(i).set_selected(false); + } + } if (on_layer_select) on_layer_select(layer); - scroll_into_view(m_gadgets[m_selected_layer_index].rect, false, true); update(); }