Skip to content

Commit 26a30c4

Browse files
committed
Adds notification for conflicting shortcuts
1 parent 2494741 commit 26a30c4

File tree

6 files changed

+76
-27
lines changed

6 files changed

+76
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
88
### Added
99
- Adds rich tooltip details to most nodes in the **GitLens** explorer and **GitLens Results** view
1010
- Adds an indicator to the *GitLens* explorer branch history to mark the synchronization point between the local and remote branch (if available)
11+
- Adds a one-time notification on startup if the `alternate` set of keyboard shortcuts is in use, with options to easily switch to another set
1112
- Adds `${agoOrDate}` and `${authorAgoOrDate}` tokens to `gitlens.blame.format`, `gitlens.currentLine.format`, `gitlens.explorers.commitFormat`, `gitlens.explorers.stashFormat`, and `gitlens.statusBar.format` settings which will honor the `gitlens.defaultDateStyle` setting — closes [#312](https://github.com/eamodio/vscode-gitlens/issues/312)
1213
- Adds `gitlens.currentLine.scrollable` setting to specify whether the current line blame annotation can be scrolled into view when it is outside the viewport — closes [#149](https://github.com/eamodio/vscode-gitlens/issues/149), [#290](https://github.com/eamodio/vscode-gitlens/issues/290), [#265](https://github.com/eamodio/vscode-gitlens/issues/265)
1314
- Adds *Copy Commit ID to Clipboard* (`gitlens.copyShaToClipboard`) command to changed file nodes in the **GitLens** explorer and **GitLens Results** view

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,8 @@
10011001
"suppressGitVersionWarning": false,
10021002
"suppressLineUncommittedWarning": false,
10031003
"suppressNoRepositoryWarning": false,
1004-
"suppressResultsExplorerNotice": false
1004+
"suppressResultsExplorerNotice": false,
1005+
"suppressShowKeyBindingsNotice": false
10051006
},
10061007
"properties": {
10071008
"suppressCommitHasNoPreviousCommitWarning": {
@@ -1031,6 +1032,10 @@
10311032
"suppressResultsExplorerNotice": {
10321033
"type": "boolean",
10331034
"default": false
1035+
},
1036+
"suppressShowKeyBindingsNotice": {
1037+
"type": "boolean",
1038+
"default": false
10341039
}
10351040
},
10361041
"description": "Specifies which messages should be suppressed",

src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export async function activate(context: ExtensionContext) {
6161

6262
notifyOnUnsupportedGitVersion(gitVersion);
6363
showWelcomePage(gitlensVersion, previousVersion);
64+
Messages.showKeyBindingsInfoMessage();
6465

6566
context.globalState.update(GlobalState.GitLensVersion, gitlensVersion);
6667

@@ -138,7 +139,7 @@ async function migrateSettings(context: ExtensionContext, previousVersion: strin
138139
if (Versions.compare(previous, Versions.from(8, 0, 0, 'beta2')) !== 1) {
139140
await configuration.migrate<boolean, OutputLevel>(
140141
'debug', configuration.name('outputLevel').value,
141-
{ migrationFn: v => v ? OutputLevel.Debug : configuration.get(configuration.name('outputLevel').value) });
142+
{ migrationFn: v => v ? OutputLevel.Debug : configuration.get<OutputLevel>(configuration.name('outputLevel').value) });
142143
await configuration.migrate('debug', configuration.name('debug').value, { migrationFn: v => undefined });
143144
}
144145

src/messages.ts

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
2-
import { ConfigurationTarget, window } from 'vscode';
2+
import { ConfigurationTarget, MessageItem, window } from 'vscode';
3+
import { configuration, KeyMap } from './configuration';
4+
import { Container } from './container';
35
import { GitCommit } from './gitService';
46
import { Logger } from './logger';
5-
import { configuration } from './configuration';
67

78
export enum SuppressedMessages {
89
CommitHasNoPreviousCommitWarning = 'suppressCommitHasNoPreviousCommitWarning',
@@ -11,41 +12,81 @@ export enum SuppressedMessages {
1112
GitVersionWarning = 'suppressGitVersionWarning',
1213
LineUncommittedWarning = 'suppressLineUncommittedWarning',
1314
NoRepositoryWarning = 'suppressNoRepositoryWarning',
14-
ResultsExplorerNotice = 'suppressResultsExplorerNotice'
15+
ResultsExplorerNotice = 'suppressResultsExplorerNotice',
16+
ShowKeyBindingsNotice = 'suppressShowKeyBindingsNotice'
1517
}
1618

1719
export class Messages {
1820

19-
static showCommitHasNoPreviousCommitWarningMessage(commit?: GitCommit): Promise<string | undefined> {
20-
if (commit === undefined) return Messages.showMessage('info', `Commit has no previous commit`, SuppressedMessages.CommitHasNoPreviousCommitWarning);
21-
return Messages.showMessage('info', `Commit ${commit.shortSha} (${commit.author}, ${commit.formattedDate}) has no previous commit`, SuppressedMessages.CommitHasNoPreviousCommitWarning);
21+
static showCommitHasNoPreviousCommitWarningMessage(commit?: GitCommit): Promise<MessageItem | undefined> {
22+
if (commit === undefined) return Messages.showMessage('info', `Commit has no previous commit.`, SuppressedMessages.CommitHasNoPreviousCommitWarning);
23+
return Messages.showMessage('info', `Commit ${commit.shortSha} (${commit.author}, ${commit.formattedDate}) has no previous commit.`, SuppressedMessages.CommitHasNoPreviousCommitWarning);
2224
}
2325

24-
static showCommitNotFoundWarningMessage(message: string): Promise<string | undefined> {
25-
return Messages.showMessage('warn', `${message}. The commit could not be found`, SuppressedMessages.CommitNotFoundWarning);
26+
static showCommitNotFoundWarningMessage(message: string): Promise<MessageItem | undefined> {
27+
return Messages.showMessage('warn', `${message}. The commit could not be found.`, SuppressedMessages.CommitNotFoundWarning);
2628
}
2729

28-
static showFileNotUnderSourceControlWarningMessage(message: string): Promise<string | undefined> {
29-
return Messages.showMessage('warn', `${message}. The file is probably not under source control`, SuppressedMessages.FileNotUnderSourceControlWarning);
30+
static showFileNotUnderSourceControlWarningMessage(message: string): Promise<MessageItem | undefined> {
31+
return Messages.showMessage('warn', `${message}. The file is probably not under source control.`, SuppressedMessages.FileNotUnderSourceControlWarning);
3032
}
3133

32-
static showLineUncommittedWarningMessage(message: string): Promise<string | undefined> {
33-
return Messages.showMessage('warn', `${message}. The line has uncommitted changes`, SuppressedMessages.LineUncommittedWarning);
34+
static async showKeyBindingsInfoMessage(): Promise<MessageItem | undefined> {
35+
const section = configuration.name('advanced')('messages').value;
36+
const messages: { [key: string]: boolean } = configuration.get<{}>(section);
37+
38+
if (messages[SuppressedMessages.ShowKeyBindingsNotice]) return undefined;
39+
40+
if (Container.config.keymap !== KeyMap.Alternate) {
41+
messages[SuppressedMessages.ShowKeyBindingsNotice] = true;
42+
await configuration.update(section, messages, ConfigurationTarget.Global);
43+
44+
return undefined;
45+
}
46+
47+
const actions: MessageItem[] = [
48+
{ title: 'Keep Shortcuts', isCloseAffordance: true },
49+
{ title: 'Switch Shortcuts' },
50+
{ title: 'No Shortcuts' }
51+
];
52+
const result = await Messages.showMessage(
53+
'info',
54+
`GitLens is using keyboard shortcuts which can conflict with menu mnemonics and different keyboard layouts. To avoid such conflicts, it is recommended to switch to the new default keyboard shortcuts.`,
55+
SuppressedMessages.ShowKeyBindingsNotice,
56+
null,
57+
...actions
58+
);
59+
60+
switch (result) {
61+
case actions[1]:
62+
await configuration.update(configuration.name('keymap').value, KeyMap.Chorded, ConfigurationTarget.Global);
63+
break;
64+
65+
case actions[2]:
66+
await configuration.update(configuration.name('keymap').value, KeyMap.None, ConfigurationTarget.Global);
67+
break;
68+
}
69+
70+
return result;
71+
}
72+
73+
static showLineUncommittedWarningMessage(message: string): Promise<MessageItem | undefined> {
74+
return Messages.showMessage('warn', `${message}. The line has uncommitted changes.`, SuppressedMessages.LineUncommittedWarning);
3475
}
3576

36-
static showNoRepositoryWarningMessage(message: string): Promise<string | undefined> {
37-
return Messages.showMessage('warn', `${message}. No repository could be found`, SuppressedMessages.NoRepositoryWarning);
77+
static showNoRepositoryWarningMessage(message: string): Promise<MessageItem | undefined> {
78+
return Messages.showMessage('warn', `${message}. No repository could be found.`, SuppressedMessages.NoRepositoryWarning);
3879
}
3980

40-
static showResultExplorerInfoMessage(): Promise<string | undefined> {
41-
return Messages.showMessage('info', `If you can't find your results, click on "GITLENS RESULTS" at the bottom of the Explorer view`, SuppressedMessages.ResultsExplorerNotice, null);
81+
static showResultExplorerInfoMessage(): Promise<MessageItem | undefined> {
82+
return Messages.showMessage('info', `If you can't find your results, click on "GITLENS RESULTS" at the bottom of the Explorer view.`, SuppressedMessages.ResultsExplorerNotice, null);
4283
}
4384

44-
static showUnsupportedGitVersionErrorMessage(version: string): Promise<string | undefined> {
45-
return Messages.showMessage('error', `GitLens requires a newer version of Git (>= 2.2.0) than is currently installed (${version}). Please install a more recent version of Git`, SuppressedMessages.GitVersionWarning);
85+
static showUnsupportedGitVersionErrorMessage(version: string): Promise<MessageItem | undefined> {
86+
return Messages.showMessage('error', `GitLens requires a newer version of Git (>= 2.2.0) than is currently installed (${version}). Please install a more recent version of Git.`, SuppressedMessages.GitVersionWarning);
4687
}
4788

48-
private static async showMessage(type: 'info' | 'warn' | 'error', message: string, suppressionKey: SuppressedMessages, dontShowAgain: string | null = 'Don\'t Show Again', ...actions: any[]): Promise<string | undefined> {
89+
private static async showMessage<T extends MessageItem>(type: 'info' | 'warn' | 'error', message: string, suppressionKey: SuppressedMessages, dontShowAgain: T | null = { title: 'Don\'t Show Again' } as T, ...actions: T[]): Promise<T | undefined> {
4990
Logger.log(`ShowMessage(${type}, '${message}', ${suppressionKey}, ${dontShowAgain})`);
5091

5192
if (configuration.get<boolean>(configuration.name('advanced')('messages')(suppressionKey).value)) {
@@ -57,7 +98,7 @@ export class Messages {
5798
actions.push(dontShowAgain);
5899
}
59100

60-
let result: string | undefined = undefined;
101+
let result: T | undefined = undefined;
61102
switch (type) {
62103
case 'info':
63104
result = await window.showInformationMessage(message, ...actions);
@@ -76,14 +117,14 @@ export class Messages {
76117
Logger.log(`ShowMessage(${type}, '${message}', ${suppressionKey}, ${dontShowAgain}) don't show again requested`);
77118

78119
const section = configuration.name('advanced')('messages').value;
79-
const messages: { [key: string]: boolean } = configuration.get(section);
120+
const messages: { [key: string]: boolean } = configuration.get<{}>(section);
80121
messages[suppressionKey] = true;
81122
await configuration.update(section, messages, ConfigurationTarget.Global);
82123

83124
if (result === dontShowAgain) return undefined;
84125
}
85126

86-
Logger.log(`ShowMessage(${type}, '${message}', ${suppressionKey}, ${dontShowAgain}) returned ${result}`);
127+
Logger.log(`ShowMessage(${type}, '${message}', ${suppressionKey}, ${dontShowAgain}) returned ${result ? result.title : result}`);
87128
return result;
88129
}
89130
}

src/ui/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export interface IAdvancedConfig {
152152
suppressLineUncommittedWarning: boolean;
153153
suppressNoRepositoryWarning: boolean;
154154
suppressResultsExplorerNotice: boolean;
155+
suppressShowKeyBindingsNotice: boolean;
155156
};
156157

157158
quickPick: {

src/ui/settings/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,9 @@ <h2 class="section__title">Keyboard Shortcuts</h2>
631631
<div class="settings-group">
632632
<label for="keymap">Use</label>
633633
<select class="setting" id="keymap" name="keymap">
634-
<option value="alternate">an alternate set of</option>
635-
<option value="chorded">a chorded set of</option>
636-
<option value="none">a custom set of</option>
634+
<option value="alternate">alt-based</option>
635+
<option value="chorded">chorded (default)</option>
636+
<option value="none">user-defined</option>
637637
</select>
638638
<label for="keymap"> keyboard shortcuts</label>
639639
<span class="label__hint hidden" data-visibility="keymap =alternate">

0 commit comments

Comments
 (0)