Skip to content

Commit

Permalink
Don't immediately search for auto completed strings. Now the completi…
Browse files Browse the repository at this point in the history
…on required -> or enter to become active.

This fixes #10977
  • Loading branch information
daschuer committed Jan 16, 2023
1 parent f0fa380 commit e25071d
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/widget/wsearchlineedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QAbstractItemView>
#include <QApplication>
#include <QCompleter>
#include <QFont>
#include <QLineEdit>
#include <QShortcut>
Expand Down Expand Up @@ -288,7 +289,18 @@ void WSearchLineEdit::resizeEvent(QResizeEvent* e) {
QString WSearchLineEdit::getSearchText() const {
if (isEnabled()) {
DEBUG_ASSERT(!currentText().isNull());
return currentText();
QString text = currentText();
QLineEdit* pEdit = lineEdit();
QCompleter* pCompleter = completer();
if (pCompleter && pEdit && pEdit->hasSelectedText()) {
if (text.startsWith(pCompleter->completionPrefix()) &&
pCompleter->completionPrefix().size() == pEdit->cursorPosition()) {
// Search for the entered text until the user has confirmed the
// completion by -> or enter
return pCompleter->completionPrefix();
}
}
return text;
} else {
return QString();
}
Expand Down Expand Up @@ -347,11 +359,23 @@ void WSearchLineEdit::keyPressEvent(QKeyEvent* keyEvent) {
slotSaveSearch();
}
break;
case Qt::Key_Left:
case Qt::Key_Right:
QComboBox::keyPressEvent(keyEvent);
slotTriggerSearch();

This comment has been minimized.

Copy link
@uklotzde

uklotzde Feb 20, 2023

Contributor

I don't understand the purpose of this code that causes a severe regression.

#11287

This comment has been minimized.

Copy link
@ronso0

ronso0 Feb 20, 2023

Member

oh, that slipped through.

So if Left or Right clear the selection (check for Shift modifier) that should just emit textChanged / start the debounce timer I guess

This comment has been minimized.

Copy link
@uklotzde

uklotzde Feb 20, 2023

Contributor

Why clear? The navigation keys should not alter the text in any way. Otherwise this would be unexpected.

This comment has been minimized.

Copy link
@ronso0

ronso0 Feb 20, 2023

Member

clear the selection, not the text. But that's irrelevant anyway.
I just tested it: passing through the keypress and calling slotTextChanged(lineEdit()->text()) restores expected behaviour. Only Enter should trigger the search immediatley.

return;
case Qt::Key_Enter:
case Qt::Key_Return:
case Qt::Key_Return: {
if (slotClearSearchIfClearButtonHasFocus()) {
return;
}
QLineEdit* pEdit = lineEdit();
if (pEdit && pEdit->hasSelectedText()) {
QComboBox::keyPressEvent(keyEvent);
slotTriggerSearch();
return;
}

if (findCurrentTextIndex() == -1) {
slotSaveSearch();
}
Expand All @@ -362,6 +386,7 @@ void WSearchLineEdit::keyPressEvent(QKeyEvent* keyEvent) {
emit setLibraryFocus(FocusWidget::TracksTable);
}
return;
}
case Qt::Key_Space:
// Open/close popup with Ctrl + space
if (keyEvent->modifiers() == Qt::ControlModifier) {
Expand Down

0 comments on commit e25071d

Please sign in to comment.