Auto-Type: Remember previous selected global match

This makes using multi-stage login forms slightly easier as you
can avoid typing the search terms multiple times.
This commit is contained in:
Toni Spets
2021-11-22 15:15:05 +02:00
committed by Jonathan White
parent d3d7bd7b81
commit 606096278b
9 changed files with 117 additions and 47 deletions

View File

@@ -111,6 +111,7 @@ namespace
{"f14", Qt::Key_F14},
{"f15", Qt::Key_F15},
{"f16", Qt::Key_F16}};
static constexpr int rememberLastEntrySecs = 30;
} // namespace
AutoType* AutoType::m_instance = nullptr;
@@ -122,6 +123,8 @@ AutoType::AutoType(QObject* parent, bool test)
, m_executor(nullptr)
, m_windowState(WindowState::Normal)
, m_windowForGlobal(0)
, m_lastMatch(nullptr, QString())
, m_lastMatchTime(0)
{
// prevent crash when the plugin has unresolved symbols
m_pluginLoader->setLoadHints(QLibrary::ResolveAllSymbolsHint);
@@ -423,6 +426,11 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
return;
}
// Invalidate last match if it's old enough
if (m_lastMatch.first && (Clock::currentSecondsSinceEpoch() - m_lastMatchTime) > rememberLastEntrySecs) {
m_lastMatch = {nullptr, QString()};
}
QList<AutoTypeMatch> matchList;
bool hideExpired = config()->get(Config::AutoTypeHideExpiredEntry).toBool();
@@ -451,7 +459,7 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
getMainWindow()->closeModalWindow();
auto* selectDialog = new AutoTypeSelectDialog();
selectDialog->setMatches(matchList, dbList);
selectDialog->setMatches(matchList, dbList, m_lastMatch);
if (!search.isEmpty()) {
selectDialog->setSearchString(search);
@@ -459,6 +467,8 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
connect(getMainWindow(), &MainWindow::databaseLocked, selectDialog, &AutoTypeSelectDialog::reject);
connect(selectDialog, &AutoTypeSelectDialog::matchActivated, this, [this](const AutoTypeMatch& match) {
m_lastMatch = match;
m_lastMatchTime = Clock::currentSecondsSinceEpoch();
executeAutoTypeActions(match.first, nullptr, match.second, m_windowForGlobal);
resetAutoTypeState();
});