Skip to content

Commit c4ff2db

Browse files
committed
#132 Add sticky header option
1 parent fbff6a5 commit c4ff2db

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
@@ -465,6 +465,11 @@
465465
},
466466
"description": "An object specifying the default visibility of the Date, Author & Commit columns. Example: {\"Date\": true, \"Author\": true, \"Commit\": true}"
467467
},
468+
"git-graph.stickyHeader": {
469+
"type": "boolean",
470+
"default": true,
471+
"description": "Keeps the header visible when the view is scrolled"
472+
},
468473
"git-graph.dialog.addTag.pushToRemote": {
469474
"type": "boolean",
470475
"default": false,

src/config.ts

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

521+
/**
522+
* Get the value of the `git-graph.stickyHeader` Extension Setting.
523+
*/
524+
get stickyHeader() {
525+
return !!this.config.get('stickyHeader', true);
526+
}
527+
521528
/**
522529
* Get the value of the `git-graph.tabIconColourTheme` Extension Setting.
523530
*/

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,
@@ -629,9 +630,10 @@ export class GitGraphView extends Disposable {
629630
<p class="unableToLoadMessage">${UNABLE_TO_FIND_GIT_MSG}</p>
630631
</body>`;
631632
} else if (numRepos > 0) {
633+
const stickyClassAttr = initialState.config.stickyHeader ? ' class="sticky"' : '';
632634
body = `<body>
633635
<div id="view" tabindex="-1">
634-
<div id="controls">
636+
<div id="controls"${stickyClassAttr}>
635637
<span id="repoControl"><span class="unselectable">Repo: </span><div id="repoDropdown" class="dropdown"></div></span>
636638
<span id="branchControl"><span class="unselectable">Branches: </span><div id="branchDropdown" class="dropdown"></div></span>
637639
<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
@@ -236,6 +236,7 @@ export interface GitGraphViewConfig {
236236
readonly repoDropdownOrder: RepoDropdownOrder;
237237
readonly showRemoteBranches: boolean;
238238
readonly showTags: boolean;
239+
readonly stickyHeader: boolean;
239240
}
240241

241242
export interface GitGraphViewGlobalState {

tests/config.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4233,4 +4233,66 @@ describe('Config', () => {
42334233
expect(value).toBe(false);
42344234
});
42354235
});
4236+
4237+
describe('stickyHeader', () => {
4238+
it('Should return TRUE when the configuration value is TRUE', () => {
4239+
// Setup
4240+
workspaceConfiguration.get.mockReturnValueOnce(true);
4241+
4242+
// Run
4243+
const value = config.stickyHeader;
4244+
4245+
// Assert
4246+
expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
4247+
expect(value).toBe(true);
4248+
});
4249+
4250+
it('Should return FALSE when the configuration value is FALSE', () => {
4251+
// Setup
4252+
workspaceConfiguration.get.mockReturnValueOnce(false);
4253+
4254+
// Run
4255+
const value = config.stickyHeader;
4256+
4257+
// Assert
4258+
expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
4259+
expect(value).toBe(false);
4260+
});
4261+
4262+
it('Should return TRUE when the configuration value is truthy', () => {
4263+
// Setup
4264+
workspaceConfiguration.get.mockReturnValueOnce(5);
4265+
4266+
// Run
4267+
const value = config.stickyHeader;
4268+
4269+
// Assert
4270+
expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
4271+
expect(value).toBe(true);
4272+
});
4273+
4274+
it('Should return FALSE when the configuration value is falsy', () => {
4275+
// Setup
4276+
workspaceConfiguration.get.mockReturnValueOnce(0);
4277+
4278+
// Run
4279+
const value = config.stickyHeader;
4280+
4281+
// Assert
4282+
expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
4283+
expect(value).toBe(false);
4284+
});
4285+
4286+
it('Should return the default value (TRUE) when the configuration value is not set', () => {
4287+
// Setup
4288+
workspaceConfiguration.get.mockImplementationOnce((_, defaultValue) => defaultValue);
4289+
4290+
// Run
4291+
const value = config.stickyHeader;
4292+
4293+
// Assert
4294+
expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
4295+
expect(value).toBe(true);
4296+
});
4297+
});
42364298
});

web/main.ts

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

739-
let html = '<tr id="tableColHeaders"><th id="tableHeaderGraphCol" class="tableColHeader" data-col="0">Graph</th><th class="tableColHeader" data-col="1">Description</th>' +
739+
const stickyClassAttr = this.config.stickyHeader ? ' class="sticky"' : '';
740+
let html = '<tr id="tableColHeaders"' + stickyClassAttr + '><th id="tableHeaderGraphCol" class="tableColHeader" data-col="0">Graph</th><th class="tableColHeader" data-col="1">Description</th>' +
740741
(colVisibility.date ? '<th class="tableColHeader dateCol" data-col="2">Date</th>' : '') +
741742
(colVisibility.author ? '<th class="tableColHeader authorCol" data-col="3">Author</th>' : '') +
742743
(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
@@ -215,7 +215,8 @@ body.selection-background-color-exists ::selection{
215215
padding:0 4px;
216216
}
217217
#commitTable th{
218-
border-bottom:1px solid rgba(128,128,128,0.5);
218+
border-bottom:1px solid transparent;
219+
box-shadow: 0 1px 0 rgba(128,128,128,0.5);
219220
line-height:18px;
220221
padding:6px 12px;
221222
}
@@ -278,6 +279,12 @@ body.selection-background-color-exists ::selection{
278279
.tableColHeader{
279280
position:relative;
280281
}
282+
#tableColHeaders.sticky .tableColHeader {
283+
position: sticky;
284+
top: 41px;
285+
z-index: 3;
286+
background-color: var(--vscode-editor-background);
287+
}
281288
.resizeCol{
282289
position:absolute;
283290
top:0;
@@ -766,11 +773,12 @@ body.tagLabelsRightAligned .gitRef.tag{
766773

767774
#controls{
768775
display:block;
769-
position:relative;
776+
position: relative;
770777
left:0;
771778
right:0;
772779
top:0;
773780
padding:4px 132px 4px 0;
781+
background-color: var(--vscode-editor-background);
774782
border-bottom:1px solid rgba(128,128,128,0.5);
775783
line-height:32px;
776784
text-align:center;
@@ -780,6 +788,11 @@ body.tagLabelsRightAligned .gitRef.tag{
780788
user-select:none;
781789
}
782790

791+
#controls.sticky {
792+
position:sticky;
793+
z-index: 4;
794+
}
795+
783796
#repoControl, #branchControl, #showRemoteBranchesControl{
784797
display:inline-block;
785798
white-space:nowrap;

0 commit comments

Comments
 (0)