Skip to content

Commit

Permalink
Merge pull request #5 from ronso0/search-clear-fix
Browse files Browse the repository at this point in the history
Search clear fix
  • Loading branch information
poelzi authored Feb 17, 2021
2 parents 2f729a3 + 619f9fc commit 8da91b9
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions src/widget/wsearchlineedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,27 +276,31 @@ QString WSearchLineEdit::getSearchText() const {
bool WSearchLineEdit::eventFilter(QObject* obj, QEvent* event) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Up) {
// if we're at the top of the list the Up key clears the search bar,
// no matter if it's a saved and unsaved query
if (findCurrentTextIndex() == 0 ||
(findCurrentTextIndex() == -1 && !currentText().isEmpty())) {
slotClearSearch();
return true;
}
} else if (keyEvent->key() == Qt::Key_Down) {
// after clearing the text field the down key is expected to
// show the latest entry
if (currentText().isEmpty()) {
setCurrentIndex(0);
return true;
}
// in case the user entered a new search query
// and presses the down key, save the query for later recall
if (findCurrentTextIndex() == -1) {
slotSaveSearch();
// if the popup is open don't intercept Up/Down keys
if (!view()->isVisible()) {
if (keyEvent->key() == Qt::Key_Up) {
// if we're at the top of the list the Up key clears the search bar,
// no matter if it's a saved and unsaved query
if (findCurrentTextIndex() == 0 ||
(findCurrentTextIndex() == -1 && !currentText().isEmpty())) {
slotClearSearch();
return true;
}
} else if (keyEvent->key() == Qt::Key_Down) {
// after clearing the text field the down key is expected to
// show the latest entry
if (currentText().isEmpty()) {
setCurrentIndex(0);
return true;
}
// in case the user entered a new search query
// and presses the down key, save the query for later recall
if (findCurrentTextIndex() == -1) {
slotSaveSearch();
}
}
} else if (keyEvent->key() == Qt::Key_Enter) {
}
if (keyEvent->key() == Qt::Key_Enter) {
if (findCurrentTextIndex() == -1) {
slotSaveSearch();
}
Expand Down Expand Up @@ -523,9 +527,9 @@ void WSearchLineEdit::slotClearSearch() {
// before returning the whole (and probably huge) library.
// No need to manually trigger a search at this point!
// See also: https://bugs.launchpad.net/mixxx/+bug/1635087
// Note that clear() would not just clear the line edit but
// erase all combobox items, thus clear the entire search history.
setCurrentText("");
// Note that just clear() would also erase all combobox items,
// thus clear the entire search history.
lineEdit()->clear();
// Refocus the edit field
setFocus(Qt::OtherFocusReason);
}
Expand Down

0 comments on commit 8da91b9

Please sign in to comment.