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

Add a "Copy to clipboard" menu to the Commit Files panel #4271

Merged
merged 2 commits into from
Feb 19, 2025

Conversation

stefanhaller
Copy link
Collaborator

@stefanhaller stefanhaller commented Feb 15, 2025

  • PR Description

Add a "Copy to clipboard" menu to the Commit Files panel

This is very similar to the same menu in the Files panel, except that it works on whatever diff is currently shown in the main view, including range diffs either in diffing mode (shift-W), or from a range selection of commits.

The menu has some code duplication with the existing menu in the Files panel, but actually not so much. The first two menu items could be unified once we have generalized the filetrees, but these are pretty trivial; the other two menu items are sufficiently different that unifying them is not practical, I think.

Fixes #4254.

  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

@stefanhaller stefanhaller added the enhancement New feature or request label Feb 15, 2025
@@ -41,6 +41,12 @@ func NewCommitFilesController(

func (self *CommitFilesController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
bindings := []*types.Binding{
{
Key: opts.GetKey(opts.Config.Files.CopyFileInfoToClipboard),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using a key from the Files section here, which could be considered wrong. Actually I think it's ok though, I prefer this both to adding a new one to the CommitFiles section, and to moving it into Universal. It's also not the first time we do this, we are already using a few others from the Files section here.

Copy link

codacy-production bot commented Feb 15, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for e15e4951 95.29%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (e15e495) Report Missing Report Missing Report Missing
Head commit (c919681) 53016 45920 86.62%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#4271) 170 162 95.29%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Change our fake clipboard command to not append a linefeed; that's closer to
what the production code does.

This allows us to use Equals instead of Contains for checking the clipboard
contents.

Finally, use FileSystem().FileContent() to assert the clipboard contents,
instead of selecting the clipboard file and then checking the diff view.
This is very similar to the same menu in the Files panel, except that it works
on whatever diff is currently shown in the main view, including range diffs
either in diffing mode (shift-W), or from a range selection of commits.
@stefanhaller stefanhaller force-pushed the add-clipboard-menu-to-commit-files-panel branch from 29f6b17 to c919681 Compare February 19, 2025 17:50
@stefanhaller stefanhaller merged commit 56c9d5a into master Feb 19, 2025
15 checks passed
@stefanhaller stefanhaller deleted the add-clipboard-menu-to-commit-files-panel branch February 19, 2025 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add command to copy diff in diff mode
2 participants