From 362f65d13b969ec1d2a92b45b174c1c5ef85e98b Mon Sep 17 00:00:00 2001
From: bendera
Date: Mon, 12 Oct 2020 22:33:33 +0200
Subject: [PATCH] #132 Add sticky header option
---
package.json | 5 ++++
src/config.ts | 7 +++++
src/gitGraphView.ts | 4 ++-
src/types.ts | 1 +
tests/config.test.ts | 62 ++++++++++++++++++++++++++++++++++++++++++++
web/main.ts | 3 ++-
web/styles/main.css | 17 ++++++++++--
7 files changed, 95 insertions(+), 4 deletions(-)
diff --git a/package.json b/package.json
index 241517b7..14935b9d 100644
--- a/package.json
+++ b/package.json
@@ -460,6 +460,11 @@
},
"description": "An object specifying the default visibility of the Date, Author & Commit columns. Example: {\"Date\": true, \"Author\": true, \"Commit\": true}"
},
+ "git-graph.stickyHeader": {
+ "type": "boolean",
+ "default": true,
+ "description": "Keeps the header visible when the view is scrolled"
+ },
"git-graph.dialog.addTag.pushToRemote": {
"type": "boolean",
"default": false,
diff --git a/src/config.ts b/src/config.ts
index f297c00f..f9650db8 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -489,6 +489,13 @@ class Config {
return !!this.config.get('showStatusBarItem', true);
}
+ /**
+ * Get the value of the `git-graph.stickyHeader` Extension Setting.
+ */
+ get stickyHeader() {
+ return !!this.config.get('stickyHeader', true);
+ }
+
/**
* Get the value of the `git-graph.tabIconColourTheme` Extension Setting.
*/
diff --git a/src/gitGraphView.ts b/src/gitGraphView.ts
index 87cb0c48..a958ee03 100644
--- a/src/gitGraphView.ts
+++ b/src/gitGraphView.ts
@@ -589,6 +589,7 @@ export class GitGraphView extends Disposable {
customPullRequestProviders: config.customPullRequestProviders,
dateFormat: config.dateFormat,
defaultColumnVisibility: config.defaultColumnVisibility,
+ stickyHeader: config.stickyHeader,
dialogDefaults: config.dialogDefaults,
enhancedAccessibility: config.enhancedAccessibility,
fetchAndPrune: config.fetchAndPrune,
@@ -628,9 +629,10 @@ export class GitGraphView extends Disposable {
${UNABLE_TO_FIND_GIT_MSG}
-
+
Repo:
Branches:
diff --git a/src/types.ts b/src/types.ts
index 10d112e0..2d7aa499 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -235,6 +235,7 @@ export interface GitGraphViewConfig {
readonly repoDropdownOrder: RepoDropdownOrder;
readonly showRemoteBranches: boolean;
readonly showTags: boolean;
+ readonly stickyHeader: boolean;
}
export interface GitGraphViewGlobalState {
diff --git a/tests/config.test.ts b/tests/config.test.ts
index 11d72c4f..b45df51c 100644
--- a/tests/config.test.ts
+++ b/tests/config.test.ts
@@ -3878,4 +3878,66 @@ describe('Config', () => {
expect(value).toBe(false);
});
});
+
+ describe('stickyHeader', () => {
+ it('Should return TRUE when the configuration value is TRUE', () => {
+ // Setup
+ workspaceConfiguration.get.mockReturnValueOnce(true);
+
+ // Run
+ const value = config.stickyHeader;
+
+ // Assert
+ expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
+ expect(value).toBe(true);
+ });
+
+ it('Should return FALSE when the configuration value is FALSE', () => {
+ // Setup
+ workspaceConfiguration.get.mockReturnValueOnce(false);
+
+ // Run
+ const value = config.stickyHeader;
+
+ // Assert
+ expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
+ expect(value).toBe(false);
+ });
+
+ it('Should return TRUE when the configuration value is truthy', () => {
+ // Setup
+ workspaceConfiguration.get.mockReturnValueOnce(5);
+
+ // Run
+ const value = config.stickyHeader;
+
+ // Assert
+ expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
+ expect(value).toBe(true);
+ });
+
+ it('Should return FALSE when the configuration value is falsy', () => {
+ // Setup
+ workspaceConfiguration.get.mockReturnValueOnce(0);
+
+ // Run
+ const value = config.stickyHeader;
+
+ // Assert
+ expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
+ expect(value).toBe(false);
+ });
+
+ it('Should return the default value (TRUE) when the configuration value is not set', () => {
+ // Setup
+ workspaceConfiguration.get.mockImplementationOnce((_, defaultValue) => defaultValue);
+
+ // Run
+ const value = config.stickyHeader;
+
+ // Assert
+ expect(workspaceConfiguration.get).toBeCalledWith('stickyHeader', true);
+ expect(value).toBe(true);
+ });
+ });
});
diff --git a/web/main.ts b/web/main.ts
index 326d6487..0c4c5d43 100644
--- a/web/main.ts
+++ b/web/main.ts
@@ -734,7 +734,8 @@ class GitGraphView {
markdown: this.config.markdown
});
- let html = '