diff --git a/common/rc_item.cpp b/common/rc_item.cpp index 6cceac68af..9b43141a00 100644 --- a/common/rc_item.cpp +++ b/common/rc_item.cpp @@ -432,18 +432,32 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo return; } + int lastGood = -1; + bool found = false; + + if( m_view ) + m_view->UnselectAll(); + for( int i = m_rcItemsProvider->GetCount() - 1; i >= 0; --i ) { - std::shared_ptr rcItem = m_rcItemsProvider->GetItem( i ); - MARKER_BASE* marker = rcItem->GetParent(); - bool excluded = marker ? marker->IsExcluded() : false; + std::shared_ptr rcItem = m_rcItemsProvider->GetItem( i ); + MARKER_BASE* marker = rcItem->GetParent(); + bool excluded = marker ? marker->IsExcluded() : false; if( aCurrentOnly && rcItem != current_item ) + { + if( found && lastGood >= 0 ) + break; + + lastGood = i; continue; + } if( excluded && !aIncludeExclusions ) continue; + found = true; + wxDataViewItem markerItem = ToItem( m_tree[i] ); wxDataViewItemArray childItems; wxDataViewItem parentItem = ToItem( m_tree[i]->m_Parent ); @@ -466,6 +480,9 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo m_rcItemsProvider->DeleteItem( i, aDeep && aCurrentOnly ); } + if( m_view && aCurrentOnly && lastGood >= 0 ) + m_view->Select( ToItem( m_tree[ lastGood ] ) ); + if( !aCurrentOnly ) { m_rcItemsProvider->DeleteAllItems( aIncludeExclusions, aDeep );