Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Copy Password button when text is selected #10853

Merged
merged 1 commit into from
Jun 19, 2024

Conversation

c4rlo
Copy link
Contributor

@c4rlo c4rlo commented Jun 2, 2024

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.

Testing strategy

Added test to TestGui.cpp. Also confirmed via manual testing.

Type of change

  • ✅ Bug fix (non-breaking change that fixes an issue)

@droidmonkey
Copy link
Member

Love it, glad to use the new action collection too! I really couldn't figure out a fix to this, too focused on the toolbar action and not the keyboard shortcut.

@c4rlo c4rlo force-pushed the fix-copy-password-sel branch 6 times, most recently from 03f7a5a to 3830953 Compare June 7, 2024 09:05
@c4rlo c4rlo changed the title Fix Copy Password button when text is selected Fix Copy Password button when text is selected, etc. Jun 7, 2024
src/gui/MainWindow.cpp Outdated Show resolved Hide resolved
@c4rlo c4rlo marked this pull request as ready for review June 7, 2024 09:15
@c4rlo
Copy link
Contributor Author

c4rlo commented Jun 9, 2024

I actually have a slightly simpler approach now, based on QObject::installEventFilter(). Moving this back to Draft while I consider it.

@c4rlo c4rlo marked this pull request as draft June 9, 2024 20:52
@c4rlo c4rlo changed the title Fix Copy Password button when text is selected, etc. Fix Copy Password button when text is selected Jun 11, 2024
@c4rlo c4rlo force-pushed the fix-copy-password-sel branch 4 times, most recently from c602efc to 07a279b Compare June 13, 2024 20:21
@c4rlo c4rlo marked this pull request as ready for review June 13, 2024 20:21
@c4rlo
Copy link
Contributor Author

c4rlo commented Jun 13, 2024

Ok, this is ready for review now. I've undone all the refactoring and kept this more focused.

@c4rlo
Copy link
Contributor Author

c4rlo commented Jun 14, 2024

The macOS CI failure seems like some kind of test flakeyness, unrelated to this change. I have created #10901 to address that.

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.

Add a test case to TestGui.cpp.

Fixes keepassxreboot#10734.
@droidmonkey droidmonkey added this to the v2.7.9 milestone Jun 16, 2024
@droidmonkey droidmonkey added the ux label Jun 16, 2024
@droidmonkey droidmonkey self-requested a review June 16, 2024 21:19
@droidmonkey droidmonkey merged commit 9972b5f into keepassxreboot:develop Jun 19, 2024
11 checks passed
libf-de pushed a commit to libf-de/keepassxc-secretservice-dbus that referenced this pull request Jun 20, 2024
Release 2.7.9

* Passkeys: Ability to easily remove a passkey from an entry [keepassxreboot#10777]
* Snap: Use new desktop portal for native messaging integration [keepassxreboot#10906]

* Improve entry placeholder/reference feature [keepassxreboot#10846]
* Improve CSV importing when title field isn't specified [keepassxreboot#10843]
* Improve encrypted Bitwarden importing [keepassxreboot#10800]
* Improve database settings UX [keepassxreboot#10821]
* Improve handling of clipboard actions from entry preview [keepassxreboot#10810]
* Improve group/entry view resize behavior and set sensible defaults [keepassxreboot#10641]
* Passkeys: Fix incorrect username fill [keepassxreboot#10874]
* Passkeys: Return additional data to the extension [keepassxreboot#10857]
* Fix password clear timer inconsistency on unlock view [keepassxreboot#10708]
* Fix portability check [keepassxreboot#10760]
* Fix page overflow on HTML exports [keepassxreboot#10735]
* Fix broken builds when using system provided zxcvbn [keepassxreboot#10717]
* Fix copy password button when text is selected [keepassxreboot#10853]
* Fix tab ordering on application settings pages [keepassxreboot#10907]
* SSH Agent: Fix broken decrypt button [keepassxreboot#10638]
* Windows: Fix ALT Auto-Type modifier [keepassxreboot#10795]
* Windows: Fix wrong DACL memory size allocation [keepassxreboot#10712]
* macOS: Fix monospace font sizing [keepassxreboot#10739]
* Flatpak: Fix configuration settings off-by-one error [keepassxreboot#10688]
* BSD: Fix compiling with libusb implementation [keepassxreboot#10736]

# -----BEGIN PGP SIGNATURE-----
#
# iQEzBAABCAAdFiEENIkEDB8MPuq41ValRA/GXy4MbgEFAmZzTogACgkQRA/GXy4M
# bgHahggAg+hzMTiM0uDaw5yfxhv6GEfQQBPHMhX3JDyHEC+i7Pq6OjlxQkdUrRdu
# f4w74od5jSul0Al/ehu9L2eZwNPMnU87FWDn16o1btYHsG9n24v5S0DuQoLXUjde
# Y9nJNKeRNoWAlVKWbUG2YGvy9hF9YbtrFaiBksaQ+g3w8Xz82PzLY0VaUu4Xa/LO
# RXAhryJC+8T3T479dXpHxJcUmEWkoY4bqj1i6R8tEK5Kz9y1c0kqzqwWysKMj+rD
# WxTb2V4y9s57pO35zt9yxMLg66xx9bdcQHbSULa2vZNMFd9qdqk8WJmWFle112yG
# UCBXv2ZIjd3lghPt0IrD+WKcuL85Aw==
# =rbfs
# -----END PGP SIGNATURE-----
# gpg: directory '/home/runner/.gnupg' created
# gpg: keybox '/home/runner/.gnupg/pubring.kbx' created
# gpg: Signature made Wed Jun 19 21:32:56 2024 UTC
# gpg:                using RSA key 3489040C1F0C3EEAB8D556A5440FC65F2E0C6E01
# gpg: Can't check signature: No public key
Perlover added a commit to Perlover/keepassxc that referenced this pull request Jul 24, 2024
Release 2.7.9

* Passkeys: Ability to easily remove a passkey from an entry [keepassxreboot#10777]
* Snap: Use new desktop portal for native messaging integration [keepassxreboot#10906]

* Improve entry placeholder/reference feature [keepassxreboot#10846]
* Improve CSV importing when title field isn't specified [keepassxreboot#10843]
* Improve encrypted Bitwarden importing [keepassxreboot#10800]
* Improve database settings UX [keepassxreboot#10821]
* Improve handling of clipboard actions from entry preview [keepassxreboot#10810]
* Improve group/entry view resize behavior and set sensible defaults [keepassxreboot#10641]
* Passkeys: Fix incorrect username fill [keepassxreboot#10874]
* Passkeys: Return additional data to the extension [keepassxreboot#10857]
* Fix password clear timer inconsistency on unlock view [keepassxreboot#10708]
* Fix portability check [keepassxreboot#10760]
* Fix page overflow on HTML exports [keepassxreboot#10735]
* Fix broken builds when using system provided zxcvbn [keepassxreboot#10717]
* Fix copy password button when text is selected [keepassxreboot#10853]
* Fix tab ordering on application settings pages [keepassxreboot#10907]
* SSH Agent: Fix broken decrypt button [keepassxreboot#10638]
* Windows: Fix ALT Auto-Type modifier [keepassxreboot#10795]
* Windows: Fix wrong DACL memory size allocation [keepassxreboot#10712]
* macOS: Fix monospace font sizing [keepassxreboot#10739]
* Flatpak: Fix configuration settings off-by-one error [keepassxreboot#10688]
* BSD: Fix compiling with libusb implementation [keepassxreboot#10736]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Password is not copied when other text is selected in KeePassXC
2 participants