Repository navigation
feat: show a diff side by side, the old version facing the new, and stage lines from either side - #50
Merged
Merged
Conversation
…tage lines from either side
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this changes
A diff can now be shown side by side: a "Side by side" button above it puts the old version on the left and the new one on the right. Unchanged lines are on both sides, a removed line faces the added line that replaced it (the same pairing the word highlights use), and a line that replaces nothing has an empty space beside it. Each side shows its own line numbers, the changed words still stand out, and lines can be picked for staging or discarding from either side, as before. The choice applies to every diff, also the one under a file's history, and lasts between runs.
This is part 2 of "Better diffs" on the roadmap; syntax colouring and images stay for part 3.
How it is tested
Hunk::side_by_sidein core gets a unit test on two diffs: blocks with more added than removed lines and the other way around, and "No newline at end of file" on the side of its line.A new app test opens a diff, checks the lines are one under the other, turns on side by side and checks from what is painted that the old line faces the new one, an unpaired added line is on the right, a context line is on both sides and the changed words are still marked; then it clicks a line on each side, stages them and reads the index; the next diff is side by side too, until the button turns it off. It fails without the pairing.
Tried in the app on Linux: staging one line from each side, the history view, and the choice surviving a restart.
cargo fmt --all,cargo clippy --workspace --all-targets -- -D warningsandcargo test --workspacepassIt adds as little code as the change needs, and removes what it makes unnecessary
Nothing in it comes from GitKraken or another closed-source client (see CONTRIBUTING.md)