mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-25 07:19:42 -05:00
Allow copying passwords directly from searching
* Reverts removal of previously implemented feature * Fix #2630 * Make gui search tests more robust
This commit is contained in:
parent
88c8cdd800
commit
71e375aff0
@ -1,5 +1,4 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Jonathan White <support@dmapps.us>
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@ -97,6 +96,13 @@ bool SearchWidget::eventFilter(QObject* obj, QEvent* event)
|
||||
if (keyEvent->key() == Qt::Key_Escape) {
|
||||
emit escapePressed();
|
||||
return true;
|
||||
} else if (keyEvent->matches(QKeySequence::Copy)) {
|
||||
// If Control+C is pressed in the search edit when no text
|
||||
// is selected, copy the password of the current entry.
|
||||
if (!m_ui->searchEdit->hasSelectedText()) {
|
||||
emit copyPressed();
|
||||
return true;
|
||||
}
|
||||
} else if (keyEvent->matches(QKeySequence::MoveToNextLine)) {
|
||||
if (m_ui->searchEdit->cursorPosition() == m_ui->searchEdit->text().length()) {
|
||||
// If down is pressed at EOL, move the focus to the entry view
|
||||
|
@ -849,19 +849,31 @@ void TestGui::testSearch()
|
||||
QTRY_VERIFY(searchTextEdit->hasFocus());
|
||||
QTest::keyClick(searchTextEdit, Qt::Key_Down);
|
||||
QTRY_VERIFY(entryView->hasFocus());
|
||||
auto* searchedEntry = entryView->currentEntry();
|
||||
// Restore focus and search text selection
|
||||
QTest::keyClick(m_mainWindow.data(), Qt::Key_F, Qt::ControlModifier);
|
||||
QTRY_COMPARE(searchTextEdit->selectedText(), QString("someTHING"));
|
||||
QTRY_VERIFY(searchTextEdit->hasFocus());
|
||||
|
||||
searchedEntry->setPassword("password");
|
||||
QClipboard* clipboard = QApplication::clipboard();
|
||||
|
||||
// Attempt password copy with selected test (should fail)
|
||||
QTest::keyClick(searchTextEdit, Qt::Key_C, Qt::ControlModifier);
|
||||
QVERIFY(clipboard->text() != searchedEntry->password());
|
||||
// Deselect text and confirm password copies
|
||||
QTest::mouseClick(searchTextEdit, Qt::LeftButton);
|
||||
QTRY_VERIFY(searchTextEdit->selectedText().isEmpty());
|
||||
QTRY_VERIFY(searchTextEdit->hasFocus());
|
||||
QTest::keyClick(searchTextEdit, Qt::Key_C, Qt::ControlModifier);
|
||||
QCOMPARE(searchedEntry->password(), clipboard->text());
|
||||
// Ensure Down focuses on entry view when search text is selected
|
||||
QTest::keyClick(searchTextEdit, Qt::Key_Down);
|
||||
QTRY_VERIFY(entryView->hasFocus());
|
||||
QCOMPARE(entryView->selectionModel()->currentIndex().row(), 0);
|
||||
// Test that password copies (entry has focus)
|
||||
QClipboard* clipboard = QApplication::clipboard();
|
||||
QCOMPARE(entryView->currentEntry(), searchedEntry);
|
||||
// Test that password copies with entry focused
|
||||
QTest::keyClick(entryView, Qt::Key_C, Qt::ControlModifier);
|
||||
QModelIndex searchedItem = entryView->model()->index(0, 1);
|
||||
Entry* searchedEntry = entryView->entryFromIndex(searchedItem);
|
||||
QTRY_COMPARE(searchedEntry->password(), clipboard->text());
|
||||
QCOMPARE(searchedEntry->password(), clipboard->text());
|
||||
// Refocus back to search edit
|
||||
QTest::mouseClick(searchTextEdit, Qt::LeftButton);
|
||||
QTRY_VERIFY(searchTextEdit->hasFocus());
|
||||
|
Loading…
Reference in New Issue
Block a user