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

Auto-Type: Remember previous selected global match #7129

Merged

Conversation

hifi
Copy link
Member

@hifi hifi commented Nov 16, 2021

This makes using multi-stage login forms slightly easier as you can avoid typing the search terms multiple times. The last match is invalidated after 30 seconds which should be plenty if you are going through a login form.

Inspired by #5864 (comment) to avoid needing a complex sequence in the first place.

Testing strategy

Manually on Linux.

Type of change

  • ✅ New feature (change that adds functionality)

@hifi hifi requested a review from droidmonkey November 16, 2021 07:16
@hifi hifi marked this pull request as draft November 16, 2021 07:26
@hifi hifi force-pushed the feature/autotype-remember-last branch from b5f2d6a to 8b039e2 Compare November 16, 2021 07:34
@codecov-commenter
Copy link

codecov-commenter commented Nov 16, 2021

Codecov Report

Merging #7129 (3c3fa2d) into develop (a3dc977) will decrease coverage by 0.05%.
The diff coverage is 4.05%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #7129      +/-   ##
===========================================
- Coverage    64.21%   64.16%   -0.05%     
===========================================
  Files          334      334              
  Lines        42221    42257      +36     
===========================================
+ Hits         27109    27112       +3     
- Misses       15112    15145      +33     
Impacted Files Coverage Δ
src/autotype/AutoType.h 100.00% <ø> (ø)
src/autotype/AutoTypeMatchModel.cpp 0.00% <0.00%> (ø)
src/autotype/AutoTypeMatchView.cpp 0.00% <0.00%> (ø)
src/autotype/AutoTypeSelectDialog.cpp 0.00% <0.00%> (ø)
src/autotype/AutoType.cpp 74.52% <42.86%> (-0.36%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a3dc977...3c3fa2d. Read the comment docs.

@hifi hifi marked this pull request as ready for review November 16, 2021 08:37
Copy link

@michaelk83 michaelk83 left a comment

Choose a reason for hiding this comment

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

This could use a doc update: how do you set up the Auto-Type sequences etc for multi-page login with this change?

@@ -35,7 +35,7 @@ class AutoTypeMatchView : public QTableView
explicit AutoTypeMatchView(QWidget* parent = nullptr);
AutoTypeMatch currentMatch();
AutoTypeMatch matchFromIndex(const QModelIndex& index);
void setMatchList(const QList<AutoTypeMatch>& matches, bool selectFirst);
void setMatchList(const QList<AutoTypeMatch>& matches, int selectedIndex, bool selectFirst);

Choose a reason for hiding this comment

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

selectFirst looks redundant with selectedIndex.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not actually redundant. selectedIndex is an index to the match list and not an index to the sorted view. I need to be able to distinguish from selecting the first visible item in the list and the first item in the input list. If it can be easily compressed into a single argument that makes sense I'll gladly refactor it.

Copy link

@michaelk83 michaelk83 Nov 16, 2021

Choose a reason for hiding this comment

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

Then maybe just a rename to clarify the difference? Something like matchIndex or inputIndex or selectedMatch for selectedIndex, and selectFirstVisible for selectFirst?

(I'm still not entirely clear what selectedIndex actually does. May need to dig a little deeper in the code.)

Copy link
Member Author

Choose a reason for hiding this comment

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

We discussed this on Matrix with @droidmonkey and decided to split this into three distinct functions where setMatchList just clears the selection so the call isn't too overloaded.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've now split it into separate functions.

src/autotype/AutoTypeSelectDialog.cpp Outdated Show resolved Hide resolved
src/autotype/AutoType.cpp Outdated Show resolved Hide resolved
src/autotype/AutoTypeMatchView.cpp Outdated Show resolved Hide resolved
src/autotype/AutoTypeSelectDialog.h Show resolved Hide resolved
@droidmonkey droidmonkey added this to the v2.7.0 milestone Nov 16, 2021
@hifi
Copy link
Member Author

hifi commented Nov 16, 2021

@michaelk83 You don't need to setup anything special for Auto-Type sequences for this to work, it will just try its best to remember your last selection when you re-open the dialog with your global hotkey.

A mention of the flow in user guide would be good I presume.

src/autotype/AutoTypeMatchView.cpp Outdated Show resolved Hide resolved
src/autotype/AutoTypeSelectDialog.h Show resolved Hide resolved
src/autotype/AutoType.cpp Outdated Show resolved Hide resolved
@@ -49,6 +49,7 @@ class AutoTypeMatchModel : public QAbstractTableModel
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

void setMatchList(const QList<AutoTypeMatch>& matches);
QList<AutoTypeMatch>* matchList();
Copy link
Member

@droidmonkey droidmonkey Nov 17, 2021

Choose a reason for hiding this comment

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

I don't like this at all, we should not be returning a pointer to an internal data member. This indicates an antipattern (also Qt does a shallow copy of container objects). Instead you should create a function (or use an existing) that searches the match list for the provided match and returns the index.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a new one since we are fine with a match that matches only the entry but not the sequence.

src/autotype/AutoTypeMatchView.cpp Outdated Show resolved Hide resolved
src/autotype/AutoTypeSelectDialog.cpp Outdated Show resolved Hide resolved
@hifi hifi force-pushed the feature/autotype-remember-last branch from fe3a882 to fe3d3ad Compare November 17, 2021 19:24
@droidmonkey droidmonkey force-pushed the feature/autotype-remember-last branch from 1e6839f to 3c3fa2d Compare November 23, 2021 04:28
src/autotype/AutoTypeMatchModel.cpp Outdated Show resolved Hide resolved
{
int row = -1;

for (int i = m_matches.size() - 1; i >= 0; i--) {
Copy link
Member

Choose a reason for hiding this comment

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

--i

Comment on lines 98 to 102
m_ui->searchCheckBox->setDisabled(m_matches.isEmpty());

m_ui->view->setMatchList(m_matches, !m_matches.isEmpty() || !m_ui->search->text().isEmpty());
m_ui->searchCheckBox->setChecked(m_matches.isEmpty());
// changing check also performs search
if (m_ui->searchCheckBox->isChecked() != m_matches.isEmpty()) {
m_ui->searchCheckBox->setChecked(m_matches.isEmpty());
Copy link
Member

Choose a reason for hiding this comment

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

We use m_matches.isEmpty() three times, lets give it a variable name for ease of reading: bool noMatches = m_matches.isEmpty()

I also have to read this if statement several times to understand what is going on. I think we should just always set the search checkbox here to the noMatches boolean and get rid of the if statement. We could suppress the checkbox signals to prevent a double search.

@hifi hifi force-pushed the feature/autotype-remember-last branch 2 times, most recently from aa03ca9 to 89d8455 Compare November 25, 2021 05:27
This makes using multi-stage login forms slightly easier as you
can avoid typing the search terms multiple times.
@hifi hifi force-pushed the feature/autotype-remember-last branch from 89d8455 to 9b2b0d4 Compare November 26, 2021 14:59
@droidmonkey droidmonkey merged commit 6060962 into keepassxreboot:develop Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants