From 0252be370ea7d2c6437995af36521bc5c32f73d9 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Fri, 3 Apr 2026 02:57:15 +1100 Subject: [PATCH] fix: delegate size not being tracked after rearrange --- .../src/Caelestia/Components/lazylistview.cpp | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/plugin/src/Caelestia/Components/lazylistview.cpp b/plugin/src/Caelestia/Components/lazylistview.cpp index d1e2570c..d4baab49 100644 --- a/plugin/src/Caelestia/Components/lazylistview.cpp +++ b/plugin/src/Caelestia/Components/lazylistview.cpp @@ -574,23 +574,26 @@ LazyListView::DelegateEntry LazyListView::createDelegate(int modelIndex) { entry.item->setWidth(width()); m_delegate->completeCreate(); - // Shared height-change handler - auto onHeightChanged = [this, modelIndex] { - if (!m_delegates.contains(modelIndex)) + // Shared height-change handler — captures item pointer instead of index + // so it remains valid after model inserts/removes/moves shift indices. + auto onHeightChanged = [this, item = entry.item] { + // Find the delegate entry by item pointer + for (auto it = m_delegates.begin(); it != m_delegates.end(); ++it) { + if (it->item != item) + continue; + const int idx = it.key(); + const qreal h = delegateHeight(item); + if (idx < static_cast(m_layout.size()) && !qFuzzyCompare(m_layout[idx].height, h)) { + const qreal oldH = m_layout[idx].height; + const bool wasKnown = m_layout[idx].heightKnown; + m_layout[idx].height = h; + m_layout[idx].heightKnown = true; + if (wasKnown) + untrackHeight(oldH); + trackHeight(h); + polish(); + } return; - auto& e = m_delegates[modelIndex]; - if (!e.item) - return; - const qreal h = delegateHeight(e.item); - if (modelIndex < static_cast(m_layout.size()) && !qFuzzyCompare(m_layout[modelIndex].height, h)) { - const qreal oldH = m_layout[modelIndex].height; - const bool wasKnown = m_layout[modelIndex].heightKnown; - m_layout[modelIndex].height = h; - m_layout[modelIndex].heightKnown = true; - if (wasKnown) - untrackHeight(oldH); - trackHeight(h); - polish(); } };