mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-11-26 03:46:49 -08:00
Fix Copy Password button when text is selected
When the user chooses to copy the password for an entry to the clipboard, previously there was logic to check if text was selected, and if so, that text was instead copied to the clipboard. That made sense if (a) the user invoked the Copy Password action via its keyboard shortcut, and (b) that keyboard shortcut was configured (as per default) to be Ctrl-C, i.e. the same as the system action for copy-to-clipboard. However, it made no sense if the user invoked that action in some other way, for example by clicking the corresponding toolbar button. It also made no sense in the case that the Copy Password action had some other keyboard shortcut assigned. Also, if some other action had Ctrl-C assigned, the logic would not kick in then. Fix all of the above by modifying the keyboard shortcut logic to intervene precisely in the case where a shortcut is pressed that matches the system copy-to-clipboard shortcut; only in that case do we now check if text is selected and if so copy that to the clipboard instead of the action we would otherwise take. Fixes #10734.
This commit is contained in:
5 files changed
+77
-23
No files matched your search
@@ -77,6 +77,28 @@
|
||||
#include "mainwindowadaptor.h"
|
||||
#endif
|
||||
|
||||
// This filter gets installed on all the QAction objects within the MainWindow.
|
||||
bool ActionEventFilter::eventFilter(QObject* watched, QEvent* event)
|
||||
{
|
||||
auto databaseWidget = getMainWindow()->m_ui->tabWidget->currentDatabaseWidget();
|
||||
if (databaseWidget && event->type() == QEvent::Shortcut) {
|
||||
// We check if we got a Shortcut event that uses the same key sequence as the
|
||||
// OS default copy-to-clipboard shortcut.
|
||||
static const auto stdCopyShortcuts = QKeySequence::keyBindings(QKeySequence::Copy);
|
||||
if (stdCopyShortcuts.contains(static_cast<QShortcutEvent*>(event)->key())) {
|
||||
// If so, we ask the database widget to check if any of its sub-widgets has text
|
||||
// selected, and to copy it to the clipboard if that is the case. We do this
|
||||
// because that is what the user likely expects to happen, yet Qt does not
|
||||
// behave like that on all platforms.
|
||||
if (databaseWidget->copyFocusedTextSelection()) {
|
||||
// In that case, we return true to stop further processing of this event.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return QObject::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
const QString MainWindow::BaseWindowTitle = "KeePassXC";
|
||||
|
||||
MainWindow* g_MainWindow = nullptr;
|
||||
@@ -450,6 +472,9 @@ MainWindow::MainWindow()
|
||||
m_ui->actionEntryRemovePasskey->setIcon(icons()->icon("document-close"));
|
||||
#endif
|
||||
|
||||
// Handle copy to clipboard shortcut interference
|
||||
m_ui->actionEntryCopyPassword->installEventFilter(&m_actionEventFilter);
|
||||
|
||||
m_actionMultiplexer.connect(
|
||||
SIGNAL(currentModeChanged(DatabaseWidget::Mode)), this, SLOT(setMenuActionState(DatabaseWidget::Mode)));
|
||||
m_actionMultiplexer.connect(SIGNAL(groupChanged()), this, SLOT(setMenuActionState()));
|
||||
|
||||
Reference in new issue
Block a user