Skip to content

Commit

Permalink
#132: align sticky table header dinamically to controls
Browse files Browse the repository at this point in the history
  • Loading branch information
bendera committed Dec 18, 2020
1 parent 0095197 commit 11d67b1
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 @@ -48,6 +48,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 @@ -71,6 +72,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 @@ -911,6 +913,11 @@ class GitGraphView {
}
}
}

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

private renderUncommittedChanges() {
Expand Down Expand Up @@ -1820,6 +1827,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 @@ -1832,6 +1855,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 11d67b1

Please sign in to comment.