From 4d3224a9cbd015c47067fdf0d42ab2f9a4eaf6a1 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 4 Dec 2020 13:38:38 +0000 Subject: [PATCH] Fix off-by-one error when deleting single marker. Fixes https://gitlab.com/kicad/code/kicad/issues/6625 --- common/rc_item.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/common/rc_item.cpp b/common/rc_item.cpp index f216355694..d148431cf8 100644 --- a/common/rc_item.cpp +++ b/common/rc_item.cpp @@ -446,7 +446,7 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo return; int lastGood = -1; - bool found = false; + bool itemDeleted = false; if( m_view ) { @@ -461,11 +461,11 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo MARKER_BASE* marker = rcItem->GetParent(); bool excluded = marker ? marker->IsExcluded() : false; + if( aCurrentOnly && itemDeleted && lastGood >= 0 ) + break; + if( aCurrentOnly && rcItem != current_item ) { - if( found && lastGood >= 0 ) - break; - lastGood = i; continue; } @@ -473,8 +473,6 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo if( excluded && !aIncludeExclusions ) continue; - found = true; - if( i < (int) m_tree.size() ) // Careful; tree is truncated for large datasets { wxDataViewItem markerItem = ToItem( m_tree[i] ); @@ -498,6 +496,11 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo // Only deep delete the current item here; others will be done through the // DeleteAllItems() call below, which is more efficient. m_rcItemsProvider->DeleteItem( i, aDeep && aCurrentOnly ); + + if( lastGood > i ) + lastGood--; + + itemDeleted = true; } if( m_view && aCurrentOnly && lastGood >= 0 )