Skip to content

Commit 6db4aae

Browse files
authored
Merge pull request #456 from ericcornelissen/455-sticky-file-headers
Implement support for sticky file headers
2 parents 35008fb + 4dae65d commit 6db4aae

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ draw(): void
156156
synchronisedScroll(): void
157157
fileListToggle(startVisible: boolean): void
158158
highlightCode(): void
159+
stickyFileHeaders(): void
159160
```
160161

161162
### Diff2HtmlUI Configuration
@@ -165,6 +166,7 @@ highlightCode(): void
165166
- `fileListToggle`: allow the file summary list to be toggled: `true` or `false`, default is `true`
166167
- `fileListStartVisible`: choose if the file summary list starts visible: `true` or `false`, default is `false`
167168
- `fileContentToggle`: allow each file contents to be toggled: `true` or `false`, default is `true`
169+
- `stickyFileHeaders`: make file headers sticky: `true` or `false`, default is `true`
168170
- [All the options](#diff2html-configuration) from Diff2Html are also valid configurations in Diff2HtmlUI
169171

170172
### Diff2HtmlUI Browser

src/ui/css/diff2html.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
background-color: #f7f7f7;
1818
font-family: 'Source Sans Pro', 'Helvetica Neue', Helvetica, Arial, sans-serif;
1919
}
20+
.d2h-file-header.d2h-sticky-header {
21+
position: sticky;
22+
top: 0;
23+
z-index: 1;
24+
}
2025

2126
.d2h-file-stats {
2227
display: -webkit-box;

src/ui/js/diff2html-ui-base.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface Diff2HtmlUIConfig extends Diff2HtmlConfig {
1616
*/
1717
smartSelection?: boolean;
1818
fileContentToggle?: boolean;
19+
stickyFileHeaders?: boolean;
1920
}
2021

2122
export const defaultDiff2HtmlUIConfig = {
@@ -31,6 +32,7 @@ export const defaultDiff2HtmlUIConfig = {
3132
*/
3233
smartSelection: true,
3334
fileContentToggle: true,
35+
stickyFileHeaders: true,
3436
};
3537

3638
export class Diff2HtmlUI {
@@ -54,6 +56,7 @@ export class Diff2HtmlUI {
5456
if (this.config.highlight) this.highlightCode();
5557
if (this.config.fileListToggle) this.fileListToggle(this.config.fileListStartVisible);
5658
if (this.config.fileContentToggle) this.fileContentToggle();
59+
if (this.config.stickyFileHeaders) this.stickyFileHeaders();
5760
}
5861

5962
synchronisedScroll(): void {
@@ -192,6 +195,12 @@ export class Diff2HtmlUI {
192195
});
193196
}
194197

198+
stickyFileHeaders(): void {
199+
this.targetElement.querySelectorAll('.d2h-file-header').forEach(header => {
200+
header.classList.add('d2h-sticky-header');
201+
});
202+
}
203+
195204
/**
196205
* @deprecated since version 3.1.0
197206
*/

0 commit comments

Comments
 (0)