Skip to content

Commit

Permalink
mhutchie#132: align sticky table header dinamically to controls
Browse files Browse the repository at this point in the history
  • Loading branch information
bendera committed Nov 7, 2020
1 parent c4ff2db commit 94c4986
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
27 changes: 27 additions & 0 deletions web/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class GitGraphView {
private readonly viewElem: HTMLElement;
private readonly controlsElem: HTMLElement;
private readonly tableElem: HTMLElement;
private tableColHeadersElem: HTMLElement | null;
private readonly footerElem: HTMLElement;
private readonly showRemoteBranchesElem: HTMLInputElement;
private readonly refreshBtnElem: HTMLElement;
Expand All @@ -66,6 +67,7 @@ class GitGraphView {

this.controlsElem = document.getElementById('controls')!;
this.tableElem = document.getElementById('commitTable')!;
this.tableColHeadersElem = document.getElementById('tableColHeaders')!;
this.footerElem = document.getElementById('footer')!;
this.scrollShadowElem = <HTMLInputElement>document.getElementById('scrollShadow')!;

Expand Down Expand Up @@ -839,6 +841,11 @@ class GitGraphView {
}
}
}

if (this.config.stickyHeader) {
this.tableColHeadersElem = document.getElementById('tableColHeaders');
this.alignTableHeaderToControls();
}
}

private renderUncommittedChanges() {
Expand Down Expand Up @@ -1746,6 +1753,22 @@ class GitGraphView {
this.requestLoadRepoInfoAndCommits(false, true);
}

private alignTableHeaderToControls() {
if (!this.tableColHeadersElem) {
return;
}

const controlsHeight = this.controlsElem.offsetHeight;
const controlsWidth = this.controlsElem.offsetWidth;
const tableColHeadersHeight = this.tableColHeadersElem.offsetHeight;
const bottomBorderWidth = 1;
const shadowYPos = controlsHeight + tableColHeadersHeight + bottomBorderWidth;

this.tableColHeadersElem.style.top = `${controlsHeight}px`;
this.scrollShadowElem.style.top = `${shadowYPos}px`;
this.scrollShadowElem.style.width = `${controlsWidth}px`;
}


/* Observers */

Expand All @@ -1758,6 +1781,10 @@ class GitGraphView {
windowWidth = window.outerWidth;
windowHeight = window.outerHeight;
}

if (this.config.stickyHeader) {
this.alignTableHeaderToControls();
}
});
}

Expand Down
7 changes: 4 additions & 3 deletions web/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ body.selection-background-color-exists ::selection{
top:0;
left:0;
right:0;
height:0;
box-shadow:0 -6px 6px 6px var(--vscode-scrollbar-shadow);
height:6px;
box-shadow: inset 0 6px 6px -6px var(--vscode-scrollbar-shadow);
z-index:20;
pointer-events:none;
}

.blockUserInteraction{
Expand Down Expand Up @@ -281,7 +282,7 @@ body.selection-background-color-exists ::selection{
}
#tableColHeaders.sticky .tableColHeader {
position: sticky;
top: 41px;
top: inherit;
z-index: 3;
background-color: var(--vscode-editor-background);
}
Expand Down

0 comments on commit 94c4986

Please sign in to comment.