Skip to content

Commit 06f3bc8

Browse files
committed
Conditionally pad images of different height
I've been debugging a diff view where the top parts of the before and after images are the same, but the before version has 100px whitespace below the content. I assumed that the images would be aligned from the top but the diff image ended looking like all the pixels were different. I found that in this particular case, moving the alignArray padding to the bottom fixes the issue. In other cases though, padding should be at the top. I used a rule-of-thumb here -- if the top row is equal between the two images, pad at the bottom. If not, pad at the top. I believe this commit makes the long-example better as well, and should improve things for a lot of diffs out there.
1 parent e9e0ba6 commit 06f3bc8

File tree

8 files changed

+9
-1
lines changed

8 files changed

+9
-1
lines changed

snapshots/long-example/diff.png

373 KB
Loading
12 KB
Loading
14 KB
Loading
14.5 KB
Loading
1.36 KB
Loading
1.62 KB
Loading
639 Bytes
Loading

src/alignArrays.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,15 @@ function applySolution(solution, a, b) {
116116
const aLength = a.length;
117117
const bLength = b.length;
118118
const shorterArray = aLength > bLength ? b : a;
119-
shorterArray.splice(0, 0, ...placeholders(Math.abs(aLength - bLength)));
119+
if (a[0] === b[0]) {
120+
shorterArray.splice(
121+
shorterArray.length - 1,
122+
0,
123+
...placeholders(Math.abs(aLength - bLength)),
124+
);
125+
} else {
126+
shorterArray.splice(0, 0, ...placeholders(Math.abs(aLength - bLength)));
127+
}
120128
}
121129

122130
/**

0 commit comments

Comments
 (0)