Skip to content

Commit 0095197

Browse files
committed
#132 Add sticky header option
1 parent a176f2e commit 0095197

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
@@ -470,6 +470,11 @@
470470
},
471471
"description": "An object specifying the default visibility of the Date, Author & Commit columns. Example: {\"Date\": true, \"Author\": true, \"Commit\": true}"
472472
},
473+
"git-graph.stickyHeader": {
474+
"type": "boolean",
475+
"default": true,
476+
"description": "Keeps the header visible when the view is scrolled"
477+
},
473478
"git-graph.dialog.addTag.pushToRemote": {
474479
"type": "boolean",
475480
"default": false,

src/config.ts

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

537+
/**
538+
* Get the value of the `git-graph.stickyHeader` Extension Setting.
539+
*/
540+
get stickyHeader() {
541+
return !!this.config.get('stickyHeader', true);
542+
}
543+
537544
/**
538545
* Get the value of the `git-graph.tabIconColourTheme` Extension Setting.
539546
*/

src/gitGraphView.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ export class GitGraphView extends Disposable {
624624
customPullRequestProviders: config.customPullRequestProviders,
625625
dateFormat: config.dateFormat,
626626
defaultColumnVisibility: config.defaultColumnVisibility,
627+
stickyHeader: config.stickyHeader,
627628
dialogDefaults: config.dialogDefaults,
628629
enhancedAccessibility: config.enhancedAccessibility,
629630
fetchAndPrune: config.fetchAndPrune,
@@ -666,9 +667,10 @@ export class GitGraphView extends Disposable {
666667
<p class="unableToLoadMessage">${UNABLE_TO_FIND_GIT_MSG}</p>
667668
</body>`;
668669
} else if (numRepos > 0) {
670+
const stickyClassAttr = initialState.config.stickyHeader ? ' class="sticky"' : '';
669671
body = `<body>
670672
<div id="view" tabindex="-1">
671-
<div id="controls">
673+
<div id="controls"${stickyClassAttr}>
672674
<span id="repoControl"><span class="unselectable">Repo: </span><div id="repoDropdown" class="dropdown"></div></span>
673675
<span id="branchControl"><span class="unselectable">Branches: </span><div id="branchDropdown" class="dropdown"></div></span>
674676
<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
@@ -250,6 +250,7 @@ export interface GitGraphViewConfig {
250250
readonly showRemoteBranches: boolean;
251251
readonly showStashes: boolean;
252252
readonly showTags: boolean;
253+
readonly stickyHeader: boolean;
253254
}
254255

255256
export interface GitGraphViewGlobalState {

tests/config.test.ts

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

26762676
describe('showStatusBarItem', testBooleanExtensionSetting('showStatusBarItem', 'showStatusBarItem', true));
26772677

2678+
describe('stickyHeader', testBooleanExtensionSetting('stickyHeader', 'stickyHeader', true));
2679+
26782680
describe('tabIconColourTheme', () => {
26792681
it('Should return TabIconColourTheme.Colour when the configuration value is "colour"', () => {
26802682
// Setup

web/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,8 @@ class GitGraphView {
808808
markdown: this.config.markdown
809809
});
810810

811-
let html = '<tr id="tableColHeaders"><th id="tableHeaderGraphCol" class="tableColHeader" data-col="0">Graph</th><th class="tableColHeader" data-col="1">Description</th>' +
811+
const stickyClassAttr = this.config.stickyHeader ? ' class="sticky"' : '';
812+
let html = '<tr id="tableColHeaders"' + stickyClassAttr + '><th id="tableHeaderGraphCol" class="tableColHeader" data-col="0">Graph</th><th class="tableColHeader" data-col="1">Description</th>' +
812813
(colVisibility.date ? '<th class="tableColHeader dateCol" data-col="2">Date</th>' : '') +
813814
(colVisibility.author ? '<th class="tableColHeader authorCol" data-col="3">Author</th>' : '') +
814815
(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;
@@ -770,11 +777,12 @@ body.tagLabelsRightAligned .gitRef.tag{
770777

771778
#controls{
772779
display:block;
773-
position:relative;
780+
position: relative;
774781
left:0;
775782
right:0;
776783
top:0;
777784
padding:4px 132px 4px 0;
785+
background-color: var(--vscode-editor-background);
778786
border-bottom:1px solid rgba(128,128,128,0.5);
779787
line-height:32px;
780788
text-align:center;
@@ -784,6 +792,11 @@ body.tagLabelsRightAligned .gitRef.tag{
784792
user-select:none;
785793
}
786794

795+
#controls.sticky {
796+
position:sticky;
797+
z-index: 4;
798+
}
799+
787800
#repoControl, #branchControl, #showRemoteBranchesControl{
788801
display:inline-block;
789802
white-space:nowrap;

0 commit comments

Comments
 (0)