Skip to content

Commit

Permalink
Closes #2345 allows shortcuts on Graph "commits"
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Nov 15, 2022
1 parent f7b010b commit b0cb1e4
Show file tree
Hide file tree
Showing 16 changed files with 342 additions and 258 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

### Added

- Adds the ability to set keyboard shortcuts to commits and stashes on the _Commit Graph_ — closes [#2345](https://github.com/gitkraken/vscode-gitlens/issues/2345)
- Keyboard shortcuts can be applied to many of the `gitlens.graph.*` commands and should use `gitlens:webview:graph:focus && !gitlens:webview:graph:inputFocus` for their "When Expression" to only apply when the _Commit Graph_ is focused
- For example, add the following to your `keybindings.json` to allow <kbd>Ctrl</kbd>+<kbd>C</kbd> to copy the selected commit's SHA to the clipboard
```json
{
"key": "ctrl+c",
"command": "gitlens.graph.copySha",
"when": "gitlens:webview:graph:focus && !gitlens:webview:graph:inputFocus"
}
```
- Adds a Terminal Links section to the GitLens Interactive Settings
- Adds ability to reset to any commit in the _Commit Graph_ and GitLens views &mdash; closes [#2326](https://github.com/gitkraken/vscode-gitlens/issues/2326)
- Adds history navigation to the search box in the _Commit Graph_
Expand Down
14 changes: 7 additions & 7 deletions package.json
Expand Up @@ -8881,37 +8881,37 @@
},
{
"command": "gitlens.refreshTimelinePage",
"when": "gitlens:timelinePage:focused",
"when": "gitlens:webview:timeline:active",
"group": "navigation@-99"
},
{
"command": "gitlens.graph.push",
"when": "gitlens:graph:focused && gitlens:hasRemotes && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"when": "gitlens:webview:graph:active && gitlens:hasRemotes && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"group": "navigation@-103"
},
{
"command": "gitlens.graph.pull",
"when": "gitlens:graph:focused && gitlens:hasRemotes && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"when": "gitlens:webview:graph:active && gitlens:hasRemotes && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"group": "navigation@-102"
},
{
"command": "gitlens.graph.fetch",
"when": "gitlens:graph:focused && gitlens:hasRemotes && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"when": "gitlens:webview:graph:active && gitlens:hasRemotes && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"group": "navigation@-101"
},
{
"command": "gitlens.graph.switchToAnotherBranch",
"when": "gitlens:graph:focused && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"when": "gitlens:webview:graph:active && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"group": "navigation@-100"
},
{
"command": "gitlens.graph.refresh",
"when": "gitlens:graph:focused",
"when": "gitlens:webview:graph:active",
"group": "navigation@-99"
},
{
"command": "gitlens.showSettingsPage#commit-graph",
"when": "gitlens:graph:focused",
"when": "gitlens:webview:graph:active",
"group": "navigation@-98"
}
],
Expand Down
4 changes: 2 additions & 2 deletions src/constants.ts
Expand Up @@ -243,20 +243,20 @@ export const enum Commands {
export const enum ContextKeys {
ActionPrefix = 'gitlens:action:',
KeyPrefix = 'gitlens:key:',
WebviewPrefix = `gitlens:webview:`,
WebviewViewPrefix = `gitlens:webviewView:`,

ActiveFileStatus = 'gitlens:activeFileStatus',
AnnotationStatus = 'gitlens:annotationStatus',
Debugging = 'gitlens:debugging',
DisabledToggleCodeLens = 'gitlens:disabledToggleCodeLens',
Disabled = 'gitlens:disabled',
Enabled = 'gitlens:enabled',
GraphFocused = 'gitlens:graph:focused',
HasConnectedRemotes = 'gitlens:hasConnectedRemotes',
HasRemotes = 'gitlens:hasRemotes',
HasRichRemotes = 'gitlens:hasRichRemotes',
HasVirtualFolders = 'gitlens:hasVirtualFolders',
Readonly = 'gitlens:readonly',
TimelinePageFocused = 'gitlens:timelinePage:focused',
Untrusted = 'gitlens:untrusted',
ViewsCanCompare = 'gitlens:views:canCompare',
ViewsCanCompareFile = 'gitlens:views:canCompare:file',
Expand Down
25 changes: 18 additions & 7 deletions src/context.ts
Expand Up @@ -4,9 +4,23 @@ import { CoreCommands } from './constants';

const contextStorage = new Map<string, unknown>();

const _onDidChangeContext = new EventEmitter<
ContextKeys | `${ContextKeys.ActionPrefix}${string}` | `${ContextKeys.KeyPrefix}${string}`
>();
type WebviewContextKeys =
| `${ContextKeys.WebviewPrefix}${string}:active`
| `${ContextKeys.WebviewPrefix}${string}:focus`
| `${ContextKeys.WebviewPrefix}${string}:inputFocus`;

type WebviewViewContextKeys =
| `${ContextKeys.WebviewViewPrefix}${string}:focus`
| `${ContextKeys.WebviewViewPrefix}${string}:inputFocus`;

type AllContextKeys =
| ContextKeys
| WebviewContextKeys
| WebviewViewContextKeys
| `${ContextKeys.ActionPrefix}${string}`
| `${ContextKeys.KeyPrefix}${string}`;

const _onDidChangeContext = new EventEmitter<AllContextKeys>();
export const onDidChangeContext = _onDidChangeContext.event;

export function getContext<T>(key: ContextKeys): T | undefined;
Expand All @@ -15,10 +29,7 @@ export function getContext<T>(key: ContextKeys, defaultValue?: T): T | undefined
return (contextStorage.get(key) as T | undefined) ?? defaultValue;
}

export async function setContext(
key: ContextKeys | `${ContextKeys.ActionPrefix}${string}` | `${ContextKeys.KeyPrefix}${string}`,
value: unknown,
): Promise<void> {
export async function setContext(key: AllContextKeys, value: unknown): Promise<void> {
contextStorage.set(key, value);
void (await commands.executeCommand(CoreCommands.SetContext, key, value));
_onDidChangeContext.fire(key);
Expand Down

0 comments on commit b0cb1e4

Please sign in to comment.