Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Searchbar clear #3262

Merged
merged 11 commits into from
Feb 17, 2021
42 changes: 28 additions & 14 deletions src/widget/wsearchlineedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +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_Down) {
// after clearing the text field the down key is expected to
// show the last entry
if (currentText().isEmpty()) {
setCurrentIndex(0);
return true;
}
// in case the user entered a new search query
// und 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 All @@ -298,7 +310,7 @@ bool WSearchLineEdit::eventFilter(QObject* obj, QEvent* event) {
return true;
} else if (keyEvent->key() == Qt::Key_Space &&
keyEvent->modifiers() == Qt::ControlModifier) {
// open popup on ctrl + space
// open/close popup on ctrl + space
if (view()->isVisible()) {
hidePopup();
} else {
Expand Down Expand Up @@ -515,7 +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
clear();
// 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