From 0cf6679bfe68edbf90ecfca77db349896a9df697 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 23 Oct 2023 18:23:24 +0100 Subject: [PATCH] Try to get the scoring logic right (again). Also adds matching against a library name. Fixes https://gitlab.com/kicad/code/kicad/-/issues/15875 --- common/lib_tree_model.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/common/lib_tree_model.cpp b/common/lib_tree_model.cpp index 17df2a113b..cd03ac749e 100644 --- a/common/lib_tree_model.cpp +++ b/common/lib_tree_model.cpp @@ -255,6 +255,8 @@ LIB_TREE_NODE_LIB::LIB_TREE_NODE_LIB( LIB_TREE_NODE* aParent, wxString const& aN m_Desc = aDesc; m_Parent = aParent; m_LibId.SetLibNickname( aName ); + + m_SearchTerms.emplace_back( SEARCH_TERM( aName, 8 ) ); } @@ -268,7 +270,10 @@ LIB_TREE_NODE_LIB_ID& LIB_TREE_NODE_LIB::AddItem( LIB_TREE_ITEM* aItem ) void LIB_TREE_NODE_LIB::UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxString& aLib ) { - // We need to score leaf nodes, which are usually (but not always) children. + // If we're matching then we default to not-matched; otherwise we default to whatever m_Score + // was initialized to (currently 1) + if( aMatcher ) + m_Score = 0; if( m_Children.size() ) { @@ -278,11 +283,10 @@ void LIB_TREE_NODE_LIB::UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxStr m_Score = std::max( m_Score, child->m_Score ); } } - else if( aMatcher ) + else { - // No children; we are a leaf. - - m_Score = aMatcher->ScoreTerms( m_SearchTerms ); + if( aMatcher ) + m_Score = aMatcher->ScoreTerms( m_SearchTerms ); } }