Handle de-highlighting items outside selection when selection changes.

Also adds selection cleared event to handled events.

And a small performance boost to not scan items for selection changes
when find is not seleciton-based.
This commit is contained in:
Jeff Young 2023-02-23 16:22:21 +00:00
parent d9a77e6a64
commit ddf8d115c4
1 changed files with 28 additions and 28 deletions

View File

@ -64,11 +64,9 @@ int SCH_FIND_REPLACE_TOOL::UpdateFind( const TOOL_EVENT& aEvent )
}
};
if( aEvent.IsAction( &ACTIONS::find ) || aEvent.IsAction( &ACTIONS::findAndReplace )
|| aEvent.IsAction( &ACTIONS::updateFind ) )
auto visitAll =
[&]()
{
m_foundItemHighlighted = false;
for( SCH_ITEM* item : m_frame->GetScreen()->Items() )
{
visit( item, &m_frame->GetCurrentSheet() );
@ -79,35 +77,37 @@ int SCH_FIND_REPLACE_TOOL::UpdateFind( const TOOL_EVENT& aEvent )
visit( aChild, &m_frame->GetCurrentSheet() );
} );
}
};
if( aEvent.IsAction( &ACTIONS::find ) || aEvent.IsAction( &ACTIONS::findAndReplace )
|| aEvent.IsAction( &ACTIONS::updateFind ) )
{
m_foundItemHighlighted = false;
visitAll();
}
else if( aEvent.Matches( EVENTS::SelectedItemsModified )
|| aEvent.Matches( EVENTS::PointSelectedEvent )
else if( aEvent.Matches( EVENTS::SelectedItemsModified ) )
{
for( EDA_ITEM* item : m_selectionTool->GetSelection() )
visit( item, &m_frame->GetCurrentSheet() );
}
else if( aEvent.Matches( EVENTS::PointSelectedEvent )
|| aEvent.Matches( EVENTS::SelectedEvent )
|| aEvent.Matches( EVENTS::UnselectedEvent ) )
|| aEvent.Matches( EVENTS::UnselectedEvent )
|| aEvent.Matches( EVENTS::ClearedEvent ) )
{
// Normal find modifies the selection, but selection-based find does
// not so we want to start over in the items we are searching through when
// the selection changes
if( selectedOnly )
{
m_afterItem = nullptr;
for( EDA_ITEM* item : m_selectionTool->GetSelection() )
visit( item, &m_frame->GetCurrentSheet() );
visitAll();
}
}
else if( m_foundItemHighlighted )
{
m_foundItemHighlighted = false;
for( SCH_ITEM* item : m_frame->GetScreen()->Items() )
{
visit( item, &m_frame->GetCurrentSheet() );
item->RunOnChildren(
[&]( SCH_ITEM* aChild )
{
visit( aChild, &m_frame->GetCurrentSheet() );
} );
}
visitAll();
}
getView()->UpdateItems();