Skip to content

Commit bd59670

Browse files
authored
Show diffhunk headers and fine-grained "show more" buttons (#180)
* thread through hunk header * update codediff.js * fix tests
1 parent e8a72fb commit bd59670

File tree

5 files changed

+136
-50
lines changed

5 files changed

+136
-50
lines changed

tests/unified_diff_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_read_codes_delete():
102102
def test_read_codes_skip():
103103
codes = read_codes(PatchSet.from_string(skip_insert_hunk))
104104
assert codes == [
105-
Code(type='skip', before=(0, 2), after=(0, 2)),
105+
Code(type='skip', before=(0, 2), after=(0, 2), header='pytest==7.1.3'),
106106
Code(type='equal', before=(2, 5), after=(2, 5)),
107107
Code(type='insert', before=(5, 5), after=(5, 6)),
108108
Code(type='equal', before=(5, 6), after=(6, 7)),

ts/CodeDiff.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export function CodeDiff(props: {filePair: FilePair, diffOptions: Partial<DiffOp
104104
}
105105
})().catch(e => {
106106
alert('Unable to get diff!');
107+
console.error(e);
107108
});
108109
}, [filePair, diffOptions]);
109110

webdiff/static/codediff.js/codediff.css

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ td.code {
1717
/* for table cells, `width` behaves more like `max-width`. */
1818
width: 61ch;
1919
white-space: pre-wrap;
20-
overflow-wrap: anywhere;
20+
word-wrap: break-word;
21+
}
22+
23+
table.diff td.code {
24+
word-break: break-all;
25+
}
26+
table.diff.word-wrap td.code {
27+
word-break: normal;
2128
}
2229

2330
table.diff td {
@@ -32,12 +39,12 @@ table.diff td {
3239
.line-no:first-child {
3340
background-image:
3441
linear-gradient(to left, #f7f7f7, #f7f7f7 3px, transparent, transparent 6px, #f7f7f7 6px),
35-
linear-gradient(#f7f7f7, #f7f7f7 1.4em, #aaa 1.4em);
42+
linear-gradient(#f7f7f7, #f7f7f7 1.5em, #aaa 1.5em);
3643
}
3744
.line-no:last-child {
3845
background-image:
3946
linear-gradient(to right, #f7f7f7, #f7f7f7 3px, transparent, transparent 6px, #f7f7f7 6px),
40-
linear-gradient(#f7f7f7, #f7f7f7 1.4em, #aaa 1.4em);
47+
linear-gradient(#f7f7f7, #f7f7f7 1.5em, #aaa 1.5em);
4148
}
4249

4350
table.diff .line-no:first-child {
@@ -51,6 +58,13 @@ table.diff .line-no:last-child {
5158
table.diff td:nth-child(2) {
5259
border-right: 1px solid #ddd;
5360
}
61+
table.diff tr.skip-row td {
62+
border-left: none;
63+
border-right: none;
64+
border-top: 1px solid #eee;
65+
border-bottom: 1px solid #eee;
66+
padding: 0.5em;
67+
}
5468

5569
.line-no, .code {
5670
padding: 2px;
@@ -59,20 +73,31 @@ table.diff td:nth-child(2) {
5973
}
6074
.diff .skip {
6175
text-align: center;
62-
background: #f7f7f7;
76+
background: white;
77+
color: #999;
78+
}
79+
.arrows-left {
80+
float: left;
81+
}
82+
.arrows-right {
83+
float: right;
84+
}
85+
.expand-up + .expand-down {
86+
margin-left: 0.25em;
6387
}
6488

65-
.diff .delete {
66-
background-color: #fee;
89+
.hunk-header {
90+
margin-left: 2em;
91+
color: #777;
6792
}
68-
.diff .insert {
69-
background-color: #efe;
93+
span.skip {
94+
cursor: pointer;
7095
}
7196

72-
.before.replace {
97+
.diff .delete, .before.replace {
7398
background-color: #fee;
7499
}
75-
.after.replace {
100+
.diff .insert, .after.replace {
76101
background-color: #efe;
77102
}
78103

webdiff/static/codediff.js/codediff.js

Lines changed: 86 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)