Browse Source

Also limit the number of search terms (as well as their length)

Fixes https://gitlab.com/kicad/code/kicad/-/issues/19464
pcb_db
Jeff Young 11 months ago
parent
commit
577c1dd332
  1. 4
      common/eda_pattern_match.cpp
  2. 12
      common/lib_tree_model_adapter.cpp

4
common/eda_pattern_match.cpp

@ -488,8 +488,8 @@ int EDA_COMBINED_MATCHER::ScoreTerms( std::vector<SEARCH_TERM>& aWeightedTerms )
// Don't cause KiCad to hang if someone accidentally pastes the PCB or schematic
// into the search box.
if( term.Text.Length() > 5000 )
term.Text = term.Text.Left( 5000 );
if( term.Text.Length() > 1000 )
term.Text = term.Text.Left( 1000 );
term.Normalized = true;
}

12
common/lib_tree_model_adapter.cpp

@ -285,17 +285,21 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( const wxString& aSearch, bool a
m_tree.ResetScore();
// Don't cause KiCad to hang if someone accidentally pastes the PCB or schematic into
// the search box.
constexpr int MAX_TERMS = 100;
wxStringTokenizer tokenizer( aSearch );
bool firstTerm = true;
int termCount = 0;
while( tokenizer.HasMoreTokens() )
while( tokenizer.HasMoreTokens() && termCount < MAX_TERMS )
{
// First search for the full token, in case it appears in a search string
wxString term = tokenizer.GetNextToken().Lower();
EDA_COMBINED_MATCHER termMatcher( term, CTX_LIBITEM );
m_tree.UpdateScore( &termMatcher, wxEmptyString, m_filter );
firstTerm = false;
termCount++;
if( term.Contains( ":" ) )
{
@ -308,7 +312,7 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( const wxString& aSearch, bool a
}
}
if( firstTerm )
if( termCount == 0 )
{
// No terms processed; just run the filter
m_tree.UpdateScore( nullptr, wxEmptyString, m_filter );

Loading…
Cancel
Save