Skip to content
Snippets Groups Projects
Commit 0c2a084a authored by Jon Evans's avatar Jon Evans :bike:
Browse files

Fix a few LIB_TREE search issues

Don't apply pruning to libraries that don't have
any children, since the point of the pruning is to
hide libraries that don't directly match a search
term if they don't have any children that match.

Fix searching for full LIB_IDs that got broken by
the implementation of "AND"

Fix searching for library names alone

Fixes kicad/code/kicad#17205
parent c1ba07e6
No related branches found
No related tags found
No related merge requests found
...@@ -247,7 +247,12 @@ void LIB_TREE_NODE_ITEM::UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxSt ...@@ -247,7 +247,12 @@ void LIB_TREE_NODE_ITEM::UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxSt
{ {
int currentScore = aMatcher->ScoreTerms( m_SearchTerms ); int currentScore = aMatcher->ScoreTerms( m_SearchTerms );
if( m_Score >= 0 && currentScore > 0 ) // This is a hack: the second phase of search in the adapter will look for a tokenized
// LIB_ID and send the lib part down here. While we generally want to prune ourselves
// out here (by setting score to -1) the first time we fail to match a search term,
// we want to give the same search term a second chance if it has been split from a library
// name.
if( ( m_Score >= 0 || !aLib.IsEmpty() ) && currentScore > 0 )
m_Score += currentScore; m_Score += currentScore;
else else
m_Score = -1; // Item has failed to match this term, rule it out m_Score = -1; // Item has failed to match this term, rule it out
...@@ -306,11 +311,15 @@ void LIB_TREE_NODE_LIBRARY::UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const w ...@@ -306,11 +311,15 @@ void LIB_TREE_NODE_LIBRARY::UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const w
m_Score = 0; m_Score = 0;
// aLib test is additive, but only when we've already accumulated some score from children // aLib test is additive, but only when we've already accumulated some score from children
if( !aLib.IsEmpty() && m_Name.Lower().Matches( aLib ) && m_Score > 0 ) if( !aLib.IsEmpty()
&& m_Name.Lower().Matches( aLib )
&& ( m_Score > 0 || m_Children.empty() ) )
{
m_Score += 1; m_Score += 1;
}
// aMatcher test is additive, but only when we've already accumulated some score from children // aMatcher test is additive
if( aMatcher && m_Score > 0 ) if( aMatcher )
m_Score += aMatcher->ScoreTerms( m_SearchTerms ); m_Score += aMatcher->ScoreTerms( m_SearchTerms );
// show all nodes if no search/filter/etc. criteria are given // show all nodes if no search/filter/etc. criteria are given
......
...@@ -302,11 +302,6 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( const wxString& aSearch, bool a ...@@ -302,11 +302,6 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( const wxString& aSearch, bool a
m_tree.UpdateScore( &itemNameMatcher, lib, nullptr ); m_tree.UpdateScore( &itemNameMatcher, lib, nullptr );
} }
else
{
// In case the full token happens to match a library name
m_tree.UpdateScore( nullptr, '*' + term + '*', nullptr );
}
} }
if( firstTerm ) if( firstTerm )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment