Skip to content

Commit 362f65d

Browse files
committed
#132 Add sticky header option
1 parent f10111f commit 362f65d

File tree

7 files changed

+95
-4
lines changed

7 files changed

+95
-4
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@
460460
},
461461
"description": "An object specifying the default visibility of the Date, Author & Commit columns. Example: {\"Date\": true, \"Author\": true, \"Commit\": true}"
462462
},
463+
"git-graph.stickyHeader": {
464+
"type": "boolean",
465+
"default": true,
466+
"description": "Keeps the header visible when the view is scrolled"
467+
},
463468
"git-graph.dialog.addTag.pushToRemote": {
464469
"type": "boolean",
465470
"default": false,

src/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,13 @@ class Config {
489489
return !!this.config.get('showStatusBarItem', true);
490490
}
491491

492+
/**
493+
* Get the value of the `git-graph.stickyHeader` Extension Setting.
494+
*/
495+
get stickyHeader() {
496+
return !!this.config.get('stickyHeader', true);
497+
}
498+
492499
/**
493500
* Get the value of the `git-graph.tabIconColourTheme` Extension Setting.
494501
*/

src/gitGraphView.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ export class GitGraphView extends Disposable {
589589
customPullRequestProviders: config.customPullRequestProviders,
590590
dateFormat: config.dateFormat,
591591
defaultColumnVisibility: config.defaultColumnVisibility,
592+
stickyHeader: config.stickyHeader,
592593
dialogDefaults: config.dialogDefaults,
593594
enhancedAccessibility: config.enhancedAccessibility,
594595
fetchAndPrune: config.fetchAndPrune,
@@ -628,9 +629,10 @@ export class GitGraphView extends Disposable {
628629
<p class="unableToLoadMessage">${UNABLE_TO_FIND_GIT_MSG}</p>
629630
</body>`;
630631
} else if (numRepos > 0) {
632+
const stickyClassAttr = initialState.config.stickyHeader ? ' class="sticky"' : '';
631633
body = `<body>
632634
<div id="view" tabindex="-1">
633-
<div id="controls">
635+
<div id="controls"${stickyClassAttr}>
634636
<span id="repoControl"><span class="unselectable">Repo: </span><div id="repoDropdown" class="dropdown"></div></span>
635637
<span id="branchControl"><span class="unselectable">Branches: </span><div id="branchDropdown" class="dropdown"></div></span>
636638
<label id="showRemoteBranchesControl"><input type="checkbox" id="showRemoteBranchesCheckbox" tabindex="-1"><span class="customCheckbox"></span>Show Remote Branches</label>

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ export interface GitGraphViewConfig {
235235
readonly repoDropdownOrder: RepoDropdownOrder;
236236
readonly showRemoteBranches: boolean;
237237
readonly showTags: boolean;
238+
readonly stickyHeader: boolean;
238239
}
239240

240241
export interface GitGraphViewGlobalState {

tests/config.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3878,4 +3878,66 @@ describe('Config', () => {
38783878
expect(value).toBe(false);
38793879
});
38803880
});
3881+
3882+
describe('stickyHeader', () => {
3883+
it('Should return TRUE when the configuration value is TRUE', () => {
3884+
// Setup
3885+
workspaceConfiguration.get.mockReturnValueOnce(true);
3886+
3887+
// Run
3888+
const value = config.stickyHeader;
3889+
3890+
// Assert
3891+
expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
3892+
expect(value).toBe(true);
3893+
});
3894+
3895+
it('Should return FALSE when the configuration value is FALSE', () => {
3896+
// Setup
3897+
workspaceConfiguration.get.mockReturnValueOnce(false);
3898+
3899+
// Run
3900+
const value = config.stickyHeader;
3901+
3902+
// Assert
3903+
expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
3904+
expect(value).toBe(false);
3905+
});
3906+
3907+
it('Should return TRUE when the configuration value is truthy', () => {
3908+
// Setup
3909+
workspaceConfiguration.get.mockReturnValueOnce(5);
3910+
3911+
// Run
3912+
const value = config.stickyHeader;
3913+
3914+
// Assert
3915+
expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
3916+
expect(value).toBe(true);
3917+
});
3918+
3919+
it('Should return FALSE when the configuration value is falsy', () => {
3920+
// Setup
3921+
workspaceConfiguration.get.mockReturnValueOnce(0);
3922+
3923+
// Run
3924+
const value = config.stickyHeader;
3925+
3926+
// Assert
3927+
expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
3928+
expect(value).toBe(false);
3929+
});
3930+
3931+
it('Should return the default value (TRUE) when the configuration value is not set', () => {
3932+
// Setup
3933+
workspaceConfiguration.get.mockImplementationOnce((_, defaultValue) => defaultValue);
3934+
3935+
// Run
3936+
const value = config.stickyHeader;
3937+
3938+
// Assert
3939+
expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
3940+
expect(value).toBe(true);
3941+
});
3942+
});
38813943
});

web/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,8 @@ class GitGraphView {
734734
markdown: this.config.markdown
735735
});
736736

737-
let html = '<tr id="tableColHeaders"><th id="tableHeaderGraphCol" class="tableColHeader" data-col="0">Graph</th><th class="tableColHeader" data-col="1">Description</th>' +
737+
const stickyClassAttr = this.config.stickyHeader ? ' class="sticky"' : '';
738+
let html = '<tr id="tableColHeaders"' + stickyClassAttr + '><th id="tableHeaderGraphCol" class="tableColHeader" data-col="0">Graph</th><th class="tableColHeader" data-col="1">Description</th>' +
738739
(colVisibility.date ? '<th class="tableColHeader dateCol" data-col="2">Date</th>' : '') +
739740
(colVisibility.author ? '<th class="tableColHeader authorCol" data-col="3">Author</th>' : '') +
740741
(colVisibility.commit ? '<th class="tableColHeader" data-col="4">Commit</th>' : '') +

web/styles/main.css

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ body.selection-background-color-exists ::selection{
210210
padding:0 4px;
211211
}
212212
#commitTable th{
213-
border-bottom:1px solid rgba(128,128,128,0.5);
213+
border-bottom:1px solid transparent;
214+
box-shadow: 0 1px 0 rgba(128,128,128,0.5);
214215
line-height:18px;
215216
padding:6px 12px;
216217
}
@@ -273,6 +274,12 @@ body.selection-background-color-exists ::selection{
273274
.tableColHeader{
274275
position:relative;
275276
}
277+
#tableColHeaders.sticky .tableColHeader {
278+
position: sticky;
279+
top: 41px;
280+
z-index: 3;
281+
background-color: var(--vscode-editor-background);
282+
}
276283
.resizeCol{
277284
position:absolute;
278285
top:0;
@@ -759,11 +766,12 @@ body.tagLabelsRightAligned .gitRef.tag{
759766

760767
#controls{
761768
display:block;
762-
position:relative;
769+
position: relative;
763770
left:0;
764771
right:0;
765772
top:0;
766773
padding:4px 132px 4px 0;
774+
background-color: var(--vscode-editor-background);
767775
border-bottom:1px solid rgba(128,128,128,0.5);
768776
line-height:32px;
769777
text-align:center;
@@ -773,6 +781,11 @@ body.tagLabelsRightAligned .gitRef.tag{
773781
user-select:none;
774782
}
775783

784+
#controls.sticky {
785+
position:sticky;
786+
z-index: 4;
787+
}
788+
776789
#repoControl, #branchControl, #showRemoteBranchesControl{
777790
display:inline-block;
778791
white-space:nowrap;

0 commit comments

Comments
 (0)