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

BugFix: Should Open Default Suggestion on Search Bar when Nothing is Selected #1232

Merged
merged 1 commit into from
Nov 4, 2024

Conversation

ShaopengLin
Copy link
Collaborator

@ShaopengLin ShaopengLin commented Oct 30, 2024

Fix #1230

Two potential implementations listed here:

  1. Open default suggestions whenever enter is pressed on an invalid index. Added 'relevant' search bar input checker to avoid race conditions. 2929d91

  2. Similar approach as before Implement Endless Zim Search Suggestions #1224, where we check text in search bar matches the suggestion text before opening. ad2e2b3

I am leaning toward the first one since it is a much cleaner change.

src/searchbar.cpp Outdated Show resolved Hide resolved
@@ -332,12 +340,13 @@ void SearchBarLineEdit::fetchSuggestions(NewSuggestionHandlerFuncPtr callback)
const int start = m_suggestionModel.countOfRegularSuggestions();
const auto suggestionWorker = new SuggestionListWorker(m_searchbarInput, m_token, start, this);
connect(suggestionWorker, &SuggestionListWorker::searchFinished, this,
[=] (const QList<SuggestionData>& suggestionList, int token) {
[=] (const QList<SuggestionData>& suggestionList, const QString& text, int token) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could have passed the search text as a captured value of the lambda. But your implementation drew my attention to the not so self-explaining token/m_token thing. Let's improve the design as follows:

  1. Replace int SearchBarLineEdit::m_token with QString SearchBarLineEdit::m_suggestionWereRequestedFor (or maybe we can instead reuse the existing m_searchbarInput data member?)
  2. Get rid of the token parameter in searchFinished() signal of SuggestionListWorker - use the new text parameter instead (BTW, the latter better be renamed to searchText and moved to the beginning of the parameter list).

Copy link
Collaborator Author

@ShaopengLin ShaopengLin Oct 30, 2024

Choose a reason for hiding this comment

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

@veloman-yunkan Removing the temporal variable m_token might introduce a race condition bug:

  1. user type "i", and suggestions are retrived.
  2. user trigger fetch more.
  3. user further type to "i am", and new suggestions are triggered.
  4. user immediately types back to "i", and the fetch more from 2. returns from asynchronous call back.
  5. the insertion order can be raced, and m_completer.complete() is not called before fetch more.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good analysis! You are a shrewd antiracist! :)

Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

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

If your preference is still in favour of the first approach then please remove the last two commits and we will be done with this PR.

@@ -313,9 +322,8 @@ void SearchBarLineEdit::onInitialSuggestions(int)
m_completer.complete(getCompleterRect());

/* Make row 0 appear but do not highlight it */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this comment still valid?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@ShaopengLin ShaopengLin force-pushed the Issue#1230-suggestion-enter-press branch from 3ee0993 to 1ea0222 Compare October 31, 2024 16:11
Search Bar opens the default suggestion when user did not select any suggestions and presses enter.
@kelson42 kelson42 merged commit bdfcc88 into main Nov 4, 2024
6 checks passed
@kelson42 kelson42 deleted the Issue#1230-suggestion-enter-press branch November 4, 2024 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pressing ENTER in the search bar opens the first suggestion
3 participants