Skip to content

Commit

Permalink
feat(ui): Always select all for search bar shortcut (fixes zealdocs#1033
Browse files Browse the repository at this point in the history
)

Previously, the search bar focus shortcut would only select all if the
search bar was not focused. This change makes select all happen all the
time, making the keyboard shortcut consistent no matter what is focused.
  • Loading branch information
mcomella committed Nov 11, 2018
1 parent 7b78e5c commit ac1748e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libs/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ MainWindow::MainWindow(Core::Application *app, QWidget *parent) :
for (auto it = searchBarFocusShortcuts.begin(); it != searchBarFocusShortcuts.end(); ++it) {
shortcut = new QShortcut(*it, this);
connect(shortcut, &QShortcut::activated,
ui->lineEdit, static_cast<void (SearchEdit::*)()>(&SearchEdit::setFocus));
ui->lineEdit, static_cast<void (SearchEdit::*)()>(&SearchEdit::setFocusByShortcut));
}

// Duplicate current tab.
Expand Down
8 changes: 8 additions & 0 deletions src/libs/ui/widgets/searchedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ bool SearchEdit::event(QEvent *event)
return true;
}

void SearchEdit::setFocusByShortcut() {
// When want the keyboard shortcut that focuses the search bar to always have the same
// behavior, even if the search bar is already focused. focusInEvent won't be called if it's
// already focused so we work around that by clearing focus before setting focus.
clearFocus();
setFocus();
}

void SearchEdit::focusInEvent(QFocusEvent *event)
{
QLineEdit::focusInEvent(event);
Expand Down
1 change: 1 addition & 0 deletions src/libs/ui/widgets/searchedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class SearchEdit : public QLineEdit
void clearQuery();
void selectQuery();
void setCompletions(const QStringList &completions);
void setFocusByShortcut();

protected:
bool event(QEvent *event) override;
Expand Down

0 comments on commit ac1748e

Please sign in to comment.