Skip to content

Commit

Permalink
Auto-Type: PageUp/PageDown scrolling for entries
Browse files Browse the repository at this point in the history
Fixes #4530
  • Loading branch information
hifi committed Apr 3, 2021
1 parent 871c4ff commit 25d456f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
41 changes: 23 additions & 18 deletions src/autotype/AutoTypeSelectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,30 @@ void AutoTypeSelectDialog::performSearch()
m_ui->view->setMatchList(matches, !m_ui->search->text().isEmpty());
}

void AutoTypeSelectDialog::moveSelectionUp()
void AutoTypeSelectDialog::moveSelection(int offset)
{
auto current = m_ui->view->currentIndex();
auto previous = current.sibling(current.row() - 1, 0);

if (previous.isValid()) {
m_ui->view->setCurrentIndex(previous);
// special case where we have no default selection (empty search)
if (!current.isValid() && offset > 0) {
current = m_ui->view->indexAt({0, 0});
offset--;
}
}

void AutoTypeSelectDialog::moveSelectionDown()
{
auto current = m_ui->view->currentIndex();
int step = offset > 0 ? 1 : -1;

// special case where we have no default selection (empty search)
if (!current.isValid()) {
m_ui->view->setCurrentIndex(m_ui->view->indexAt({0, 0}));
return;
}
while (offset != 0) {
auto next = current.sibling(current.row() + step, 0);

auto next = current.sibling(current.row() + 1, 0);
if (!next.isValid()) {
break;
}

if (next.isValid()) {
m_ui->view->setCurrentIndex(next);
current = next;
offset -= step;
}

m_ui->view->setCurrentIndex(current);
}

void AutoTypeSelectDialog::activateCurrentMatch()
Expand Down Expand Up @@ -217,10 +216,16 @@ bool AutoTypeSelectDialog::eventFilter(QObject* obj, QEvent* event)
auto* keyEvent = static_cast<QKeyEvent*>(event);
switch (keyEvent->key()) {
case Qt::Key_Up:
moveSelectionUp();
moveSelection(-1);
return true;
case Qt::Key_Down:
moveSelectionDown();
moveSelection(1);
return true;
case Qt::Key_PageUp:
moveSelection(-5);
return true;
case Qt::Key_PageDown:
moveSelection(5);
return true;
case Qt::Key_Escape:
if (m_ui->search->text().isEmpty()) {
Expand Down
3 changes: 1 addition & 2 deletions src/autotype/AutoTypeSelectDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class AutoTypeSelectDialog : public QDialog
private slots:
void submitAutoTypeMatch(AutoTypeMatch match);
void performSearch();
void moveSelectionUp();
void moveSelectionDown();
void moveSelection(int offset);
void activateCurrentMatch();
void updateActionMenu(const AutoTypeMatch& match);

Expand Down

0 comments on commit 25d456f

Please sign in to comment.