Skip to content

Commit

Permalink
Fix clearing search field when using application
Browse files Browse the repository at this point in the history
* Reset clear timer when manipulating the entry view and opening/closing entries
* Only start the clear timer if there is an active search
  • Loading branch information
droidmonkey committed Feb 28, 2020
1 parent b188385 commit eb88b8c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/gui/SearchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ bool SearchWidget::eventFilter(QObject* obj, QEvent* event)
return true;
}
}
} else if (event->type() == QEvent::FocusOut) {
} else if (event->type() == QEvent::FocusOut && !m_ui->searchEdit->text().isEmpty()) {
if (config()->get("security/clearsearch").toBool()) {
int timeout = config()->get("security/clearsearchtimeout").toInt();
if (timeout > 0) {
Expand All @@ -124,6 +124,7 @@ bool SearchWidget::eventFilter(QObject* obj, QEvent* event)
}
}
} else if (event->type() == QEvent::FocusIn) {
// Never clear the search if we are using it
m_clearSearchTimer->stop();
}

Expand All @@ -139,6 +140,8 @@ void SearchWidget::connectSignals(SignalMultiplexer& mx)
mx.connect(this, SIGNAL(copyPressed()), SLOT(copyPassword()));
mx.connect(this, SIGNAL(downPressed()), SLOT(setFocus()));
mx.connect(SIGNAL(clearSearch()), m_ui->searchEdit, SLOT(clear()));
mx.connect(SIGNAL(entrySelectionChanged()), this, SLOT(resetSearchClearTimer()));
mx.connect(SIGNAL(currentModeChanged(DatabaseWidget::Mode)), this, SLOT(resetSearchClearTimer()));
mx.connect(m_ui->searchEdit, SIGNAL(returnPressed()), SLOT(switchToEntryEdit()));
}

Expand Down Expand Up @@ -177,6 +180,14 @@ void SearchWidget::startSearch()
search(m_ui->searchEdit->text());
}

void SearchWidget::resetSearchClearTimer()
{
// Restart the search clear timer if it is running
if (m_clearSearchTimer->isActive()) {
m_clearSearchTimer->start();
}
}

void SearchWidget::updateCaseSensitive()
{
emit caseSensitiveChanged(m_actionCaseSensitive->isChecked());
Expand Down
1 change: 1 addition & 0 deletions src/gui/SearchWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private slots:
void searchFocus();
void toggleHelp();
void showSearchMenu();
void resetSearchClearTimer();

private:
const QScopedPointer<Ui::SearchWidget> m_ui;
Expand Down

0 comments on commit eb88b8c

Please sign in to comment.