Skip to content

Commit 8beaa2b

Browse files
committed
mhutchie#132: align sticky table header dinamically to controls
1 parent d074ce6 commit 8beaa2b

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

web/main.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class GitGraphView {
4949
private readonly viewElem: HTMLElement;
5050
private readonly controlsElem: HTMLElement;
5151
private readonly tableElem: HTMLElement;
52+
private tableColHeadersElem: HTMLElement | null;
5253
private readonly footerElem: HTMLElement;
5354
private readonly showRemoteBranchesElem: HTMLInputElement;
5455
private readonly refreshBtnElem: HTMLElement;
@@ -72,6 +73,7 @@ class GitGraphView {
7273

7374
this.controlsElem = document.getElementById('controls')!;
7475
this.tableElem = document.getElementById('commitTable')!;
76+
this.tableColHeadersElem = document.getElementById('tableColHeaders')!;
7577
this.footerElem = document.getElementById('footer')!;
7678
this.scrollShadowElem = <HTMLInputElement>document.getElementById('scrollShadow')!;
7779

@@ -921,6 +923,11 @@ class GitGraphView {
921923
}
922924
}
923925
}
926+
927+
if (this.config.stickyHeader) {
928+
this.tableColHeadersElem = document.getElementById('tableColHeaders');
929+
this.alignTableHeaderToControls();
930+
}
924931
}
925932

926933
private renderUncommittedChanges() {
@@ -1882,6 +1889,22 @@ class GitGraphView {
18821889
this.requestLoadRepoInfoAndCommits(false, true);
18831890
}
18841891

1892+
private alignTableHeaderToControls() {
1893+
if (!this.tableColHeadersElem) {
1894+
return;
1895+
}
1896+
1897+
const controlsHeight = this.controlsElem.offsetHeight;
1898+
const controlsWidth = this.controlsElem.offsetWidth;
1899+
const tableColHeadersHeight = this.tableColHeadersElem.offsetHeight;
1900+
const bottomBorderWidth = 1;
1901+
const shadowYPos = controlsHeight + tableColHeadersHeight + bottomBorderWidth;
1902+
1903+
this.tableColHeadersElem.style.top = `${controlsHeight}px`;
1904+
this.scrollShadowElem.style.top = `${shadowYPos}px`;
1905+
this.scrollShadowElem.style.width = `${controlsWidth}px`;
1906+
}
1907+
18851908

18861909
/* Observers */
18871910

@@ -1894,6 +1917,10 @@ class GitGraphView {
18941917
windowWidth = window.outerWidth;
18951918
windowHeight = window.outerHeight;
18961919
}
1920+
1921+
if (this.config.stickyHeader) {
1922+
this.alignTableHeaderToControls();
1923+
}
18971924
});
18981925
}
18991926

web/styles/main.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ code{
7474
top:0;
7575
left:0;
7676
right:0;
77-
height:0;
78-
box-shadow:0 -6px 6px 6px var(--vscode-scrollbar-shadow);
77+
height:6px;
78+
box-shadow: inset 0 6px 6px -6px var(--vscode-scrollbar-shadow);
7979
z-index:20;
80+
pointer-events:none;
8081
}
8182

8283

@@ -280,7 +281,7 @@ code{
280281
}
281282
#tableColHeaders.sticky .tableColHeader {
282283
position: sticky;
283-
top: 41px;
284+
top: inherit;
284285
z-index: 3;
285286
background-color: var(--vscode-editor-background);
286287
}

0 commit comments

Comments
 (0)