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

Search clear fix #5

Merged
merged 2 commits into from
Feb 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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