From 3dd91d24c2c9222c6585eea5762d25fd380f31f6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 3 May 2020 21:02:06 +0200 Subject: [PATCH] Slightly simplify proposed drop index determination No real changes, just reorganize the code in a way that should hopefully be more clear to understand. --- src/generic/datavgen.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 0bf03c6c78..2bfc52a380 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -2233,15 +2233,25 @@ wxDataViewMainWindow::DropItemInfo wxDataViewMainWindow::GetDropItemInfo(const w if (m_owner->GetModel()->IsContainer(ascendNode->GetItem())) { // Item can be inserted + dropItemInfo.m_item = ascendNode->GetItem(); int itemPosition = ascendNode->FindChildByItem(prevAscendNode->GetItem()); - dropItemInfo.m_proposedDropIndex = itemPosition == wxNOT_FOUND ? 0 : itemPosition + 1; - dropItemInfo.m_item = ascendNode->GetItem(); + if ( itemPosition == wxNOT_FOUND ) + itemPosition = 0; + else + itemPosition++; - // We must break the loop if the applied node is expanded (opened) - // and the proposed drop position is not the last in this node - if (ascendNode->IsOpen() && dropItemInfo.m_proposedDropIndex != static_cast(ascendNode->GetChildNodes().size())) - break; + dropItemInfo.m_proposedDropIndex = itemPosition; + + // We must break the loop if the applied node is expanded + // (opened) and the proposed drop position is not the last + // in this node. + if ( ascendNode->IsOpen() ) + { + const size_t lastPos = ascendNode->GetChildNodes().size(); + if ( static_cast(itemPosition) != lastPos ) + break; + } int indent = GetOwner()->GetIndent()*level + expanderWidth;