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

No longer trigger unneccessary searches om left and right cursor keys #11289

Merged
merged 4 commits into from
Mar 19, 2023

Conversation

daschuer
Copy link
Member

This fixes #11287, a regression from
e25071d

@ronso0
Copy link
Member

ronso0 commented Feb 20, 2023

On second thought: let's not make pressing Right trigger a search.
IMO that should just accept the completion -- triggering the search should be up to the user (Enter) or the debounce timer.

@ronso0
Copy link
Member

ronso0 commented Feb 20, 2023

Otoh that would delay triggering the search (debounce timer is restarted on each keystroke).
But maybe that's even okay since moving the cursor somehow implies the user is still refining the search phrase?

@ronso0
Copy link
Member

ronso0 commented Feb 20, 2023

On second thought: let's not make pressing Right trigger a search. IMO that should just accept the completion -- triggering the search should be up to the user (Enter) or the debounce timer.

ed10381

@uklotzde
Copy link
Contributor

Otoh that would delay triggering the search (debounce timer is restarted on each keystroke). But maybe that's even okay since moving the cursor somehow implies the user is still refining the search phrase?

This is the expected behavior!

QLineEdit* pEdit = lineEdit();
bool hadSelectedText = pEdit->hasSelectedText();
bool hadSelectedText = pEdit ? pEdit->hasSelectedText() : false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These null checks do not help and only complicate the code. We expect that there is always a line QLineEdit. Just invoke lineEdit() without using any mutable, local variables.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nup, I figured it's the other way around:
if it's editable then there's always a QLineEdit.
And since the editable state is not changed there will always be a lineEdit()
https://github.com/mixxxdj/mixxx/pull/11289/files#diff-85c225cd63139457cde84ddb0d2f69c854c16f8254672cd19587fd25dd755c62L94

Copy link
Contributor

@uklotzde uklotzde Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you need to use VERIFY_OR_DEBUG_ASSERT Then please simplify the code, i.e. invoke lineEdit() when needed and use the resulting pointer directly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sake of completeness, if isEditable is true then there is a QLineEdit, otherwise lineEdit() is a nullptr:

void QComboBox::setEditable(bool editable)
{
    Q_D(QComboBox);
    if (isEditable() == editable)
        return;

    QStyleOptionComboBox opt;
    initStyleOption(&opt);
    if (editable) {
        if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
            d->viewContainer()->updateScrollers();
            view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        }
        QLineEdit *le = new QLineEdit(this);
        le->setPalette(palette());
        setLineEdit(le);
    } else {
        if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
            d->viewContainer()->updateScrollers();
            view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        }
        setAttribute(Qt::WA_InputMethodEnabled, false);
        d->lineEdit->hide();
        d->lineEdit->deleteLater();
        d->lineEdit = nullptr;
    }

    d->updateDelegate();
    d->updateFocusPolicy();

    d->viewContainer()->updateTopBottomMargin();
    if (!testAttribute(Qt::WA_Resized))
        adjustSize();
}

@daschuer
Copy link
Member Author

I did some usability test and it works now nice even with a looong delay of 10 s

@@ -803,3 +809,11 @@ void WSearchLineEdit::slotSetFont(const QFont& font) {
updateClearAndDropdownButton(getSearchText());
}
}

bool WSearchLineEdit::hasSelectedText() const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -517,6 +525,12 @@ void WSearchLineEdit::slotRestoreSearch(const QString& text) {
enableSearch(text);
}

void WSearchLineEdit::triggerSearchDelayed() {
Copy link
Contributor

@uklotzde uklotzde Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

triggerSearchDebounced() for consistent naming?

case Qt::Key_Right:
case Qt::Key_Right: {
// Both keys may change or clear the selection (suggested completion).
const bool hadSelectedText = hasSelectedText();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hadSelectedTextBeforeKeyPressed for disambiguation of the very similar identifiers.

slotTriggerSearch();
// fetch lineEdit again, because we have no guarantee that pEdit
// is still valid after QComboBox::keyPressEvent()
if (hadSelectedTextBeforeKeyPressed && hasSelectedText()) {
Copy link
Contributor

@uklotzde uklotzde Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Condition is wrong? Doesn't match the comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

Copy link
Contributor

@uklotzde uklotzde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash the commits.

@ronso0
Copy link
Member

ronso0 commented Feb 21, 2023

Tbh, to me, this feels a bit complicated by now.

I thought of the QCompleter signals initially, thought it was too complicated, but I gave it a shot and it turns out to be pretty simple, and solid so far. Please take a look at 1bdd6eb. I'll open a PR tomorrow.

@daschuer
Copy link
Member Author

My original approach was like this, but I did not manage to make it work reliable.
We need also consider that lineEdit is a subject of a change:
https://github.com/qt/qtbase/blob/e0a5915f88a780ba0791bce5ed042e92036a4900/src/widgets/widgets/qcombobox.cpp#L1743

@daschuer
Copy link
Member Author

Rebase done.

@daschuer
Copy link
Member Author

@ronso0: So we can merge this?

return false;
}
return pEdit->hasSelectedText();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I already pointed out earlier, this is obsolete:
There is always a QLineEdit because we set the combobox editable in the constructor, and we rely on that in many places here. Please see
https://github.com/qt/qtbase/blob/4903e45231b00fb8a06f0b3c60af764f13e831bd/src/widgets/widgets/qcombobox.cpp#L1787-L1802

Just use lineEdit() directly.

Also applies here 7165f0b#diff-85c225cd63139457cde84ddb0d2f69c854c16f8254672cd19587fd25dd755c62R316

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other changes LGTM, thanks!

@daschuer
Copy link
Member Author

Done

@daschuer
Copy link
Member Author

the pre-commit issue is caused by #11386

@ronso0
Copy link
Member

ronso0 commented Mar 19, 2023

Thank you!

@ronso0 ronso0 merged commit e0401fc into mixxxdj:2.4 Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants