Skip to content

Commit 31806ca

Browse files
committed
mhutchie#486 All Git Graph View Keyboard Shortcut extension settings can now alternatively be set to "UNASSIGNED", if you don't want to have a keybinding for a specific Keyboard Shortcut.
1 parent 5ca83ed commit 31806ca

File tree

5 files changed

+69
-14
lines changed

5 files changed

+69
-14
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@
730730
"git-graph.keyboardShortcut.find": {
731731
"type": "string",
732732
"enum": [
733+
"UNASSIGNED",
733734
"CTRL/CMD + A",
734735
"CTRL/CMD + B",
735736
"CTRL/CMD + C",
@@ -763,6 +764,7 @@
763764
"git-graph.keyboardShortcut.refresh": {
764765
"type": "string",
765766
"enum": [
767+
"UNASSIGNED",
766768
"CTRL/CMD + A",
767769
"CTRL/CMD + B",
768770
"CTRL/CMD + C",
@@ -796,6 +798,7 @@
796798
"git-graph.keyboardShortcut.scrollToHead": {
797799
"type": "string",
798800
"enum": [
801+
"UNASSIGNED",
799802
"CTRL/CMD + A",
800803
"CTRL/CMD + B",
801804
"CTRL/CMD + C",
@@ -829,6 +832,7 @@
829832
"git-graph.keyboardShortcut.scrollToStash": {
830833
"type": "string",
831834
"enum": [
835+
"UNASSIGNED",
832836
"CTRL/CMD + A",
833837
"CTRL/CMD + B",
834838
"CTRL/CMD + C",

src/config.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,14 @@ class Config {
578578
*/
579579
private getKeybinding(section: string, defaultValue: string) {
580580
const configValue = this.config.get<string>(section);
581-
if (typeof configValue === 'string' && Config.KEYBINDING_REGEXP.test(configValue)) {
582-
return configValue.substring(11).toLowerCase();
583-
} else {
584-
return defaultValue;
581+
if (typeof configValue === 'string') {
582+
if (configValue === 'UNASSIGNED') {
583+
return null;
584+
} else if (Config.KEYBINDING_REGEXP.test(configValue)) {
585+
return configValue.substring(11).toLowerCase();
586+
}
585587
}
588+
return defaultValue;
586589
}
587590

588591
/**

src/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,10 @@ export interface GraphConfig {
279279
}
280280

281281
export interface KeybindingConfig {
282-
readonly find: string;
283-
readonly refresh: string;
284-
readonly scrollToHead: string;
285-
readonly scrollToStash: string;
282+
readonly find: string | null;
283+
readonly refresh: string | null;
284+
readonly scrollToHead: string | null;
285+
readonly scrollToStash: string | null;
286286
}
287287

288288
export type LoadGitGraphViewTo = {

tests/config.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,18 @@ describe('Config', () => {
18251825
expect(value).toBe('a');
18261826
});
18271827

1828+
it('Should return the configured keybinding (unassigned)', () => {
1829+
// Setup
1830+
vscode.mockExtensionSettingReturnValue('keyboardShortcut.find', 'UNASSIGNED');
1831+
1832+
// Run
1833+
const value = config.keybindings.find;
1834+
1835+
// Assert
1836+
expect(workspaceConfiguration.get).toBeCalledWith('keyboardShortcut.find');
1837+
expect(value).toBeNull();
1838+
});
1839+
18281840
it('Should return the default keybinding when the value is not one of the available keybindings', () => {
18291841
// Setup
18301842
vscode.mockExtensionSettingReturnValue('keyboardShortcut.find', 'CTRL/CMD + Shift + A');
@@ -1872,6 +1884,18 @@ describe('Config', () => {
18721884
expect(value).toBe('a');
18731885
});
18741886

1887+
it('Should return the configured keybinding (unassigned)', () => {
1888+
// Setup
1889+
vscode.mockExtensionSettingReturnValue('keyboardShortcut.refresh', 'UNASSIGNED');
1890+
1891+
// Run
1892+
const value = config.keybindings.refresh;
1893+
1894+
// Assert
1895+
expect(workspaceConfiguration.get).toBeCalledWith('keyboardShortcut.refresh');
1896+
expect(value).toBeNull();
1897+
});
1898+
18751899
it('Should return the default keybinding when the value is not one of the available keybindings', () => {
18761900
// Setup
18771901
vscode.mockExtensionSettingReturnValue('keyboardShortcut.refresh', 'CTRL/CMD + Shift + A');
@@ -1919,6 +1943,18 @@ describe('Config', () => {
19191943
expect(value).toBe('a');
19201944
});
19211945

1946+
it('Should return the configured keybinding (unassigned)', () => {
1947+
// Setup
1948+
vscode.mockExtensionSettingReturnValue('keyboardShortcut.scrollToHead', 'UNASSIGNED');
1949+
1950+
// Run
1951+
const value = config.keybindings.scrollToHead;
1952+
1953+
// Assert
1954+
expect(workspaceConfiguration.get).toBeCalledWith('keyboardShortcut.scrollToHead');
1955+
expect(value).toBeNull();
1956+
});
1957+
19221958
it('Should return the default keybinding when the value is not one of the available keybindings', () => {
19231959
// Setup
19241960
vscode.mockExtensionSettingReturnValue('keyboardShortcut.scrollToHead', 'CTRL/CMD + Shift + A');
@@ -1966,6 +2002,18 @@ describe('Config', () => {
19662002
expect(value).toBe('a');
19672003
});
19682004

2005+
it('Should return the configured keybinding (unassigned)', () => {
2006+
// Setup
2007+
vscode.mockExtensionSettingReturnValue('keyboardShortcut.scrollToStash', 'UNASSIGNED');
2008+
2009+
// Run
2010+
const value = config.keybindings.scrollToStash;
2011+
2012+
// Assert
2013+
expect(workspaceConfiguration.get).toBeCalledWith('keyboardShortcut.scrollToStash');
2014+
expect(value).toBeNull();
2015+
});
2016+
19692017
it('Should return the default keybinding when the value is not one of the available keybindings', () => {
19702018
// Setup
19712019
vscode.mockExtensionSettingReturnValue('keyboardShortcut.scrollToStash', 'CTRL/CMD + Shift + A');

web/main.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,19 +2008,19 @@ class GitGraphView {
20082008
const elem = findCommitElemWithId(getCommitElems(), newHashIndex);
20092009
if (elem !== null) this.loadCommitDetails(elem);
20102010
}
2011-
} else if (e.ctrlKey || e.metaKey) {
2012-
const key = e.key.toLowerCase();
2013-
if (key === this.config.keybindings.scrollToStash) {
2011+
} else if (e.key && (e.ctrlKey || e.metaKey)) {
2012+
const key = e.key.toLowerCase(), keybindings = this.config.keybindings;
2013+
if (key === keybindings.scrollToStash) {
20142014
this.scrollToStash(!e.shiftKey);
20152015
handledEvent(e);
20162016
} else if (!e.shiftKey) {
2017-
if (key === this.config.keybindings.refresh) {
2017+
if (key === keybindings.refresh) {
20182018
this.refresh(true, true);
20192019
handledEvent(e);
2020-
} else if (key === this.config.keybindings.find) {
2020+
} else if (key === keybindings.find) {
20212021
this.findWidget.show(true);
20222022
handledEvent(e);
2023-
} else if (key === this.config.keybindings.scrollToHead && this.commitHead !== null) {
2023+
} else if (key === keybindings.scrollToHead && this.commitHead !== null) {
20242024
this.scrollToCommit(this.commitHead, true, true);
20252025
handledEvent(e);
20262026
}

0 commit comments

Comments
 (0)