Skip to content

Commit

Permalink
Search: avoid storing duplicates in slotSaveSearch()
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Oct 19, 2021
1 parent 5a799e0 commit f47176a
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/widget/wsearchlineedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,23 +443,32 @@ void WSearchLineEdit::slotTriggerSearch() {

/// saves the current query as selection
void WSearchLineEdit::slotSaveSearch() {
int cIndex = findCurrentTextIndex();
#if ENABLE_TRACE_LOG
kLogger.trace()
<< "save search. Index: "
<< cIndex;
#endif // ENABLE_TRACE_LOG
m_saveTimer.stop();
// entry already exists and is on top
if (cIndex == 0) {
if (currentText().isEmpty() || !isEnabled()) {
return;
}
if (!currentText().isEmpty() && isEnabled()) {
// we remove the existing item and add a new one at the top
if (cIndex != -1) {
removeItem(cIndex);
}
insertItem(0, currentText());
QString cText(currentText());
if (currentIndex == -1) {
removeItem(-1);
}
// Check if the text is already listed
QSet<QString> querySet;
for (int index = 0; index < count(); index++) {
querySet.insert(itemText(index));
}
if (querySet.contains(cText)) {
// If query exists clear the box and use its index to set the currentIndex
int cIndex = findCurrentTextIndex();
setCurrentIndex(cIndex);
return;
} else {
// Else add it at the top
insertItem(0, cText);
setCurrentIndex(0);
while (count() > kMaxSearchEntries) {
removeItem(kMaxSearchEntries);
Expand Down

0 comments on commit f47176a

Please sign in to comment.