Make selected text copyable instead of copying password

* Fixes 7209
This commit is contained in:
mckeema 2021-12-08 17:26:55 -05:00 committed by Jonathan White
parent a0a063b57f
commit 6c4a82bd51

View File

@ -24,6 +24,7 @@
#include <QDesktopServices> #include <QDesktopServices>
#include <QHostInfo> #include <QHostInfo>
#include <QKeyEvent> #include <QKeyEvent>
#include <QPlainTextEdit>
#include <QProcess> #include <QProcess>
#include <QSplitter> #include <QSplitter>
#include <QTextEdit> #include <QTextEdit>
@ -591,11 +592,26 @@ void DatabaseWidget::copyUsername()
void DatabaseWidget::copyPassword() void DatabaseWidget::copyPassword()
{ {
// QTextEdit does not properly trap Ctrl+C copy shortcut // Some platforms do not properly trap Ctrl+C copy shortcut
// if a text edit has focus pass the copy operation to it // if a text edit or label has focus pass the copy operation to it
bool clearClipboard = config()->get(Config::Security_ClearClipboard).toBool();
auto plainTextEdit = qobject_cast<QPlainTextEdit*>(focusWidget());
if (plainTextEdit) {
clipboard()->setText(plainTextEdit->textCursor().selectedText(), clearClipboard);
return;
}
auto label = qobject_cast<QLabel*>(focusWidget());
if (label) {
clipboard()->setText(label->selectedText(), clearClipboard);
return;
}
auto textEdit = qobject_cast<QTextEdit*>(focusWidget()); auto textEdit = qobject_cast<QTextEdit*>(focusWidget());
if (textEdit) { if (textEdit) {
textEdit->copy(); clipboard()->setText(textEdit->textCursor().selectedText(), clearClipboard);
return; return;
} }