Don't break alphabetical sorting on search

When using the "Filter" search for footprints/symbols, the least
surprising outcome is that the window filters the existing
(alphabetically sorted) list but does not change the display order based
on scoring.

This also needs to adjust the fix for
https://gitlab.com/kicad/code/kicad/-/issues/259 as that assumed the
selected element would be the first below the group (not the case if we
are sorting alphabetically)

Fixes https://gitlab.com/kicad/code/kicad/issues/11746
This commit is contained in:
Seth Hillbrand 2022-06-10 11:45:25 -07:00
parent e0f0bb2edd
commit 4790257616
3 changed files with 25 additions and 13 deletions

View File

@ -105,9 +105,6 @@ int LIB_TREE_NODE::Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aN
if( aNode1.m_Type != aNode2.m_Type )
return 0;
if( aNode1.m_Score != aNode2.m_Score )
return aNode1.m_Score - aNode2.m_Score;
if( aNode1.m_Parent != aNode2.m_Parent )
return 0;

View File

@ -268,7 +268,7 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( const wxString& aSearch, bool a
wxDataViewItem parent = GetParent( item );
if( parent.IsOk() )
item = parent;
m_widget->EnsureVisible( parent );
}
m_widget->EnsureVisible( item );
@ -509,7 +509,7 @@ bool LIB_TREE_MODEL_ADAPTER::GetAttr( const wxDataViewItem& aItem,
}
void LIB_TREE_MODEL_ADAPTER::FindAndExpand( LIB_TREE_NODE& aNode,
void LIB_TREE_MODEL_ADAPTER::Find( LIB_TREE_NODE& aNode,
std::function<bool( const LIB_TREE_NODE* )> aFunc,
LIB_TREE_NODE** aHighScore )
{
@ -517,14 +517,11 @@ void LIB_TREE_MODEL_ADAPTER::FindAndExpand( LIB_TREE_NODE& aNode,
{
if( aFunc( &*node ) )
{
wxDataViewItem item = wxDataViewItem( &*node );
m_widget->ExpandAncestors( item );
if( !(*aHighScore) || node->m_Score > (*aHighScore)->m_Score )
(*aHighScore) = &*node;
}
FindAndExpand( *node, aFunc, aHighScore );
Find( *node, aFunc, aHighScore );
}
}
@ -533,7 +530,7 @@ LIB_TREE_NODE* LIB_TREE_MODEL_ADAPTER::ShowResults()
{
LIB_TREE_NODE* highScore = nullptr;
FindAndExpand( m_tree,
Find( m_tree,
[]( LIB_TREE_NODE const* n )
{
// return leaf nodes with some level of matching
@ -541,6 +538,12 @@ LIB_TREE_NODE* LIB_TREE_MODEL_ADAPTER::ShowResults()
},
&highScore );
if( highScore)
{
wxDataViewItem item = wxDataViewItem( highScore );
m_widget->ExpandAncestors( item );
}
return highScore;
}
@ -552,7 +555,7 @@ LIB_TREE_NODE* LIB_TREE_MODEL_ADAPTER::ShowPreselect()
if( !m_preselect_lib_id.IsValid() )
return highScore;
FindAndExpand( m_tree,
Find( m_tree,
[&]( LIB_TREE_NODE const* n )
{
if( n->m_Type == LIB_TREE_NODE::LIBID && ( n->m_Children.empty() ||
@ -566,6 +569,12 @@ LIB_TREE_NODE* LIB_TREE_MODEL_ADAPTER::ShowPreselect()
},
&highScore );
if( highScore)
{
wxDataViewItem item = wxDataViewItem( highScore );
m_widget->ExpandAncestors( item );
}
return highScore;
}
@ -574,7 +583,7 @@ LIB_TREE_NODE* LIB_TREE_MODEL_ADAPTER::ShowSingleLibrary()
{
LIB_TREE_NODE* highScore = nullptr;
FindAndExpand( m_tree,
Find( m_tree,
[]( LIB_TREE_NODE const* n )
{
return n->m_Type == LIB_TREE_NODE::TYPE::LIBID &&
@ -582,5 +591,11 @@ LIB_TREE_NODE* LIB_TREE_MODEL_ADAPTER::ShowSingleLibrary()
},
&highScore );
if( highScore)
{
wxDataViewItem item = wxDataViewItem( highScore );
m_widget->ExpandAncestors( item );
}
return highScore;
}

View File

@ -369,7 +369,7 @@ private:
* Find any results worth highlighting and expand them, according to given criteria
* The highest-scoring node is written to aHighScore
*/
void FindAndExpand( LIB_TREE_NODE& aNode, std::function<bool( const LIB_TREE_NODE* )> aFunc,
void Find( LIB_TREE_NODE& aNode, std::function<bool( const LIB_TREE_NODE* )> aFunc,
LIB_TREE_NODE** aHighScore );
/**