Skip to content

Commit

Permalink
Search entry: respect shortcut config on Copy key
Browse files Browse the repository at this point in the history
If the system Copy key sequence (i.e. Ctrl+C or Cmd+C) is pressed while
inside the search entry without any text being selected, previously we
would copy the currently selected entry's password. This made sense when
keyboard shortcuts were fixed. Now that they are configurable, change it
to re-route the event to the main window, which can then take the
appropriate action (i.e. Ctrl+C might be bound to some other action).
  • Loading branch information
c4rlo committed Jun 7, 2024
1 parent 6ee544b commit bb4b216
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/gui/SearchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "SearchWidget.h"
#include "gui/MainWindow.h"
#include "ui_SearchHelpWidget.h"
#include "ui_SearchWidget.h"

Expand Down Expand Up @@ -94,10 +95,12 @@ bool SearchWidget::eventFilter(QObject* obj, QEvent* event)
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 the system Copy shortcut (typically Ctrl+C or Cmd+C) is pressed
// in the search edit when no text is selected, route the event to the
// main window. With the default shorcut configuration, this will copy
// the password of the current entry to the clipboard.
if (!m_ui->searchEdit->hasSelectedText()) {
emit copyPressed();
QCoreApplication::sendEvent(getMainWindow(), event);
return true;
}
} else if (keyEvent->matches(QKeySequence::MoveToNextLine)) {
Expand Down Expand Up @@ -135,7 +138,6 @@ void SearchWidget::connectSignals(SignalMultiplexer& mx)
mx.connect(this, SIGNAL(saveSearch(QString)), SLOT(saveSearch(QString)));
mx.connect(this, SIGNAL(caseSensitiveChanged(bool)), SLOT(setSearchCaseSensitive(bool)));
mx.connect(this, SIGNAL(limitGroupChanged(bool)), SLOT(setSearchLimitGroup(bool)));
mx.connect(this, SIGNAL(copyPressed()), SLOT(copyPassword()));
mx.connect(this, SIGNAL(downPressed()), SLOT(focusOnEntries()));
mx.connect(SIGNAL(requestSearch(QString)), m_ui->searchEdit, SLOT(setText(QString)));
mx.connect(SIGNAL(clearSearch()), this, SLOT(clearSearch()));
Expand Down
1 change: 0 additions & 1 deletion src/gui/SearchWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class SearchWidget : public QWidget
void caseSensitiveChanged(bool state);
void limitGroupChanged(bool state);
void escapePressed();
void copyPressed();
void downPressed();
void enterPressed();
void lostFocus();
Expand Down

0 comments on commit bb4b216

Please sign in to comment.