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 https://gitlab.com/kicad/code/kicad/-/issues/17205


(cherry picked from commit 0c2a084a47)
This commit is contained in:
Jon Evans 2024-03-05 18:54:04 -05:00
parent 8afbe544a3
commit 816e3efbd5
2 changed files with 13 additions and 9 deletions

View File

@ -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
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

View File

@ -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 )