-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
Pressing ENTER in the search bar opens the first suggestion #1230
Comments
@veloman-yunkan Since we opened this issue I am continuing discussion here. From #1189 (comment), it is found that QCompleter's activate signal is not sent on the invalid index so it doesn't work. This approach is inherently wrong since during typing, the m Regardless, to ensure correctness, openCompletion() needs to check the text content before opening the index. One change could be that we make getDefaultSuggestionIndex more generalized: QModelIndex SearchBarLineEdit::getRowOrDefaultIndex(int row) const
{
const auto rowIndex = m_suggestionModel.index(row);
...
} Then, we adapt openCompletion: /* In .h */
void openCompletion(const QModelIndex& index = QModelIndex());
/* In .h */
void SearchBarLineEdit::openCompletion(const QModelIndex &index)
{
QModelIndex openIndex = getRowOrDefaultIndex(index.isValid() ? index.row() : 0);
if (openIndex.isValid())
{
const QUrl url = openIndex.data(Qt::UserRole).toUrl();
QTimer::singleShot(0, [=](){KiwixApp::instance()->openUrl(url, false);});
}
}
void SearchBarLineEdit::onInitialSuggestions(int)
{
if (m_returnPressed) {
openCompletion();
...
} |
Another approach is to track if suggestions are valid (have already been produced) for the current content of the searchbox. If so, then |
@veloman-yunkan This would result in the issue I described above:
If we open in |
@ShaopengLin That's why my proposal is centered around tracking relevance of suggestions - though I used a somewhat ambiguous adjective valid, which may have confused you, I meant it in the meaning relevant. The parenthesized fragment may have added to the confusion. Please reread my idea as follows
With more detailed outline for a possible implementation:
That's the main idea. You may have to take into account a couple of edge cases (like the searchbox being empty, etc). But I would like to see both fixes (as separate commits in one PR) so that we can select the better one. |
#1224 broke the handling of pressing ENTER in the search bar - it always opens the first suggestion (even if it doesn't fully match the text in the searchbar).
Originally posted by @veloman-yunkan in #1224 (comment)
The text was updated successfully, but these errors were encountered: