Skip to content

Commit d074ce6

Browse files
committed
mhutchie#132 Add sticky header option
1 parent b9112e6 commit d074ce6

File tree

7 files changed

+35
-4
lines changed

7 files changed

+35
-4
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,11 @@
493493
},
494494
"description": "An object specifying the default visibility of the Date, Author & Commit columns. Example: {\"Date\": true, \"Author\": true, \"Commit\": true}"
495495
},
496+
"git-graph.stickyHeader": {
497+
"type": "boolean",
498+
"default": true,
499+
"description": "Keeps the header visible when the view is scrolled"
500+
},
496501
"git-graph.dialog.addTag.pushToRemote": {
497502
"type": "boolean",
498503
"default": false,

src/config.ts

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

548+
/**
549+
* Get the value of the `git-graph.stickyHeader` Extension Setting.
550+
*/
551+
get stickyHeader() {
552+
return !!this.config.get('stickyHeader', true);
553+
}
554+
548555
/**
549556
* Get the value of the `git-graph.tabIconColourTheme` Extension Setting.
550557
*/

src/gitGraphView.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ export class GitGraphView extends Disposable {
639639
customPullRequestProviders: config.customPullRequestProviders,
640640
dateFormat: config.dateFormat,
641641
defaultColumnVisibility: config.defaultColumnVisibility,
642+
stickyHeader: config.stickyHeader,
642643
dialogDefaults: config.dialogDefaults,
643644
enhancedAccessibility: config.enhancedAccessibility,
644645
fetchAndPrune: config.fetchAndPrune,
@@ -681,9 +682,10 @@ export class GitGraphView extends Disposable {
681682
<p class="unableToLoadMessage">${UNABLE_TO_FIND_GIT_MSG}</p>
682683
</body>`;
683684
} else if (numRepos > 0) {
685+
const stickyClassAttr = initialState.config.stickyHeader ? ' class="sticky"' : '';
684686
body = `<body>
685687
<div id="view" tabindex="-1">
686-
<div id="controls">
688+
<div id="controls"${stickyClassAttr}>
687689
<span id="repoControl"><span class="unselectable">Repo: </span><div id="repoDropdown" class="dropdown"></div></span>
688690
<span id="branchControl"><span class="unselectable">Branches: </span><div id="branchDropdown" class="dropdown"></div></span>
689691
<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
@@ -260,6 +260,7 @@ export interface GitGraphViewConfig {
260260
readonly showRemoteBranches: boolean;
261261
readonly showStashes: boolean;
262262
readonly showTags: boolean;
263+
readonly stickyHeader: boolean;
263264
}
264265

265266
export interface GitGraphViewGlobalState {

tests/config.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2845,6 +2845,8 @@ describe('Config', () => {
28452845

28462846
describe('showStatusBarItem', testBooleanExtensionSetting('showStatusBarItem', 'showStatusBarItem', true));
28472847

2848+
describe('stickyHeader', testBooleanExtensionSetting('stickyHeader', 'stickyHeader', true));
2849+
28482850
describe('tabIconColourTheme', () => {
28492851
it('Should return TabIconColourTheme.Colour when the configuration value is "colour"', () => {
28502852
// Setup

web/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,8 @@ class GitGraphView {
818818
markdown: this.config.markdown
819819
});
820820

821-
let html = '<tr id="tableColHeaders"><th id="tableHeaderGraphCol" class="tableColHeader" data-col="0">Graph</th><th class="tableColHeader" data-col="1">Description</th>' +
821+
const stickyClassAttr = this.config.stickyHeader ? ' class="sticky"' : '';
822+
let html = '<tr id="tableColHeaders"' + stickyClassAttr + '><th id="tableHeaderGraphCol" class="tableColHeader" data-col="0">Graph</th><th class="tableColHeader" data-col="1">Description</th>' +
822823
(colVisibility.date ? '<th class="tableColHeader dateCol" data-col="2">Date</th>' : '') +
823824
(colVisibility.author ? '<th class="tableColHeader authorCol" data-col="3">Author</th>' : '') +
824825
(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
@@ -214,7 +214,8 @@ code{
214214
padding:0 4px;
215215
}
216216
#commitTable th{
217-
border-bottom:1px solid rgba(128,128,128,0.5);
217+
border-bottom:1px solid transparent;
218+
box-shadow: 0 1px 0 rgba(128,128,128,0.5);
218219
line-height:18px;
219220
padding:6px 12px;
220221
}
@@ -277,6 +278,12 @@ code{
277278
.tableColHeader{
278279
position:relative;
279280
}
281+
#tableColHeaders.sticky .tableColHeader {
282+
position: sticky;
283+
top: 41px;
284+
z-index: 3;
285+
background-color: var(--vscode-editor-background);
286+
}
280287
.resizeCol{
281288
position:absolute;
282289
top:0;
@@ -776,11 +783,12 @@ body.tagLabelsRightAligned .gitRef.tag{
776783

777784
#controls{
778785
display:block;
779-
position:relative;
786+
position: relative;
780787
left:0;
781788
right:0;
782789
top:0;
783790
padding:4px 132px 4px 0;
791+
background-color: var(--vscode-editor-background);
784792
border-bottom:1px solid rgba(128,128,128,0.5);
785793
line-height:32px;
786794
text-align:center;
@@ -790,6 +798,11 @@ body.tagLabelsRightAligned .gitRef.tag{
790798
user-select:none;
791799
}
792800

801+
#controls.sticky {
802+
position:sticky;
803+
z-index: 4;
804+
}
805+
793806
#repoControl, #branchControl, #showRemoteBranchesControl{
794807
display:inline-block;
795808
white-space:nowrap;

0 commit comments

Comments
 (0)