Skip to content

Commit

Permalink
fixed bugs with searchHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
neoneela committed Nov 11, 2023
1 parent c3d23a7 commit 782dd5a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions plugins/gui/src/searchbar/searchbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ namespace hal
else if(mIncrementalSearch && mLineEdit->text().length() >= mMinCharsToStartIncSearch)
{
Q_EMIT triggerNewSearch(mLineEdit->text(), mCurrentOptions->toInt());
updateSearchHistory(mLineEdit->text());
}
}

Expand All @@ -226,7 +225,6 @@ namespace hal
}
else{
Q_EMIT triggerNewSearch(mLineEdit->text(), mCurrentOptions->toInt());
//updateSearchHistory(mLineEdit->text());
}
}

Expand Down Expand Up @@ -293,15 +291,23 @@ namespace hal
}

void Searchbar::updateSearchHistory(QString entry){
if(entry.length() >= 3 && !mSearchHistory.contains(entry))

const int MAX_ENTRIES = 10;
const int MIN_LENGTH = 3;

if(entry.length() >= MIN_LENGTH && !mSearchHistory.contains(entry))
{
if(!mSearchHistory.empty() && (entry.startsWith(mSearchHistory[0])))
mSearchHistory[0] = entry;
else
{
if (mSearchHistory.length() >= 10) mSearchHistory.removeLast();
if(!mSearchHistory.empty() && mSearchHistory[0].startsWith(entry))
return;

if (mSearchHistory.length() >= MAX_ENTRIES) mSearchHistory.removeLast();
mSearchHistory.prepend(entry);
}

}
}
}

0 comments on commit 782dd5a

Please sign in to comment.