-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
Conversation
ad2e2b3
to
e7e8a1f
Compare
src/searchbar.cpp
Outdated
@@ -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) { |
There was a problem hiding this comment.
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:
- Replace
int SearchBarLineEdit::m_token
withQString SearchBarLineEdit::m_suggestionWereRequestedFor
(or maybe we can instead reuse the existingm_searchbarInput
data member?) - Get rid of the
token
parameter insearchFinished()
signal ofSuggestionListWorker
- use the newtext
parameter instead (BTW, the latter better be renamed tosearchText
and moved to the beginning of the parameter list).
There was a problem hiding this comment.
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:
- user type "i", and suggestions are retrived.
- user trigger fetch more.
- user further type to "i am", and new suggestions are triggered.
- user immediately types back to "i", and the fetch more from 2. returns from asynchronous call back.
- the insertion order can be raced, and m_completer.complete() is not called before fetch more.
There was a problem hiding this comment.
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! :)
e7e8a1f
to
ad5d6af
Compare
ad5d6af
to
3ee0993
Compare
There was a problem hiding this 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.
src/searchbar.cpp
Outdated
@@ -313,9 +322,8 @@ void SearchBarLineEdit::onInitialSuggestions(int) | |||
m_completer.complete(getCompleterRect()); | |||
|
|||
/* Make row 0 appear but do not highlight it */ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
3ee0993
to
1ea0222
Compare
Search Bar opens the default suggestion when user did not select any suggestions and presses enter.
1ea0222
to
94b991e
Compare
Fix #1230
Two potential implementations listed here:
Open default suggestions whenever enter is pressed on an invalid index. Added 'relevant' search bar input checker to avoid race conditions. 2929d91
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.