Strip the '+' and '-' characters when copying parts of a diff to the clipboard #4519
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This makes it easier to copy diff hunks and paste them into code. We only strip the prefixes if the copied lines are either all '+' or all '-' (possibly including context lines), otherwise we keep them. We also keep them when parts of a hunk header is included in the selection; this is useful for copying a diff hunk and pasting it into a github comment, for example.
A not-quite-correct edge case is when you select the '--- a/file.txt' line of a diff header on its own; in this case we copy it as '-- a/file.txt' (same for the '+++' line). This is probably uncommon enough that it's not worth fixing (it's not trivial to fix because we don't know that we're in a header).
Fixes #3859.
Fixes #4511.
go generate ./...
)