Fix off-by-one error when deleting single marker.

Fixes https://gitlab.com/kicad/code/kicad/issues/6625
This commit is contained in:
Jeff Young 2020-12-04 13:38:38 +00:00
parent f3e1ac8dbe
commit 4d3224a9cb
1 changed files with 9 additions and 6 deletions

View File

@ -446,7 +446,7 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo
return; return;
int lastGood = -1; int lastGood = -1;
bool found = false; bool itemDeleted = false;
if( m_view ) if( m_view )
{ {
@ -461,11 +461,11 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo
MARKER_BASE* marker = rcItem->GetParent(); MARKER_BASE* marker = rcItem->GetParent();
bool excluded = marker ? marker->IsExcluded() : false; bool excluded = marker ? marker->IsExcluded() : false;
if( aCurrentOnly && itemDeleted && lastGood >= 0 )
break;
if( aCurrentOnly && rcItem != current_item ) if( aCurrentOnly && rcItem != current_item )
{ {
if( found && lastGood >= 0 )
break;
lastGood = i; lastGood = i;
continue; continue;
} }
@ -473,8 +473,6 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo
if( excluded && !aIncludeExclusions ) if( excluded && !aIncludeExclusions )
continue; continue;
found = true;
if( i < (int) m_tree.size() ) // Careful; tree is truncated for large datasets if( i < (int) m_tree.size() ) // Careful; tree is truncated for large datasets
{ {
wxDataViewItem markerItem = ToItem( m_tree[i] ); 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 // Only deep delete the current item here; others will be done through the
// DeleteAllItems() call below, which is more efficient. // DeleteAllItems() call below, which is more efficient.
m_rcItemsProvider->DeleteItem( i, aDeep && aCurrentOnly ); m_rcItemsProvider->DeleteItem( i, aDeep && aCurrentOnly );
if( lastGood > i )
lastGood--;
itemDeleted = true;
} }
if( m_view && aCurrentOnly && lastGood >= 0 ) if( m_view && aCurrentOnly && lastGood >= 0 )