Skip to content

Commit

Permalink
#486 All Git Graph View Keyboard Shortcut extension settings can now …
Browse files Browse the repository at this point in the history
…alternatively be set to "UNASSIGNED", if you don't want to have a keybinding for a specific Keyboard Shortcut.
  • Loading branch information
mhutchie committed Mar 17, 2021
1 parent 5ca83ed commit 31806ca
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 14 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@
"git-graph.keyboardShortcut.find": {
"type": "string",
"enum": [
"UNASSIGNED",
"CTRL/CMD + A",
"CTRL/CMD + B",
"CTRL/CMD + C",
Expand Down Expand Up @@ -763,6 +764,7 @@
"git-graph.keyboardShortcut.refresh": {
"type": "string",
"enum": [
"UNASSIGNED",
"CTRL/CMD + A",
"CTRL/CMD + B",
"CTRL/CMD + C",
Expand Down Expand Up @@ -796,6 +798,7 @@
"git-graph.keyboardShortcut.scrollToHead": {
"type": "string",
"enum": [
"UNASSIGNED",
"CTRL/CMD + A",
"CTRL/CMD + B",
"CTRL/CMD + C",
Expand Down Expand Up @@ -829,6 +832,7 @@
"git-graph.keyboardShortcut.scrollToStash": {
"type": "string",
"enum": [
"UNASSIGNED",
"CTRL/CMD + A",
"CTRL/CMD + B",
"CTRL/CMD + C",
Expand Down
11 changes: 7 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,14 @@ class Config {
*/
private getKeybinding(section: string, defaultValue: string) {
const configValue = this.config.get<string>(section);
if (typeof configValue === 'string' && Config.KEYBINDING_REGEXP.test(configValue)) {
return configValue.substring(11).toLowerCase();
} else {
return defaultValue;
if (typeof configValue === 'string') {
if (configValue === 'UNASSIGNED') {
return null;
} else if (Config.KEYBINDING_REGEXP.test(configValue)) {
return configValue.substring(11).toLowerCase();
}
}
return defaultValue;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ export interface GraphConfig {
}

export interface KeybindingConfig {
readonly find: string;
readonly refresh: string;
readonly scrollToHead: string;
readonly scrollToStash: string;
readonly find: string | null;
readonly refresh: string | null;
readonly scrollToHead: string | null;
readonly scrollToStash: string | null;
}

export type LoadGitGraphViewTo = {
Expand Down
48 changes: 48 additions & 0 deletions tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,18 @@ describe('Config', () => {
expect(value).toBe('a');
});

it('Should return the configured keybinding (unassigned)', () => {
// Setup
vscode.mockExtensionSettingReturnValue('keyboardShortcut.find', 'UNASSIGNED');

// Run
const value = config.keybindings.find;

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('keyboardShortcut.find');
expect(value).toBeNull();
});

it('Should return the default keybinding when the value is not one of the available keybindings', () => {
// Setup
vscode.mockExtensionSettingReturnValue('keyboardShortcut.find', 'CTRL/CMD + Shift + A');
Expand Down Expand Up @@ -1872,6 +1884,18 @@ describe('Config', () => {
expect(value).toBe('a');
});

it('Should return the configured keybinding (unassigned)', () => {
// Setup
vscode.mockExtensionSettingReturnValue('keyboardShortcut.refresh', 'UNASSIGNED');

// Run
const value = config.keybindings.refresh;

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('keyboardShortcut.refresh');
expect(value).toBeNull();
});

it('Should return the default keybinding when the value is not one of the available keybindings', () => {
// Setup
vscode.mockExtensionSettingReturnValue('keyboardShortcut.refresh', 'CTRL/CMD + Shift + A');
Expand Down Expand Up @@ -1919,6 +1943,18 @@ describe('Config', () => {
expect(value).toBe('a');
});

it('Should return the configured keybinding (unassigned)', () => {
// Setup
vscode.mockExtensionSettingReturnValue('keyboardShortcut.scrollToHead', 'UNASSIGNED');

// Run
const value = config.keybindings.scrollToHead;

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('keyboardShortcut.scrollToHead');
expect(value).toBeNull();
});

it('Should return the default keybinding when the value is not one of the available keybindings', () => {
// Setup
vscode.mockExtensionSettingReturnValue('keyboardShortcut.scrollToHead', 'CTRL/CMD + Shift + A');
Expand Down Expand Up @@ -1966,6 +2002,18 @@ describe('Config', () => {
expect(value).toBe('a');
});

it('Should return the configured keybinding (unassigned)', () => {
// Setup
vscode.mockExtensionSettingReturnValue('keyboardShortcut.scrollToStash', 'UNASSIGNED');

// Run
const value = config.keybindings.scrollToStash;

// Assert
expect(workspaceConfiguration.get).toBeCalledWith('keyboardShortcut.scrollToStash');
expect(value).toBeNull();
});

it('Should return the default keybinding when the value is not one of the available keybindings', () => {
// Setup
vscode.mockExtensionSettingReturnValue('keyboardShortcut.scrollToStash', 'CTRL/CMD + Shift + A');
Expand Down
12 changes: 6 additions & 6 deletions web/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2008,19 +2008,19 @@ class GitGraphView {
const elem = findCommitElemWithId(getCommitElems(), newHashIndex);
if (elem !== null) this.loadCommitDetails(elem);
}
} else if (e.ctrlKey || e.metaKey) {
const key = e.key.toLowerCase();
if (key === this.config.keybindings.scrollToStash) {
} else if (e.key && (e.ctrlKey || e.metaKey)) {
const key = e.key.toLowerCase(), keybindings = this.config.keybindings;
if (key === keybindings.scrollToStash) {
this.scrollToStash(!e.shiftKey);
handledEvent(e);
} else if (!e.shiftKey) {
if (key === this.config.keybindings.refresh) {
if (key === keybindings.refresh) {
this.refresh(true, true);
handledEvent(e);
} else if (key === this.config.keybindings.find) {
} else if (key === keybindings.find) {
this.findWidget.show(true);
handledEvent(e);
} else if (key === this.config.keybindings.scrollToHead && this.commitHead !== null) {
} else if (key === keybindings.scrollToHead && this.commitHead !== null) {
this.scrollToCommit(this.commitHead, true, true);
handledEvent(e);
}
Expand Down

0 comments on commit 31806ca

Please sign in to comment.