diff --git a/package.json b/package.json index 233faed8..de0cc39d 100644 --- a/package.json +++ b/package.json @@ -730,6 +730,7 @@ "git-graph.keyboardShortcut.find": { "type": "string", "enum": [ + "UNASSIGNED", "CTRL/CMD + A", "CTRL/CMD + B", "CTRL/CMD + C", @@ -763,6 +764,7 @@ "git-graph.keyboardShortcut.refresh": { "type": "string", "enum": [ + "UNASSIGNED", "CTRL/CMD + A", "CTRL/CMD + B", "CTRL/CMD + C", @@ -796,6 +798,7 @@ "git-graph.keyboardShortcut.scrollToHead": { "type": "string", "enum": [ + "UNASSIGNED", "CTRL/CMD + A", "CTRL/CMD + B", "CTRL/CMD + C", @@ -829,6 +832,7 @@ "git-graph.keyboardShortcut.scrollToStash": { "type": "string", "enum": [ + "UNASSIGNED", "CTRL/CMD + A", "CTRL/CMD + B", "CTRL/CMD + C", diff --git a/src/config.ts b/src/config.ts index ed482331..d5dc870b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -578,11 +578,14 @@ class Config { */ private getKeybinding(section: string, defaultValue: string) { const configValue = this.config.get(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; } /** diff --git a/src/types.ts b/src/types.ts index 2b8a0032..80176974 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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 = { diff --git a/tests/config.test.ts b/tests/config.test.ts index 0586cc5e..18cb70cd 100644 --- a/tests/config.test.ts +++ b/tests/config.test.ts @@ -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'); @@ -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'); @@ -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'); @@ -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'); diff --git a/web/main.ts b/web/main.ts index 1ef4b5c0..95fcaf9c 100644 --- a/web/main.ts +++ b/web/main.ts @@ -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); }