From 0c2a084a476decc7fe7d8fa65608eeec71133424 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Tue, 5 Mar 2024 18:54:04 -0500 Subject: [PATCH] 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 --- common/lib_tree_model.cpp | 17 +++++++++++++---- common/lib_tree_model_adapter.cpp | 5 ----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/common/lib_tree_model.cpp b/common/lib_tree_model.cpp index cd38ee12f2..575109420a 100644 --- a/common/lib_tree_model.cpp +++ b/common/lib_tree_model.cpp @@ -247,7 +247,12 @@ void LIB_TREE_NODE_ITEM::UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxSt { 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; else 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; // 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; + } - // aMatcher test is additive, but only when we've already accumulated some score from children - if( aMatcher && m_Score > 0 ) + // aMatcher test is additive + if( aMatcher ) m_Score += aMatcher->ScoreTerms( m_SearchTerms ); // show all nodes if no search/filter/etc. criteria are given diff --git a/common/lib_tree_model_adapter.cpp b/common/lib_tree_model_adapter.cpp index e10150e2ef..0afa5bb692 100644 --- a/common/lib_tree_model_adapter.cpp +++ b/common/lib_tree_model_adapter.cpp @@ -302,11 +302,6 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( const wxString& aSearch, bool a 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 )